fix
This commit is contained in:
@@ -1,31 +1,20 @@
|
||||
package httpapi
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
func TestInviteMailResult(t *testing.T) {
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/mail"
|
||||
)
|
||||
|
||||
func TestInviteAcceptURLAlwaysShareable(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
name string
|
||||
smtpEnabled bool
|
||||
sendOK bool
|
||||
wantMailSent bool
|
||||
wantToken bool
|
||||
}{
|
||||
{name: "smtp_ok", smtpEnabled: true, sendOK: true, wantMailSent: true, wantToken: false},
|
||||
{name: "smtp_send_fail", smtpEnabled: true, sendOK: false, wantMailSent: false, wantToken: true},
|
||||
{name: "noop_mailer_send_ok", smtpEnabled: false, sendOK: true, wantMailSent: false, wantToken: true},
|
||||
{name: "disabled_no_send", smtpEnabled: false, sendOK: false, wantMailSent: false, wantToken: true},
|
||||
url := mail.AcceptInviteURL("https://app.example.com/", "tok_abc")
|
||||
want := "https://app.example.com/accept-invite?token=tok_abc"
|
||||
if url != want {
|
||||
t.Fatalf("AcceptInviteURL = %q want %q", url, want)
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
mailSent, includeToken := inviteMailResult(tc.smtpEnabled, tc.sendOK)
|
||||
if mailSent != tc.wantMailSent {
|
||||
t.Fatalf("mailSent=%v want %v", mailSent, tc.wantMailSent)
|
||||
}
|
||||
if includeToken != tc.wantToken {
|
||||
t.Fatalf("includeToken=%v want %v", includeToken, tc.wantToken)
|
||||
}
|
||||
})
|
||||
if strings.Contains(url, "mailto:") {
|
||||
t.Fatal("invite URL must not be mailto")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user