feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -0,0 +1,126 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
|
||||
func TestNeedCreateMappingPreservesAbsenceNullAndEmptyLists(t *testing.T) {
|
||||
request := &api.NeedCreate{Title: api.NeedTitle("Payments backend"), RequiredSkills: []api.NeedSkillInput{}}
|
||||
request.SourceText.SetTo(api.NeedSourceText("Requirements: Go"))
|
||||
request.VacancyID.SetToNull()
|
||||
|
||||
input := createNeedInput(request)
|
||||
if input.Title != "Payments backend" || !input.SourceText.Set || input.SourceText.Null || input.SourceText.Value != "Requirements: Go" {
|
||||
t.Fatalf("create mapping lost title or source text: %+v", input)
|
||||
}
|
||||
if !input.VacancyID.Set || !input.VacancyID.Null {
|
||||
t.Fatalf("explicit null vacancy mapped as %+v", input.VacancyID)
|
||||
}
|
||||
if input.Grade.Set || input.Specialization.Set || input.RequiredSkills == nil || len(input.RequiredSkills) != 0 || input.DesiredSkills != nil {
|
||||
t.Fatalf("create mapping did not distinguish absent fields from an empty list: %+v", input)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeedUpdateMappingPreservesFieldPresenceAndListReplacement(t *testing.T) {
|
||||
request := &api.NeedUpdate{ExpectedVersion: 4, RequiredSkills: []api.NeedSkillInput{}}
|
||||
request.Title.SetTo(api.NeedTitle("Platform backend"))
|
||||
request.SourceText.SetToNull()
|
||||
|
||||
input := updateNeedInput(request)
|
||||
if input.ExpectedVersion != 4 || !input.Title.Set || input.Title.Null || input.Title.Value != "Platform backend" {
|
||||
t.Fatalf("update mapping lost expected version or title: %+v", input)
|
||||
}
|
||||
if !input.SourceText.Set || !input.SourceText.Null || input.RequiredSkills == nil || len(input.RequiredSkills) != 0 || input.DesiredSkills != nil {
|
||||
t.Fatalf("update mapping did not preserve null and list replacement: %+v", input)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeedResponseDoesNotExposePrivateSuppressionState(t *testing.T) {
|
||||
createdAt := time.Date(2026, time.October, 7, 10, 0, 0, 0, time.UTC)
|
||||
need, err := domain.NewNeed(domain.NeedSnapshot{
|
||||
ID: uuid.Must(uuid.NewV7()), OrganizationID: uuid.Must(uuid.NewV7()), Title: "Payments backend",
|
||||
Version: 1, RequirementsVersion: 1, Requirements: domain.EmptyNeedRequirements(),
|
||||
RejectedSuggestions: []domain.NeedRejectedSuggestion{{Field: domain.NeedRejectedSkills, Value: "postgresql"}},
|
||||
CreatedAt: createdAt, UpdatedAt: createdAt,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NewNeed() error = %v", err)
|
||||
}
|
||||
encoded, err := json.Marshal(needResponse(need.ResponseSnapshot()))
|
||||
if err != nil {
|
||||
t.Fatalf("marshal public need: %v", err)
|
||||
}
|
||||
if strings.Contains(string(encoded), "rejected_suggestions") || strings.Contains(string(encoded), "postgresql") {
|
||||
t.Fatalf("public need exposed private suppression state: %s", encoded)
|
||||
}
|
||||
if !strings.Contains(string(encoded), `"recommendations":{"status":"not_available"`) {
|
||||
t.Fatalf("need response did not report the unavailable calculator honestly: %s", encoded)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeedCursorIsBoundToActorAndOrganization(t *testing.T) {
|
||||
actorID := uuid.Must(uuid.NewV7())
|
||||
organizationID := uuid.Must(uuid.NewV7())
|
||||
position := outbound.NeedListPosition{
|
||||
CreatedAt: time.Date(2026, time.October, 7, 10, 0, 0, 123456000, time.UTC),
|
||||
NeedID: uuid.Must(uuid.NewV7()),
|
||||
}
|
||||
cursor, err := encodeNeedCursor(actorID, organizationID, position)
|
||||
if err != nil {
|
||||
t.Fatalf("encodeNeedCursor() error = %v", err)
|
||||
}
|
||||
decoded, err := decodeNeedCursor(cursor, actorID, organizationID)
|
||||
if err != nil || decoded.NeedID != position.NeedID || !decoded.CreatedAt.Equal(position.CreatedAt) {
|
||||
t.Fatalf("decodeNeedCursor() = %+v, %v, want %+v", decoded, err, position)
|
||||
}
|
||||
if _, err := decodeNeedCursor(cursor, uuid.Must(uuid.NewV7()), organizationID); err == nil {
|
||||
t.Fatal("decodeNeedCursor() accepted a cursor from another actor")
|
||||
}
|
||||
if _, err := decodeNeedCursor(cursor, actorID, uuid.Must(uuid.NewV7())); err == nil {
|
||||
t.Fatal("decodeNeedCursor() accepted a cursor from another organization")
|
||||
}
|
||||
|
||||
encoded, err := base64.RawURLEncoding.DecodeString(cursor)
|
||||
if err != nil {
|
||||
t.Fatalf("decode cursor bytes: %v", err)
|
||||
}
|
||||
encoded[33] = 0x80
|
||||
invalidTimestamp := base64.RawURLEncoding.EncodeToString(encoded)
|
||||
if _, err := decodeNeedCursor(invalidTimestamp, actorID, organizationID); err == nil {
|
||||
t.Fatal("decodeNeedCursor() accepted an out-of-range timestamp")
|
||||
}
|
||||
encoded, err = base64.RawURLEncoding.DecodeString(cursor)
|
||||
if err != nil {
|
||||
t.Fatalf("decode cursor bytes: %v", err)
|
||||
}
|
||||
binary.BigEndian.PutUint64(encoded[33:41], maxNeedCursorTime+1)
|
||||
outsideDateTime := base64.RawURLEncoding.EncodeToString(encoded)
|
||||
if _, err := decodeNeedCursor(outsideDateTime, actorID, organizationID); err == nil {
|
||||
t.Fatal("decodeNeedCursor() accepted a timestamp outside the contract date-time range")
|
||||
}
|
||||
encoded, err = base64.RawURLEncoding.DecodeString(cursor)
|
||||
if err != nil {
|
||||
t.Fatalf("decode cursor bytes: %v", err)
|
||||
}
|
||||
binary.BigEndian.PutUint32(encoded[41:45], 123456001)
|
||||
subMicrosecond := base64.RawURLEncoding.EncodeToString(encoded)
|
||||
if _, err := decodeNeedCursor(subMicrosecond, actorID, organizationID); err == nil {
|
||||
t.Fatal("decodeNeedCursor() accepted precision that PostgreSQL cannot preserve")
|
||||
}
|
||||
if _, err := encodeNeedCursor(actorID, organizationID, outbound.NeedListPosition{
|
||||
CreatedAt: time.Date(10000, 1, 1, 0, 0, 0, 0, time.UTC), NeedID: position.NeedID,
|
||||
}); err == nil {
|
||||
t.Fatal("encodeNeedCursor() accepted a timestamp outside the contract date-time range")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user