62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package candidateview
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"slices"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"lincodex/backend/internal/domain"
|
|
)
|
|
|
|
func TestCardViewAccessEventRecordsOnlyFieldsReturnedInTheProjection(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
key, err := domain.NewCandidateViewPseudonymKey(bytes.Repeat([]byte("candidate-view-key"), 2))
|
|
if err != nil {
|
|
t.Fatalf("NewCandidateViewPseudonymKey() error = %v", err)
|
|
}
|
|
candidateID, organizationID, actorID := uuid.New(), uuid.New(), uuid.New()
|
|
pseudonym, err := key.ForOrganization(organizationID, candidateID)
|
|
if err != nil {
|
|
t.Fatalf("ForOrganization() error = %v", err)
|
|
}
|
|
|
|
view := domain.AnonymousCandidateViewDTO{Pseudonym: pseudonym}
|
|
event, err := cardViewAccessEvent(candidateID, organizationID, actorID, view, time.Now())
|
|
if err != nil {
|
|
t.Fatalf("cardViewAccessEvent(pseudonym only) error = %v", err)
|
|
}
|
|
if got := event.FieldCodes(); len(got) != 0 {
|
|
t.Fatalf("pseudonym-only field codes = %v, want empty", got)
|
|
}
|
|
|
|
band := domain.CandidateExperienceBandOneToThree
|
|
compatibility := domain.CandidateViewSalaryCompatible
|
|
view.Categories = []domain.CandidateViewCategory{{Specialization: domain.SpecializationBackend, Grade: domain.GradeJunior, Strength: domain.CandidateViewStrengthStandard}}
|
|
view.Skills = []domain.CandidateViewSkillCode{domain.CandidateViewSkillGo}
|
|
view.ExperienceBand = &band
|
|
view.WorkFormats = []domain.QuestionnaireWorkFormat{domain.QuestionnaireWorkFormatRemote}
|
|
view.SalaryCompatibility = &compatibility
|
|
event, err = cardViewAccessEvent(candidateID, organizationID, actorID, view, time.Now())
|
|
if err != nil {
|
|
t.Fatalf("cardViewAccessEvent(projected fields) error = %v", err)
|
|
}
|
|
want := []string{"categories", "experience", "salary_compatibility", "stack", "work_formats"}
|
|
if got := event.FieldCodes(); !slices.Equal(got, want) {
|
|
t.Fatalf("projected field codes = %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestCardViewAccessEventRejectsAHandleThatIsNotAnOpaqueAlias(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
_, err := cardViewAccessEvent(uuid.New(), uuid.New(), uuid.New(), domain.AnonymousCandidateViewDTO{Pseudonym: "candidate-id"}, time.Now())
|
|
if !errors.Is(err, ErrInvalidCandidateHandle) {
|
|
t.Fatalf("cardViewAccessEvent(invalid alias) error = %v, want ErrInvalidCandidateHandle", err)
|
|
}
|
|
}
|