ultisuite-backend/internal/migration/roster_test.go
R3D347HR4Y 1ffd0817d8
Some checks are pending
CI / Go tests (push) Waiting to run
CI / Integration tests (push) Waiting to run
CI / DB migrations (push) Waiting to run
feat(migration): enhance migration API with roster and audit export features
- Added endpoints for listing and importing migration rosters.
- Introduced audit export functionality for migration jobs in CSV and NDJSON formats.
- Implemented tenant mismatch validation for Microsoft migration claims.
- Enhanced error handling for email claiming and migration processes.
- Added integration tests for roster import and claim workflows.
2026-06-13 13:11:30 +02:00

70 lines
1.7 KiB
Go

package migration
import (
"strings"
"testing"
)
func TestParseRosterCSVWithHeader(t *testing.T) {
csv := `email,display_name,alternate_emails
alice@corp.com,Alice Corp,alice.old@corp.com;bob.alias@corp.com
bob@corp.com,Bob,
`
rows, err := ParseRosterCSV(strings.NewReader(csv))
if err != nil {
t.Fatalf("parse: %v", err)
}
if len(rows) != 2 {
t.Fatalf("expected 2 rows, got %d", len(rows))
}
if rows[0].Email != "alice@corp.com" || rows[0].DisplayName != "Alice Corp" {
t.Fatalf("row0: %#v", rows[0])
}
if len(rows[0].AlternateEmails) != 2 {
t.Fatalf("row0 alternates: %#v", rows[0].AlternateEmails)
}
if rows[1].Email != "bob@corp.com" || rows[1].DisplayName != "Bob" {
t.Fatalf("row1: %#v", rows[1])
}
}
func TestParseRosterCSVWithoutHeader(t *testing.T) {
csv := "alice@corp.com,Alice\nbob@corp.com\n"
rows, err := ParseRosterCSV(strings.NewReader(csv))
if err != nil {
t.Fatalf("parse: %v", err)
}
if len(rows) != 2 {
t.Fatalf("expected 2 rows, got %d", len(rows))
}
if rows[0].DisplayName != "Alice" {
t.Fatalf("display name: %#v", rows[0])
}
if rows[1].DisplayName != "" {
t.Fatalf("row1 display: %#v", rows[1])
}
}
func TestParseRosterCSVInvalidEmail(t *testing.T) {
_, err := ParseRosterCSV(strings.NewReader("not-an-email,Someone\n"))
if err == nil {
t.Fatal("expected invalid email error")
}
}
func TestParseAlternateEmailsField(t *testing.T) {
got := parseAlternateEmailsField(`a@x.com; b@x.com | c@x.com`)
if len(got) != 3 {
t.Fatalf("got %#v", got)
}
}
func TestLooksLikeRosterHeader(t *testing.T) {
if !looksLikeRosterHeader([]string{"Email", "Name"}) {
t.Fatal("expected header detection")
}
if looksLikeRosterHeader([]string{"alice@corp.com", "Alice"}) {
t.Fatal("data row should not be header")
}
}