feat: add assessment, privacy and support flows

This commit is contained in:
TakuyaYagam1 committed 2026-10-08 08:08:25 +03:00
1 parent ee3738ee73
commit e4f24fa202
339 files changed
+56454 -1126

No files matched your search

@@ -36,11 +36,13 @@ var (
candidateSearchStatusesTable = pgx.Identifier{"candidate_search_statuses"}
candidateHiddenOrganizationsTable = pgx.Identifier{"candidate_hidden_organizations"}
candidatePrivacyEventsTable = pgx.Identifier{"candidate_privacy_events"}
candidateCardAccessEventsTable = pgx.Identifier{"candidate_card_access_events"}
// candidatePrivacyTables reference users, organizations, and the consent
// ledger, so every TRUNCATE of those names them through
// usersDependentTables.
candidatePrivacyTables = []pgx.Identifier{
candidatePrivacyEventsTable, candidateHiddenOrganizationsTable, candidateSearchStatusesTable, candidatePublicationsTable,
candidateCardAccessEventsTable, candidatePrivacyEventsTable, candidateHiddenOrganizationsTable,
candidateSearchStatusesTable, candidatePublicationsTable,
}
)
@@ -772,6 +774,66 @@ func TestCandidatePrivacyStorage(t *testing.T) {
})
}
func TestCandidateCardAccessEventRetentionAndActorAnonymization(t *testing.T) {
env := bootstrap(t, postgresService)
ctx, cancel := context.WithTimeout(t.Context(), candidatePrivacyTestTimeout)
defer cancel()
pool := env.newPool(ctx, t)
now := time.Now().UTC().Truncate(time.Microsecond)
identity := identityFixture{ctx: ctx, pool: pool, store: postgresadapter.NewIdentityStore(pool), now: now}
fixture := candidatePrivacyFixture{
ctx: ctx, pool: pool, queries: sqlc.New(pool), identity: identity,
organizations: organizationFixture{ctx: ctx, pool: pool, identity: identity, transactor: postgresadapter.NewTransactor(pool), now: now},
ledger: postgresadapter.NewConsentStore(pool), now: now,
}
truncateTables(ctx, t, pool, usersDependentTables...)
candidate := fixture.candidate(t, "privacy-owner@example.test")
verifyPrivacyCohortCandidate(t, fixture, candidate)
organizationOwner := fixture.organizations.employer(t, "privacy-organization-owner@example.test")
organization := fixture.organizations.create(t, organizationOwner,
fixture.organizations.completeProfile(t, "Access history organization"), now)
actor := fixture.candidate(t, "privacy-viewer@example.test")
access, err := domain.NewCandidateCardAccess(domain.CandidateCardAccessInput{
CandidateID: candidate.ID, OrganizationID: organization.ID(), ActorID: actor.ID,
Kind: domain.CandidateCardAccessCardViewed, OccurredAt: now,
})
if err != nil {
t.Fatalf("NewCandidateCardAccess() error = %v", err)
}
queries := sqlc.New(pool)
if err := queries.InsertCandidateCardAccessEvent(ctx, sqlc.InsertCandidateCardAccessEventParams{
ID: uuidParam(access.ID()), CandidateID: uuidParam(candidate.ID), OrganizationID: uuidParam(organization.ID()),
ActorID: uuidParam(actor.ID), Kind: string(access.Kind()), FieldCodes: access.FieldCodes(), OccurredAt: timeParam(access.OccurredAt()),
}); err != nil {
t.Fatalf("InsertCandidateCardAccessEvent(pseudonym-only) error = %v", err)
}
_, err = pool.Exec(ctx, `UPDATE candidate_card_access_events SET field_codes = ARRAY['location'] WHERE id = $1`, access.ID())
assertPgError(t, "reject card access field update", err, privacyIntegrityViolation, "candidate_card_access_events_immutable")
_, err = pool.Exec(ctx, `UPDATE candidate_card_access_events SET actor_id = NULL WHERE id = $1`, access.ID())
assertPgError(t, "reject direct card access actor anonymization", err, privacyIntegrityViolation, "candidate_card_access_events_immutable")
_, err = pool.Exec(ctx, `DELETE FROM candidate_card_access_events WHERE id = $1`, access.ID())
assertPgError(t, "reject card access deletion", err, privacyIntegrityViolation, "candidate_card_access_events_retained")
if _, err := pool.Exec(ctx, `DELETE FROM users WHERE id = $1`, actor.ID); err != nil {
t.Fatalf("DELETE audit actor = %v", err)
}
var storedCandidate, storedOrganization uuid.UUID
var storedActor pgtype.UUID
var kind string
var fields []string
if err := pool.QueryRow(ctx, `SELECT candidate_id, organization_id, actor_id, kind, field_codes FROM candidate_card_access_events WHERE id = $1`, access.ID()).
Scan(&storedCandidate, &storedOrganization, &storedActor, &kind, &fields); err != nil {
t.Fatalf("read retained card access = %v", err)
}
if storedCandidate != candidate.ID || storedOrganization != organization.ID() || storedActor.Valid ||
kind != string(domain.CandidateCardAccessCardViewed) || len(fields) != 0 {
t.Fatalf("retained access = candidate %s org %s actor %+v kind %s fields %v", storedCandidate, storedOrganization, storedActor, kind, fields)
}
}
func containsWord(column, word string) bool {
for _, part := range splitIdentifier(column) {
if part == word {