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(FN-3163): allow non gef deals #4209

Merged
merged 7 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ CONTACT_US_SELF_SERVICE_PORTAL_URL=
# FEATURE FLAGS
CHANGE_STREAM_ENABLED=false
CLAMAV_SCANNING_ENABLED=false
GEF_DEAL_VERSION=0
abhi-markan marked this conversation as resolved.
Show resolved Hide resolved
FF_TFM_PAYMENT_RECONCILIATION_ENABLED=false
FF_TFM_DEAL_CANCELLATION_ENABLED=false
FF_PORTAL_FACILITY_AMENDMENTS_ENABLED=false
Expand Down
14 changes: 10 additions & 4 deletions external-api/api-tests/v1/party-db.ff-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { api } from '../api';
const { APIM_MDM_URL } = process.env;
const { VALID, VALID_WITH_LETTERS, INVALID_TOO_SHORT, INVALID_TOO_LONG } = MOCK_COMPANY_REGISTRATION_NUMBERS;
const { get, post } = api(app);
const bodyValid = { companyRegNo: VALID, companyName: 'Some name', probabilityOfDefault: 3 };
const bodyValidWithProbabilityOfDefault = { companyRegNo: VALID, companyName: 'Some name', probabilityOfDefault: 3 };
const bodyValidWithoutProbabilityOfDefault = { companyRegNo: VALID, companyName: 'Some name', probabilityOfDefault: undefined };
let axiosMock: MockAdapter;

jest.mock('@ukef/dtfs2-common', () => ({
Expand Down Expand Up @@ -67,16 +68,21 @@ describe('GET /party-db', () => {
});

describe('POST /party-db', () => {
it(`returns a ${HttpStatusCode.Ok} response with a valid body`, async () => {
const { status } = await post(bodyValid).to(`/party-db/`);
it(`returns a ${HttpStatusCode.Ok} response with a valid body with probability of default`, async () => {
const { status } = await post(bodyValidWithProbabilityOfDefault).to(`/party-db/`);

expect(status).toEqual(HttpStatusCode.Ok);
});

it(`returns a ${HttpStatusCode.Ok} response with a valid body without probability of default`, async () => {
const { status } = await post(bodyValidWithoutProbabilityOfDefault).to(`/party-db/`);

expect(status).toEqual(HttpStatusCode.Ok);
});

const invalidBodies = [
{ companyRegNo: null, companyName: 'Some name', probabilityOfDefault: 3 },
{ companyRegNo: VALID, companyName: null, probabilityOfDefault: 3 },
{ companyRegNo: VALID, companyName: 'Some name', probabilityOfDefault: null },
{ companyRegNo: INVALID_TOO_SHORT, companyName: 'Some name', probabilityOfDefault: 3 },
{ companyRegNo: INVALID_TOO_LONG, companyName: 'Some name', probabilityOfDefault: 3 },
];
Expand Down
5 changes: 0 additions & 5 deletions external-api/src/v1/controllers/party-db.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ export const getOrCreateParty = async (
return res.status(HttpStatusCode.BadRequest).send({ status: HttpStatusCode.BadRequest, data: 'Invalid company name' });
}

if (!probabilityOfDefault) {
console.error('No probability of default provided');
return res.status(HttpStatusCode.BadRequest).send({ status: HttpStatusCode.BadRequest, data: 'Invalid probability of default' });
}

const response: { status: number; data: unknown } = await axios({
method: 'post',
url: `${APIM_MDM_URL}customers`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('add partyUrn to deal', () => {
expect(noMatch.tfm.parties.exporter.partyUrn).toEqual('');
});

it('should return the deal with partyUrn is successfully matched', async () => {
it('should return the deal with partyUrn is successfully matched and probability of default is provided', async () => {
mockUpdateDeal();

const deal = {
Expand All @@ -67,6 +67,37 @@ describe('add partyUrn to deal', () => {
expect(match.tfm.parties.exporter.partyUrn).toEqual('testPartyUrn');
});

it('should return the deal with partyUrn is successfully matched and probability of default is undefined', async () => {
mockUpdateDeal();

const deal = {
...MOCK_DEAL,
exporter: {
companiesHouseRegistrationNumber: COMPANY_REGISTRATION_NUMBER.MATCH,
companyName: 'some name',
probabilityOfDefault: undefined,
},
};

const match = await addPartyUrns(deal, generatePortalAuditDetails(MOCK_PORTAL_USERS[0]._id));
expect(match.tfm.parties.exporter.partyUrn).toEqual('testPartyUrn');
});

it('should return the deal with partyUrn is successfully matched and probability of default is not provided', async () => {
mockUpdateDeal();

const deal = {
...MOCK_DEAL,
exporter: {
companiesHouseRegistrationNumber: COMPANY_REGISTRATION_NUMBER.MATCH,
companyName: 'some name',
},
};

const match = await addPartyUrns(deal, generatePortalAuditDetails(MOCK_PORTAL_USERS[0]._id));
expect(match.tfm.parties.exporter.partyUrn).toEqual('testPartyUrn');
});

it('should retain existing tfm data', async () => {
mockUpdateDeal();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ beforeEach(() => {
});

const invalidQueryParameters = [
{
query: {
companyName: 'TEST NAME',
companyRegNo: '12345678',
},
},
{
query: {
companyRegNo: '12345678',
Expand Down Expand Up @@ -130,6 +124,32 @@ it('should allow a probability of default set to its default value', async () =>
expect(result).toBe('TEST_URN');
});

it('should allow a probability of default set to undefined', async () => {
getOrCreatePartyDbInfo.mockResolvedValue([{ partyUrn: 'TEST_URN' }]);

const companyData = { companyRegNo: '12345678', companyName: 'name', probabilityOfDefault: undefined };
abhi-markan marked this conversation as resolved.
Show resolved Hide resolved

const result = await api.getPartyUrn(companyData);

expect(getOrCreatePartyDbInfo).toHaveBeenCalledWith(companyData);
expect(getOrCreatePartyDbInfo).toHaveBeenCalledTimes(1);

expect(result).toBe('TEST_URN');
});

it('should allow a probability of default not provided', async () => {
getOrCreatePartyDbInfo.mockResolvedValue([{ partyUrn: 'TEST_URN' }]);

const companyData = { companyRegNo: '12345678', companyName: 'name' };

const result = await api.getPartyUrn(companyData);

expect(getOrCreatePartyDbInfo).toHaveBeenCalledWith(companyData);
expect(getOrCreatePartyDbInfo).toHaveBeenCalledTimes(1);

expect(result).toBe('TEST_URN');
});

it('should not call getPartyDbInfo', async () => {
getOrCreatePartyDbInfo.mockResolvedValue([{ partyUrn: 'TEST_URN' }]);

Expand Down
5 changes: 0 additions & 5 deletions trade-finance-manager-api/src/v1/controllers/deal.party-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ const getPartyUrn = async ({ companyRegNo, companyName, probabilityOfDefault })
return '';
}

if (!probabilityOfDefault) {
console.error('No probability of default provided');
return '';
}

partyDbInfo = await api.getOrCreatePartyDbInfo({ companyRegNo, companyName, probabilityOfDefault });
} else {
partyDbInfo = await api.getPartyDbInfo({ companyRegNo });
Expand Down
Loading