package model import "testing" func TestPendingInvitationStatusValues(t *testing.T) { got := PendingInvitationStatusValues() want := []string{"created", "sent"} if len(got) != len(want) { t.Fatalf("pending status count mismatch: got %d want %d", len(got), len(want)) } for i := range want { if got[i] != want[i] { t.Fatalf("pending status %d mismatch: got %q want %q", i, got[i], want[i]) } } if !IsPendingInvitationStatus(InvitationCreated) { t.Fatal("created must be pending") } if !IsPendingInvitationStatus(InvitationSent) { t.Fatal("sent must be pending") } for _, status := range []InvitationStatus{InvitationAccepted, InvitationDeclined, InvitationRevoked} { if IsPendingInvitationStatus(status) { t.Fatalf("%q must not be pending", status) } } } func TestInvitationValidateEmail(t *testing.T) { tests := []struct { name string email string wantErr bool }{ {name: "valid", email: "invitee@example.com"}, {name: "whitespace padded valid", email: " invitee@example.com "}, {name: "empty", email: "", wantErr: true}, {name: "whitespace only", email: " ", wantErr: true}, {name: "missing domain", email: "invitee@", wantErr: true}, {name: "missing at", email: "invitee.example.com", wantErr: true}, {name: "display name", email: "Invitee ", wantErr: true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { inv := &Invitation{ Status: InvitationCreated, Content: invitationDesc{ Email: tt.email, }, } err := inv.Validate() if tt.wantErr && err == nil { t.Fatal("expected validation error") } if !tt.wantErr && err != nil { t.Fatalf("expected valid invitation, got %v", err) } }) } }