690514:2019 204-rfa-approval-refactor #01
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
// File: tests/unit/distribution/distribution-matrix.service.spec.ts
|
||||
// Change Log
|
||||
// - 2026-05-14: Add regression coverage for Distribution Matrix public-ID handling.
|
||||
import { DistributionMatrixService } from '../../../src/modules/distribution/distribution-matrix.service';
|
||||
import { DistributionMatrix } from '../../../src/modules/distribution/entities/distribution-matrix.entity';
|
||||
import { DistributionRecipient } from '../../../src/modules/distribution/entities/distribution-recipient.entity';
|
||||
import { Project } from '../../../src/modules/project/entities/project.entity';
|
||||
import { ResponseCode } from '../../../src/modules/response-code/entities/response-code.entity';
|
||||
import {
|
||||
DeliveryMethod,
|
||||
RecipientType,
|
||||
} from '../../../src/modules/common/enums/review.enums';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
type RepositoryMock<T extends object> = {
|
||||
find: jest.MockedFunction<(options: unknown) => Promise<T[]>>;
|
||||
findOne: jest.MockedFunction<(options: unknown) => Promise<T | null>>;
|
||||
create: jest.MockedFunction<(payload: Partial<T>) => T>;
|
||||
save: jest.MockedFunction<(payload: T) => Promise<T>>;
|
||||
remove: jest.MockedFunction<(payload: T) => Promise<T>>;
|
||||
};
|
||||
|
||||
const createRepositoryMock = <T extends object>(): RepositoryMock<T> => ({
|
||||
find: jest.fn(),
|
||||
findOne: jest.fn(),
|
||||
create: jest.fn((payload: Partial<T>): T => payload as T),
|
||||
save: jest.fn((payload: T): Promise<T> => Promise.resolve(payload)),
|
||||
remove: jest.fn((payload: T): Promise<T> => Promise.resolve(payload)),
|
||||
});
|
||||
|
||||
describe('DistributionMatrixService', () => {
|
||||
const matrixRepo = createRepositoryMock<DistributionMatrix>();
|
||||
const recipientRepo = createRepositoryMock<DistributionRecipient>();
|
||||
const projectRepo = createRepositoryMock<Project>();
|
||||
const responseCodeRepo = createRepositoryMock<ResponseCode>();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('creates a schema-aligned matrix by resolving public IDs internally', async () => {
|
||||
const service = new DistributionMatrixService(
|
||||
matrixRepo as unknown as Repository<DistributionMatrix>,
|
||||
recipientRepo as unknown as Repository<DistributionRecipient>,
|
||||
projectRepo as unknown as Repository<Project>,
|
||||
responseCodeRepo as unknown as Repository<ResponseCode>
|
||||
);
|
||||
matrixRepo.findOne.mockResolvedValue({
|
||||
id: 7,
|
||||
publicId: '019505a1-7c3e-7000-8000-000000000001',
|
||||
} as unknown as DistributionMatrix);
|
||||
projectRepo.findOne.mockResolvedValue({
|
||||
id: 7,
|
||||
publicId: '019505a1-7c3e-7000-8000-000000000001',
|
||||
} as Project);
|
||||
responseCodeRepo.findOne.mockResolvedValue({
|
||||
id: 9,
|
||||
publicId: '019505a1-7c3e-7000-8000-000000000002',
|
||||
} as ResponseCode);
|
||||
|
||||
await service.create({
|
||||
name: 'Shop Drawing Distribution',
|
||||
projectPublicId: '019505a1-7c3e-7000-8000-000000000001',
|
||||
documentTypeId: 3,
|
||||
responseCodePublicId: '019505a1-7c3e-7000-8000-000000000002',
|
||||
conditions: { codes: ['1A', '1B'], excludeCodes: ['3'] },
|
||||
});
|
||||
|
||||
expect(matrixRepo.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
name: 'Shop Drawing Distribution',
|
||||
projectId: 7,
|
||||
documentTypeId: 3,
|
||||
responseCodeId: 9,
|
||||
conditions: { codes: ['1A', '1B'], excludeCodes: ['3'] },
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('adds recipients with recipientPublicId instead of internal recipient ids', async () => {
|
||||
const service = new DistributionMatrixService(
|
||||
matrixRepo as unknown as Repository<DistributionMatrix>,
|
||||
recipientRepo as unknown as Repository<DistributionRecipient>,
|
||||
projectRepo as unknown as Repository<Project>,
|
||||
responseCodeRepo as unknown as Repository<ResponseCode>
|
||||
);
|
||||
matrixRepo.findOne.mockResolvedValue({
|
||||
id: 11,
|
||||
publicId: '019505a1-7c3e-7000-8000-000000000003',
|
||||
} as DistributionMatrix);
|
||||
|
||||
await service.addRecipient('019505a1-7c3e-7000-8000-000000000003', {
|
||||
recipientType: RecipientType.ORGANIZATION,
|
||||
recipientPublicId: '019505a1-7c3e-7000-8000-000000000004',
|
||||
deliveryMethod: DeliveryMethod.BOTH,
|
||||
sequence: 1,
|
||||
});
|
||||
|
||||
expect(recipientRepo.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
matrixId: 11,
|
||||
recipientType: RecipientType.ORGANIZATION,
|
||||
recipientPublicId: '019505a1-7c3e-7000-8000-000000000004',
|
||||
deliveryMethod: DeliveryMethod.BOTH,
|
||||
sequence: 1,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
// File: tests/unit/distribution/transmittal-creator.service.spec.ts
|
||||
// Change Log
|
||||
// - 2026-05-14: Add regression coverage for Distribution Matrix response-code filtering.
|
||||
import { TransmittalCreatorService } from '../../../src/modules/distribution/services/transmittal-creator.service';
|
||||
import { DistributionMatrix } from '../../../src/modules/distribution/entities/distribution-matrix.entity';
|
||||
import { DistributionRecipient } from '../../../src/modules/distribution/entities/distribution-recipient.entity';
|
||||
import { DocumentNumberingService } from '../../../src/modules/document-numbering/services/document-numbering.service';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
|
||||
type MatrixRepositoryMock = {
|
||||
findOne: jest.MockedFunction<
|
||||
(options: unknown) => Promise<DistributionMatrix | null>
|
||||
>;
|
||||
};
|
||||
|
||||
describe('TransmittalCreatorService', () => {
|
||||
const matrixRepo: MatrixRepositoryMock = {
|
||||
findOne: jest.fn(),
|
||||
};
|
||||
const dataSource = {
|
||||
manager: {
|
||||
findOne: jest.fn(),
|
||||
},
|
||||
query: jest.fn(),
|
||||
createQueryRunner: jest.fn(),
|
||||
};
|
||||
const numberingService = {
|
||||
generateNextNumber: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('skips distribution when the response code is excluded', async () => {
|
||||
const service = new TransmittalCreatorService(
|
||||
matrixRepo as unknown as Repository<DistributionMatrix>,
|
||||
dataSource as unknown as DataSource,
|
||||
numberingService as unknown as DocumentNumberingService
|
||||
);
|
||||
matrixRepo.findOne.mockResolvedValue({
|
||||
conditions: { excludeCodes: ['3', '4'] },
|
||||
recipients: [{} as DistributionRecipient],
|
||||
} as DistributionMatrix);
|
||||
|
||||
const result = await service.createFromDistribution({
|
||||
rfaPublicId: '019505a1-7c3e-7000-8000-000000000001',
|
||||
rfaRevisionPublicId: '019505a1-7c3e-7000-8000-000000000002',
|
||||
projectId: 1,
|
||||
documentTypeId: 2,
|
||||
responseCode: '3',
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
transmittalPublicIds: [],
|
||||
notificationTargets: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user