Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DTFS2-7498): fetch amendments eligibility criteria from db #4155

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
acac5e4
feat(DTFS2-7498): add eligibility criteria to initial draft amendment
BethThomas141 Jan 17, 2025
27a7e25
feat(DTFS2-7498): add null answer field when creating draft amendment
BethThomas141 Jan 17, 2025
7b3f731
feat(DTFS2-7498): add tests
BethThomas141 Jan 17, 2025
b1ef1d3
feat(DTFS2-7498): add dtfs-central tests
BethThomas141 Jan 20, 2025
895768a
feat(DTFS2-7498): fix test and type names
BethThomas141 Jan 20, 2025
bec8c35
feat(DTFS2-7498): update field to be non-optional
BethThomas141 Jan 20, 2025
8bd62fc
Merge branch 'refs/heads/main' into feat/DTFS2-7498/fetch-eligibility…
BethThomas141 Jan 20, 2025
442d12b
feat(DTFS2-7498): add test to ec not found error
BethThomas141 Jan 20, 2025
21729b1
feat(DTFS2-7498): remove unnecessary check from controller
BethThomas141 Jan 20, 2025
277a863
feat(DTFS2-7498): update objects in tests
BethThomas141 Jan 20, 2025
da899ad
feat(DTFS2-7621): add eligibility criteria to mock data loader
BethThomas141 Jan 21, 2025
fb08f0d
feat(DTFS2-7621): fix test namings
BethThomas141 Jan 21, 2025
13ba88f
feat(DTFS2-7498): renamings and docstrings
BethThomas141 Jan 22, 2025
9cda993
feat(DTFS2-7498): remove audit record and product from eligibility cr…
BethThomas141 Jan 22, 2025
2b387cc
feat(DTFS2-7498): more review mark ups
BethThomas141 Jan 22, 2025
072ab9e
Merge branch 'refs/heads/main' into feat/DTFS2-7498/fetch-eligibility…
BethThomas141 Jan 22, 2025
e04f956
feat(DTFS2-7498): more review mark ups
BethThomas141 Jan 22, 2025
ae7564f
feat(DTFS2-7621): revert accidental test change
BethThomas141 Jan 22, 2025
45fee29
feat(DTFS2-7621): change types to interface
BethThomas141 Jan 22, 2025
d78a3cd
feat(DTFS2-7621): fix api tests
BethThomas141 Jan 22, 2025
d745a4c
feat(DTFS2-7621): tiny renaming
BethThomas141 Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import aDeal from '../deal-builder';
import { aPortalUser } from '../../mocks/test-users/portal-user';
import { createPortalUser } from '../../helpers/create-portal-user';
import { createPortalFacilityAmendment } from '../../helpers/create-portal-facility-amendment';
import { mongoDbClient as db } from '../../../src/drivers/db-client';
import { amendmentsEligibilityCriteria } from '../../../test-helpers/test-data/eligibility-criteria-amendments';

const originalEnv = { ...process.env };

Expand All @@ -40,7 +42,10 @@ describe('GET /v1/portal/facilities/:facilityId/amendments/:amendmentId', () =>
let portalUserId: string;

beforeAll(async () => {
await wipeDB.wipe([MONGO_DB_COLLECTIONS.FACILITIES, MONGO_DB_COLLECTIONS.TFM_FACILITIES]);
await wipeDB.wipe([MONGO_DB_COLLECTIONS.FACILITIES, MONGO_DB_COLLECTIONS.TFM_FACILITIES, MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS]);
await db
.getCollection(MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS)
.then((collection) => collection.insertOne(amendmentsEligibilityCriteria(1, [FACILITY_TYPE.CASH, FACILITY_TYPE.CONTINGENT])));

portalUserId = (await createPortalUser())._id;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import aDeal from '../deal-builder';
import { aPortalUser } from '../../mocks/test-users/portal-user';
import { createPortalUser } from '../../helpers/create-portal-user';
import { createPortalFacilityAmendment } from '../../helpers/create-portal-facility-amendment';
import { mongoDbClient as db } from '../../../src/drivers/db-client';
import { amendmentsEligibilityCriteria } from '../../../test-helpers/test-data/eligibility-criteria-amendments';

const originalEnv = { ...process.env };

Expand All @@ -33,7 +35,10 @@ describe('PATCH /v1/portal/facilities/:facilityId/amendments/', () => {
let portalUserId: string;

beforeAll(async () => {
await wipeDB.wipe([MONGO_DB_COLLECTIONS.FACILITIES, MONGO_DB_COLLECTIONS.TFM_FACILITIES]);
await wipeDB.wipe([MONGO_DB_COLLECTIONS.FACILITIES, MONGO_DB_COLLECTIONS.TFM_FACILITIES, MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS]);
await db
.getCollection(MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS)
.then((collection) => collection.insertOne(amendmentsEligibilityCriteria(1, [FACILITY_TYPE.CASH, FACILITY_TYPE.CONTINGENT])));

portalUserId = (await createPortalUser())._id;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import aDeal from '../deal-builder';
import { aPortalUser } from '../../mocks/test-users/portal-user';
import { createPortalUser } from '../../helpers/create-portal-user';
import { createPortalFacilityAmendment } from '../../helpers/create-portal-facility-amendment';
import { amendmentsEligibilityCriteria } from '../../../test-helpers/test-data/eligibility-criteria-amendments';
import { mongoDbClient as db } from '../../../src/drivers/db-client';

const originalEnv = { ...process.env };

Expand All @@ -22,18 +24,29 @@ const generateUrl = (facilityId: string): string => {
return `/v1/portal/facilities/${facilityId}/amendments/`;
};

console.error = jest.fn();

const newDeal = aDeal({
dealType: DEAL_TYPE.GEF,
submissionType: DEAL_SUBMISSION_TYPE.AIN,
}) as AnyObject;

const draftCashEligibilityCriteria = amendmentsEligibilityCriteria(1.5, [FACILITY_TYPE.CASH, FACILITY_TYPE.CONTINGENT], true);
const latestCashEligibilityCriteria = amendmentsEligibilityCriteria(1.2, [FACILITY_TYPE.CASH, FACILITY_TYPE.CONTINGENT]);
const legacyCashEligibilityCriteria = amendmentsEligibilityCriteria(1, [FACILITY_TYPE.CASH, FACILITY_TYPE.CONTINGENT]);
const otherEligibilityCriteria = amendmentsEligibilityCriteria(2, [FACILITY_TYPE.LOAN]);

const eligibilityCriteriaList = [draftCashEligibilityCriteria, legacyCashEligibilityCriteria, latestCashEligibilityCriteria, otherEligibilityCriteria];

describe('PUT /v1/portal/facilities/:facilityId/amendments/', () => {
let dealId: string;
let facilityId: string;

let portalUserId: string;

beforeAll(async () => {
await wipeDB.wipe([MONGO_DB_COLLECTIONS.FACILITIES, MONGO_DB_COLLECTIONS.TFM_FACILITIES]);
await wipeDB.wipe([MONGO_DB_COLLECTIONS.FACILITIES, MONGO_DB_COLLECTIONS.TFM_FACILITIES, MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS]);
await db.getCollection(MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS).then((collection) => collection.insertMany(eligibilityCriteriaList));

portalUserId = (await createPortalUser())._id;
});
Expand Down Expand Up @@ -124,7 +137,13 @@ describe('PUT /v1/portal/facilities/:facilityId/amendments/', () => {

// Assert
expect(status).toEqual(HttpStatusCode.Ok);
expect(body).toEqual(expect.objectContaining({ amendmentId: expect.any(String) as string, facilityId, dealId }));
expect(body).toEqual(
expect.objectContaining({
amendmentId: expect.any(String) as string,
facilityId,
dealId,
}),
);
});

it('should overwrite any existing amendment', async () => {
Expand All @@ -150,5 +169,50 @@ describe('PUT /v1/portal/facilities/:facilityId/amendments/', () => {
message: `Amendment not found: ${existingAmendmentId} on facility: ${facilityId}`,
});
});

it('should return the new amendment with the latest non-draft eligibility criteria for the facility type', async () => {
// Act
const { body, status } = (await testApi
.put({ dealId, amendment: aPortalFacilityAmendmentUserValues(), auditDetails: generatePortalAuditDetails(portalUserId) })
.to(generateUrl(facilityId))) as FacilityAmendmentResponse;

// Assert
const latestCriteriaForFacilityType = latestCashEligibilityCriteria.criteria.map((criterion) => ({ ...criterion, answer: null }));
const latestVersionForFacilityType = latestCashEligibilityCriteria.version;

expect(status).toEqual(HttpStatusCode.Ok);
expect(body).toEqual(
expect.objectContaining({
amendmentId: expect.any(String) as string,
facilityId,
dealId,
eligibilityCriteria: { version: latestVersionForFacilityType, criteria: latestCriteriaForFacilityType },
}),
);
});

it('should throw an error if no eligibility criteria exists in the db for the given facility type', async () => {
// Arrange
await wipeDB.wipe([MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS]);
const eligibilityCriteriaNoCash = [
amendmentsEligibilityCriteria(1, [FACILITY_TYPE.CONTINGENT]),
amendmentsEligibilityCriteria(2, [FACILITY_TYPE.CASH], true),
amendmentsEligibilityCriteria(1.5, [FACILITY_TYPE.BOND, FACILITY_TYPE.LOAN]),
];
await db.getCollection(MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS).then((c) => c.insertMany(eligibilityCriteriaNoCash));

// Act
const { body, status } = (await testApi
.put({ dealId, amendment: aPortalFacilityAmendmentUserValues(), auditDetails: generatePortalAuditDetails(portalUserId) })
.to(generateUrl(facilityId))) as FacilityAmendmentResponse;

// Assert
expect(status).toEqual(HttpStatusCode.NotFound);
expect(body).toEqual({
status: HttpStatusCode.NotFound,
message: 'Eligibility criteria not found',
});
expect(console.error).toHaveBeenCalledWith('Unable to find latest eligibility criteria for facility type %s', FACILITY_TYPE.CASH);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { AmendmentsEligibilityCriteria, FACILITY_TYPE, MONGO_DB_COLLECTIONS } from '@ukef/dtfs2-common';
import { mongoDbClient } from '../../drivers/db-client';
import { EligibilityCriteriaAmendmentsRepo } from './eligibility-criteria-amendments.repo';
import { amendmentsEligibilityCriteria } from '../../../test-helpers/test-data/eligibility-criteria-amendments';

describe('EligibilityCriteriaAmendmentsRepo', () => {
const findToArrayMock = jest.fn();
const findMock = jest.fn();
const getCollectionMock = jest.fn();

afterEach(() => {
jest.resetAllMocks();
});

describe('findLatestEligibilityCriteria', () => {
const eligibilityCriteria: AmendmentsEligibilityCriteria = amendmentsEligibilityCriteria();

Check failure on line 16 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts#L16

Unsafe assignment of an error typed value.

beforeEach(() => {
findToArrayMock.mockResolvedValue([eligibilityCriteria]);
findMock.mockReturnValue({ sort: () => ({ limit: () => ({ toArray: findToArrayMock }) }) });

getCollectionMock.mockResolvedValue({
find: findMock,
});

jest.spyOn(mongoDbClient, 'getCollection').mockImplementation(getCollectionMock);

Check failure on line 26 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts#L26

Unsafe call of an `error` type typed value.
});

it(`should call getCollection with ${MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS}`, async () => {
// Act
await EligibilityCriteriaAmendmentsRepo.findLatestEligibilityCriteria(FACILITY_TYPE.CASH);

// Assert
expect(getCollectionMock).toHaveBeenCalledTimes(1);
expect(getCollectionMock).toHaveBeenCalledWith(MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS);

Check failure on line 35 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts#L35

Unsafe member access .ELIGIBILITY_CRITERIA_AMENDMENTS on an `error` typed value.
});

it('should call find with the expected parameters', async () => {
// Act
const facilityType = FACILITY_TYPE.CASH;

Check failure on line 40 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts#L40

Unsafe assignment of an error typed value.

Check failure on line 40 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.test.ts#L40

Unsafe member access .CASH on an `error` typed value.
await EligibilityCriteriaAmendmentsRepo.findLatestEligibilityCriteria(facilityType);

// Assert
const expectedFilter = { $and: [{ facilityType }, { isInDraft: { $eq: false } }] };

expect(findMock).toHaveBeenCalledTimes(1);
expect(findMock).toHaveBeenCalledWith(expectedFilter);
});

it('should return the found latest eligibility criteria', async () => {
// Act
const facilityType = FACILITY_TYPE.CASH;
const result = await EligibilityCriteriaAmendmentsRepo.findLatestEligibilityCriteria(facilityType);

// Assert
expect(result).toEqual(eligibilityCriteria);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Collection, WithoutId } from 'mongodb';

Check failure on line 1 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts#L1

Unable to resolve path to module 'mongodb'.
import { MONGO_DB_COLLECTIONS, AmendmentsEligibilityCriteria, EligibilityCriteriaNotFoundError, FacilityType } from '@ukef/dtfs2-common';

Check failure on line 2 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts#L2

Unable to resolve path to module '@ukef/dtfs2-common'.
import { mongoDbClient } from '../../drivers/db-client';

/**
* Repository to handle database operations for amendments eligibility criteria
*/
export class EligibilityCriteriaAmendmentsRepo {
private static async getCollection(): Promise<Collection<WithoutId<AmendmentsEligibilityCriteria>>> {
return await mongoDbClient.getCollection(MONGO_DB_COLLECTIONS.ELIGIBILITY_CRITERIA_AMENDMENTS);

Check failure on line 10 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts#L10

Unsafe call of an `error` type typed value.

Check failure on line 10 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts#L10

Unsafe member access .getCollection on an `error` typed value.
}

/**
* Finds the portal amendments eligibility criteria for the given facility type with the latest version number
* @param facilityType the facility type
* @returns The latest portal amendments eligibility criteria for the given facility type
*/
public static async findLatestEligibilityCriteria(facilityType: FacilityType): Promise<AmendmentsEligibilityCriteria> {
const collection = await this.getCollection();

const [latestEligibilityCriteria] = await collection
.find({ $and: [{ facilityType }, { isInDraft: { $eq: false } }] })

Check failure on line 22 in dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/repositories/portal/eligibility-criteria-amendments.repo.ts#L22

Unsafe assignment of an error typed value.
.sort({ version: -1 })
.limit(1)
.toArray();

if (!latestEligibilityCriteria) {
console.error('Unable to find latest eligibility criteria for facility type %s', facilityType);
throw new EligibilityCriteriaNotFoundError();
}

return latestEligibilityCriteria;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import { ObjectId } from 'mongodb';
import { findOneUser } from '../../v1/controllers/user/get-user.controller';
import { TfmFacilitiesRepo } from '../../repositories/tfm-facilities-repo';
import { EligibilityCriteriaAmendmentsRepo } from '../../repositories/portal/eligibility-criteria-amendments.repo';
import { findOneFacility } from '../../v1/controllers/portal/facility/get-facility.controller';

export class PortalFacilityAmendmentService {
/**
Expand Down Expand Up @@ -39,6 +41,12 @@
throw new InvalidAuditDetailsError(`Supplied auditDetails 'id' ${auditDetails.id.toString()} does not correspond to a valid user`);
}

const { type: facilityType } = await findOneFacility(facilityId);

const { version, criteria } = await EligibilityCriteriaAmendmentsRepo.findLatestEligibilityCriteria(facilityType);

const updatedCriteria = criteria.map((criterion) => ({ ...criterion, answer: null }));

Check failure on line 48 in dtfs-central-api/src/services/portal/facility-amendment.service.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/services/portal/facility-amendment.service.ts#L48

Unsafe call of an `error` type typed value.

const amendmentToInsert: PortalFacilityAmendment = {
...amendment,
dealId: new ObjectId(dealId),
Expand All @@ -48,6 +56,7 @@
status: PORTAL_AMENDMENT_STATUS.DRAFT,
createdAt: getUnixTimestampSeconds(new Date()),
updatedAt: getUnixTimestampSeconds(new Date()),
eligibilityCriteria: { version, criteria: updatedCriteria },
createdBy: {
username: user.username,
name: `${user.firstname} ${user.surname}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
/* eslint-disable import/first */
const mockFindOneUser = jest.fn();
import { PORTAL_AMENDMENT_STATUS, AMENDMENT_TYPES, InvalidAuditDetailsError, AmendmentsEligibilityCriteria } from '@ukef/dtfs2-common';

Check failure on line 2 in dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts#L2

Unable to resolve path to module '@ukef/dtfs2-common'.

jest.mock('../../v1/controllers/user/get-user.controller', () => ({
findOneUser: mockFindOneUser,
}));
const mockFindOneUser = jest.fn();
const mockFindOneFacility = jest.fn();
const mockFindLatestEligibilityCriteria = jest.fn() as jest.Mock<Promise<AmendmentsEligibilityCriteria>>;

import { ObjectId } from 'mongodb';
import { HttpStatusCode } from 'axios';
import { getUnixTime } from 'date-fns';
import { generatePortalAuditDetails } from '@ukef/dtfs2-common/change-stream';
import { PORTAL_AMENDMENT_STATUS, AMENDMENT_TYPES, InvalidAuditDetailsError } from '@ukef/dtfs2-common';
import { aPortalFacilityAmendmentUserValues } from '@ukef/dtfs2-common/mock-data-backend';
import { amendmentsEligibilityCriteria } from '../../../test-helpers/test-data/eligibility-criteria-amendments';
import { PortalFacilityAmendmentService } from './facility-amendment.service';
import { aPortalUser } from '../../../test-helpers';
import { aFacility, aPortalUser } from '../../../test-helpers';
import { TfmFacilitiesRepo } from '../../repositories/tfm-facilities-repo';

jest.mock('../../v1/controllers/user/get-user.controller', () => ({
findOneUser: mockFindOneUser,
}));

jest.mock('../../v1/controllers/portal/facility/get-facility.controller', () => ({
findOneFacility: mockFindOneFacility,
}));

jest.mock('../../repositories/portal/eligibility-criteria-amendments.repo', () => ({
EligibilityCriteriaAmendmentsRepo: {
findLatestEligibilityCriteria: (facilityType: string) => mockFindLatestEligibilityCriteria(facilityType),
},
}));

const mockUpsertPortalFacilityAmendmentDraft = jest.fn();

const dealId = new ObjectId().toString();
const facilityId = new ObjectId().toString();
const amendment = aPortalFacilityAmendmentUserValues();
const auditDetails = generatePortalAuditDetails(aPortalUser()._id);
const facility = aFacility();
const eligibilityCriteria = amendmentsEligibilityCriteria();

describe('PortalFacilityAmendmentService', () => {
beforeAll(() => {
Expand All @@ -33,7 +49,9 @@
jest.spyOn(TfmFacilitiesRepo, 'upsertPortalFacilityAmendmentDraft').mockImplementation(mockUpsertPortalFacilityAmendmentDraft);

mockFindOneUser.mockResolvedValue(aPortalUser());
mockUpsertPortalFacilityAmendmentDraft.mockResolvedValue({});
mockFindOneFacility.mockResolvedValue(facility);
mockFindOneFacility.mockResolvedValue(facility);
mockFindLatestEligibilityCriteria.mockResolvedValue(eligibilityCriteria);
});

afterAll(() => {
Expand Down Expand Up @@ -70,6 +88,34 @@
).rejects.toThrow(InvalidAuditDetailsError);
});

it('should call findOneFacility with the facility id', async () => {
// Act
await PortalFacilityAmendmentService.upsertPortalFacilityAmendmentDraft({
dealId,
facilityId,
amendment,
auditDetails,
});

// Assert
expect(mockFindOneFacility).toHaveBeenCalledTimes(1);
expect(mockFindOneFacility).toHaveBeenCalledWith(facilityId);
});

it('should call findLatestEligibilityCriteria with the facility type', async () => {
// Act
await PortalFacilityAmendmentService.upsertPortalFacilityAmendmentDraft({
dealId,
facilityId,
amendment,
auditDetails,
});

// Assert
expect(mockFindLatestEligibilityCriteria).toHaveBeenCalledTimes(1);
expect(mockFindLatestEligibilityCriteria).toHaveBeenCalledWith(facility.type);

Check failure on line 116 in dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts#L116

Unsafe member access .type on an `error` typed value.
});

it('should call TfmFacilitiesRepo.upsertPortalFacilityAmendmentDraft with correct params', async () => {
// Act
await PortalFacilityAmendmentService.upsertPortalFacilityAmendmentDraft({
Expand All @@ -89,6 +135,13 @@
status: PORTAL_AMENDMENT_STATUS.DRAFT,
createdAt: getUnixTime(new Date()),
updatedAt: getUnixTime(new Date()),
eligibilityCriteria: {
version: eligibilityCriteria.version,

Check failure on line 139 in dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts#L139

Unsafe assignment of an error typed value.
criteria: [
{ ...eligibilityCriteria.criteria[0], answer: null },

Check failure on line 141 in dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

dtfs-central-api/src/services/portal/facility-amendment.upsertPortalFacilityAmendmentDraft.service.test.ts#L141

Unsafe member access .criteria on an `error` typed value.
{ ...eligibilityCriteria.criteria[1], answer: null },
],
},
createdBy: {
username: aPortalUser().username,
name: `${aPortalUser().firstname} ${aPortalUser().surname}`,
Expand Down Expand Up @@ -119,6 +172,13 @@
status: PORTAL_AMENDMENT_STATUS.DRAFT,
createdAt: getUnixTime(new Date()),
updatedAt: getUnixTime(new Date()),
eligibilityCriteria: {
version: eligibilityCriteria.version,
criteria: [
{ ...eligibilityCriteria.criteria[0], answer: null },
{ ...eligibilityCriteria.criteria[1], answer: null },
],
},
createdBy: {
username: aPortalUser().username,
name: `${aPortalUser().firstname} ${aPortalUser().surname}`,
Expand Down
Loading
Loading