feat(accounts): add consent settings and organization management
This commit is contained in:
1 parent
24638d46d2
commit
391af7a1ef
83 files changed
+10198
-613
No files matched your search
@@ -2,9 +2,11 @@ package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
@@ -81,3 +83,50 @@ func TestManagerRoleNamesFollowTheDomainRule(t *testing.T) {
|
||||
t.Fatalf("managerRoleNames() = %v, want only the owner", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizationCreationSnapshotRoundTripsDomainResult(t *testing.T) {
|
||||
at := time.Date(2026, 8, 15, 10, 30, 0, 123456789, time.UTC)
|
||||
profile, err := domain.NewOrganizationProfile(domain.OrganizationProfileInput{
|
||||
Name: "ООО Пример", Description: "Описание", Sphere: "Платежи",
|
||||
Contacts: domain.OrganizationContactsInput{
|
||||
Website: "https://example.com", Email: "careers@example.com", Phone: "+74951234567", Telegram: "@example",
|
||||
},
|
||||
Representatives: []domain.OrganizationRepresentativeInput{{Name: "Анна Тестова", JobTitle: "Директор"}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("NewOrganizationProfile() error = %v", err)
|
||||
}
|
||||
company, err := domain.NewOrganization(profile, at)
|
||||
if err != nil {
|
||||
t.Fatalf("NewOrganization() error = %v", err)
|
||||
}
|
||||
owner, err := domain.NewOwnerMembership(company.ID(), uuid.New(), at)
|
||||
if err != nil {
|
||||
t.Fatalf("NewOwnerMembership() error = %v", err)
|
||||
}
|
||||
result := outbound.OrganizationCreationResult{Organization: company, Owner: owner}
|
||||
snapshot := creationSnapshotFromDomain(result)
|
||||
encoded, err := json.Marshal(snapshot)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal(snapshot) error = %v", err)
|
||||
}
|
||||
var decoded organizationCreationSnapshot
|
||||
if err := json.Unmarshal(encoded, &decoded); err != nil {
|
||||
t.Fatalf("Unmarshal(snapshot) error = %v", err)
|
||||
}
|
||||
got, err := decoded.domainResult()
|
||||
if err != nil {
|
||||
t.Fatalf("domainResult() error = %v", err)
|
||||
}
|
||||
if got.Organization.ID() != company.ID() || got.Organization.Version() != company.Version() ||
|
||||
!got.Organization.Profile().Equal(company.Profile()) ||
|
||||
got.Organization.Verification().Level() != domain.OrganizationVerificationE0 ||
|
||||
got.Organization.Verification().Basis() != domain.OrganizationBasisConfirmedEmail ||
|
||||
!got.Organization.CreatedAt().Equal(at) || got.Owner.ID() != owner.ID() || got.Owner.UserID() != owner.UserID() ||
|
||||
got.Owner.OrganizationID() != company.ID() || got.Owner.Role() != domain.OrganizationRoleOwner || !got.Owner.GrantsAccess() {
|
||||
t.Fatal("creation snapshot did not preserve the original organization and owner result")
|
||||
}
|
||||
if len(encoded) > maxOrganizationCreationSnapshotBytes {
|
||||
t.Fatalf("snapshot size = %d, want at most %d bytes", len(encoded), maxOrganizationCreationSnapshotBytes)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user