feat(invitations): send invitations into the candidate inbox atomically
This commit is contained in:
1 parent
fc35e27af5
commit
1a067221f7
46 files changed
+3276
-113
No files matched your search
@@ -274,12 +274,63 @@ func TestSyntheticNoticeResolverFollowsTheRecipientStanding(t *testing.T) {
|
||||
OccurredAt: time.Date(2026, time.October, 8, 12, 0, 0, 0, time.UTC),
|
||||
})
|
||||
if _, err := resolvers.Resolve(context.Background(), unit, invitation); !errors.Is(err, ErrInboxContentUnavailable) {
|
||||
t.Fatalf("Resolve(source without a resolver) error = %v, want ErrInboxContentUnavailable", err)
|
||||
t.Fatalf("Resolve(invitation the recipient cannot read) error = %v, want ErrInboxContentUnavailable", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveInvitationNoticeNamesTheSenderOnlyWhileVisible(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fixture := newInboxFixture(t, domain.ScenarioCandidate)
|
||||
delivered := fixture.deliveredInvitation(t)
|
||||
entry := fixtureEntry(t, domain.NotificationInboxEntryInput{
|
||||
EventID: uuid.New(), RecipientUserID: fixture.user.ID, OrganizationID: fixture.organizationID,
|
||||
EventType: domain.NotificationInboxInvitationDelivered, SchemaVersion: 1,
|
||||
SourceType: domain.NotificationInboxSourceInvitation, SourceID: delivered.ID(),
|
||||
OccurredAt: time.Date(2026, time.October, 8, 12, 0, 0, 0, time.UTC),
|
||||
})
|
||||
resolvers := NewInboxContentResolver(DefaultInboxSourceResolvers(false))
|
||||
content, err := resolvers.Resolve(context.Background(), fixture.unit(), entry)
|
||||
if err != nil {
|
||||
t.Fatalf("Resolve(delivered invitation) error = %v", err)
|
||||
}
|
||||
if content.Title() != invitationNoticeTitle || content.LinkPath() != candidateInvitationsPath ||
|
||||
!strings.Contains(content.Summary(), "«Север»") || !strings.Contains(content.Summary(), "«Inbox role»") {
|
||||
t.Fatalf("invitation content = %q / %q / %q", content.Title(), content.Summary(), content.LinkPath())
|
||||
}
|
||||
if strings.Contains(content.Summary(), fixture.user.ID.String()) {
|
||||
t.Fatal("invitation content names the candidate")
|
||||
}
|
||||
|
||||
// Another recipient and another organization context find nothing.
|
||||
foreign := fixtureEntry(t, domain.NotificationInboxEntryInput{
|
||||
EventID: uuid.New(), RecipientUserID: uuid.New(), OrganizationID: fixture.organizationID,
|
||||
EventType: domain.NotificationInboxInvitationDelivered, SchemaVersion: 1,
|
||||
SourceType: domain.NotificationInboxSourceInvitation, SourceID: delivered.ID(),
|
||||
OccurredAt: time.Date(2026, time.October, 8, 12, 0, 0, 0, time.UTC),
|
||||
})
|
||||
if _, err := ResolveInvitationNotice(context.Background(), fixture.unit(), foreign); !errors.Is(err, ErrInboxContentUnavailable) {
|
||||
t.Fatalf("ResolveInvitationNotice(other recipient) error = %v, want ErrInboxContentUnavailable", err)
|
||||
}
|
||||
otherContext := fixtureEntry(t, domain.NotificationInboxEntryInput{
|
||||
EventID: uuid.New(), RecipientUserID: fixture.user.ID, OrganizationID: uuid.New(),
|
||||
EventType: domain.NotificationInboxInvitationDelivered, SchemaVersion: 1,
|
||||
SourceType: domain.NotificationInboxSourceInvitation, SourceID: delivered.ID(),
|
||||
OccurredAt: time.Date(2026, time.October, 8, 12, 0, 0, 0, time.UTC),
|
||||
})
|
||||
if _, err := ResolveInvitationNotice(context.Background(), fixture.unit(), otherContext); !errors.Is(err, ErrInboxContentUnavailable) {
|
||||
t.Fatalf("ResolveInvitationNotice(other organization) error = %v, want ErrInboxContentUnavailable", err)
|
||||
}
|
||||
// A hidden organization is no longer named.
|
||||
fixture.repository.organizationName = ""
|
||||
if _, err := ResolveInvitationNotice(context.Background(), fixture.unit(), entry); !errors.Is(err, ErrInboxContentUnavailable) {
|
||||
t.Fatalf("ResolveInvitationNotice(hidden sender) error = %v, want ErrInboxContentUnavailable", err)
|
||||
}
|
||||
}
|
||||
|
||||
type inboxFixture struct {
|
||||
service *InboxService
|
||||
invitations map[uuid.UUID]domain.Invitation
|
||||
repository *memoryInboxRepository
|
||||
resolver *memoryInboxResolver
|
||||
users map[uuid.UUID]domain.User
|
||||
@@ -298,6 +349,7 @@ func newInboxFixtureWithClock(t *testing.T, scenario domain.Scenario, clock func
|
||||
t.Helper()
|
||||
verifiedAt := time.Date(2026, time.October, 1, 10, 0, 0, 0, time.UTC)
|
||||
fixture := &inboxFixture{
|
||||
invitations: map[uuid.UUID]domain.Invitation{},
|
||||
repository: &memoryInboxRepository{organizationName: "Север"},
|
||||
resolver: &memoryInboxResolver{unavailable: map[uuid.UUID]bool{}},
|
||||
users: map[uuid.UUID]domain.User{},
|
||||
@@ -316,6 +368,39 @@ func newInboxFixtureWithClock(t *testing.T, scenario domain.Scenario, clock func
|
||||
|
||||
func (fixture *inboxFixture) unit() outbound.UnitOfWork { return inboxTestUnit{fixture: fixture} }
|
||||
|
||||
// deliveredInvitation stores a delivered invitation of the fixture
|
||||
// organization addressed to the fixture user.
|
||||
func (fixture *inboxFixture) deliveredInvitation(t *testing.T) domain.Invitation {
|
||||
t.Helper()
|
||||
policyID, err := domain.NewPolicyVersionID()
|
||||
if err != nil {
|
||||
t.Fatalf("NewPolicyVersionID() error = %v", err)
|
||||
}
|
||||
none := domain.InvitationPackageItem{Status: domain.InvitationPackageNotProvided}
|
||||
at := time.Date(2026, time.October, 8, 11, 0, 0, 0, time.UTC)
|
||||
draft, err := domain.NewInvitationDraft(domain.NewInvitationDraftInput{
|
||||
ID: uuid.New(), OrganizationID: fixture.organizationID, CandidateID: fixture.user.ID, ActorID: uuid.New(),
|
||||
PolicyVersionID: policyID, At: at,
|
||||
Content: domain.InvitationDraftContent{ResponsePeriod: 7, Terms: domain.InvitationTerms{
|
||||
RoleTitle: "Inbox role", Specialization: domain.SpecializationBackend, Grade: domain.GradeMiddle,
|
||||
OfferType: domain.InvitationOfferFullTime, Tasks: []string{"Read the inbox"}, Team: "Inbox team",
|
||||
TechStack: []string{"Go"}, WorkFormats: []domain.NeedWorkFormat{domain.NeedWorkFormatRemote},
|
||||
CommunicationMethod: domain.InvitationCommunicationMethod{Channel: domain.InvitationChannelEmail},
|
||||
Salary: domain.SalaryRange{SalaryFrom: 100_000, SalaryTo: 140_000, Currency: "RUB", Period: "month", TaxBasis: "net"},
|
||||
Package: domain.InvitationPackage{Bonus: none, Equipment: none, Training: none, HealthInsurance: none},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NewInvitationDraft() error = %v", err)
|
||||
}
|
||||
delivered, err := draft.Deliver(at.Add(time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("Deliver() error = %v", err)
|
||||
}
|
||||
fixture.invitations[delivered.ID()] = delivered
|
||||
return delivered
|
||||
}
|
||||
|
||||
func (fixture *inboxFixture) entryInput() domain.NotificationInboxEntryInput {
|
||||
return fixtureEntryInput(fixture.user.ID, fixture.organizationID)
|
||||
}
|
||||
@@ -379,6 +464,25 @@ func (unit inboxTestUnit) Organizations() outbound.OrganizationRepository {
|
||||
func (unit inboxTestUnit) NotificationInbox() outbound.NotificationInboxRepository {
|
||||
return unit.fixture.repository
|
||||
}
|
||||
func (unit inboxTestUnit) Invitations() outbound.InvitationRepository {
|
||||
return inboxTestInvitations{fixture: unit.fixture}
|
||||
}
|
||||
|
||||
type inboxTestInvitations struct {
|
||||
outbound.InvitationRepository
|
||||
|
||||
fixture *inboxFixture
|
||||
}
|
||||
|
||||
// GetForCandidate answers like the real repository: only a delivered
|
||||
// invitation addressed to the candidate is found.
|
||||
func (repository inboxTestInvitations) GetForCandidate(_ context.Context, candidateID, invitationID uuid.UUID) (domain.Invitation, error) {
|
||||
invitation, ok := repository.fixture.invitations[invitationID]
|
||||
if !ok || invitation.CandidateID() != candidateID || !invitation.IsDelivered() {
|
||||
return domain.Invitation{}, outbound.ErrInvitationNotFound
|
||||
}
|
||||
return invitation, nil
|
||||
}
|
||||
|
||||
type inboxTestUsers struct {
|
||||
outbound.UserRepository
|
||||
|
||||
Reference in new issue
Block a user