Skip to content

Commit

Permalink
feat: [#188339189] remove DUPLICATE_LICENSE_TYPE_ERROR logic
Browse files Browse the repository at this point in the history
  • Loading branch information
FarazA22 committed Oct 10, 2024
1 parent 5871c1e commit d9bc270
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
BusinessAddressesClient,
BusinessIdsAndNamesClient,
ChecklistItemsForAllApplicationsClient,
DUPLICATE_LICENSE_TYPE_ERROR,
LicenseApplicationIdsForAllBusinessIdsClient,
} from "@client/dynamics/license-status/regulatedBusinessDynamicsLicenseStatusTypes";
import { AccessTokenClient } from "@client/dynamics/types";
Expand Down Expand Up @@ -313,58 +312,5 @@ describe("RegulatedBusinessDynamicsLicenseStatusClient", () => {
});
await expect(client(nameAndAddress)).rejects.toEqual(500);
});

it("throws error when formatDynamicsApplications throws DUPLICATE_LICENSE_TYPE_ERROR error", async () => {
const address = generateLicenseSearchAddress({
addressLine1: nameAndAddress.addressLine1,
zipCode: nameAndAddress.zipCode,
});

const businessIdAndLicenseSearchNameAndAddresses = [
{
businessId: "businessId1",
name: "Business1",
addresses: [address],
},
{
businessId: "businessId2",
name: "Business2",
addresses: [generateLicenseSearchAddress({})],
},
];

const professionNameAndLicenseType1 = "some profession name1";
const expirationdate = getCurrentDateISOString();

const licenseStatusChecklistResult = [
generateLicenseStatusChecklistResult({
professionNameAndLicenseType: professionNameAndLicenseType1,
licenseStatus: "ACTIVE",
expirationDateISO: expirationdate,
}),
generateLicenseStatusChecklistResult({
professionNameAndLicenseType: professionNameAndLicenseType1,
licenseStatus: "ACTIVE",
expirationDateISO: expirationdate,
}),
];

stubBusinessAddressesClient.getBusinessAddressesForAllBusinessIds.mockResolvedValue(
businessIdAndLicenseSearchNameAndAddresses
);
stubChecklistItemsClient.getChecklistItemsForAllApplications.mockResolvedValue(
licenseStatusChecklistResult
);

client = RegulatedBusinessDynamicsLicenseStatusClient({
dynamicsAccessTokenClient: stubAccessTokenClient,
rgbBusinessIdsAndNamesClient: stubBusinessIdsAndNamesClient,
rgbBusinessAddressesClient: stubBusinessAddressesClient,
rgbLicenseApplicationIdsClient: stubLicenseApplicationIdsClient,
rgbChecklistItemsClient: stubChecklistItemsClient,
});

await expect(client(nameAndAddress)).rejects.toThrow(DUPLICATE_LICENSE_TYPE_ERROR);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface RgbApiConfiguration {
rgbChecklistItemsClient: ChecklistItemsForAllApplicationsClient;
}

const DEBUG_RegulatedBusinessDynamicsLicenseSearch = false;
const DEBUG_RegulatedBusinessDynamicsLicenseSearch = false; // this variable exists in updateLicenseStatusFactory; enable both for debugging

export const RegulatedBusinessDynamicsLicenseStatusClient = (
rgbApiConfiguration: RgbApiConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { formatRegulatedBusinessDynamicsApplications } from "@client/dynamics/license-status/formatRegulatedBusinessDynamicsApplications";
import { DUPLICATE_LICENSE_TYPE_ERROR } from "@client/dynamics/license-status/regulatedBusinessDynamicsLicenseStatusTypes";
import { generateLicenseStatusChecklistResult } from "@test/factories";

describe("formatRegulatedBusinessDynamicsApplications", () => {
Expand All @@ -21,16 +20,15 @@ describe("formatRegulatedBusinessDynamicsApplications", () => {
});
});

it("throws DUPLICATE_LICENSE_TYPE_ERROR error when there is a duplicate professionNameAndLicenseType", () => {
const checklistResult1 = generateLicenseStatusChecklistResult({
professionNameAndLicenseType: "duplicate profession name and license type",
});
const checklistResult2 = generateLicenseStatusChecklistResult({
professionNameAndLicenseType: "duplicate profession name and license type",
});
it("returns one license when duplicate checklist results are provided to the fn", () => {
const checklistResult1 = generateLicenseStatusChecklistResult({});

expect(() => formatRegulatedBusinessDynamicsApplications([checklistResult1, checklistResult2])).toThrow(
DUPLICATE_LICENSE_TYPE_ERROR
);
expect(formatRegulatedBusinessDynamicsApplications([checklistResult1, checklistResult1])).toEqual({
[checklistResult1.professionNameAndLicenseType]: {
licenseStatus: checklistResult1.licenseStatus,
expirationDateISO: checklistResult1.expirationDateISO,
checklistItems: checklistResult1.checklistItems,
},
});
});
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { LicenseChecklistResponse, LicenseStatusResults } from "@api/types";
import { DUPLICATE_LICENSE_TYPE_ERROR } from "@client/dynamics/license-status/regulatedBusinessDynamicsLicenseStatusTypes";
import { LicenseName } from "@shared/license";

export const formatRegulatedBusinessDynamicsApplications = (
applications: LicenseChecklistResponse[]
): LicenseStatusResults => {
return applications.reduce((result: LicenseStatusResults, app) => {
if (app.professionNameAndLicenseType in result) {
throw new Error(DUPLICATE_LICENSE_TYPE_ERROR);
} else {
const key = app.professionNameAndLicenseType as LicenseName;
result[key] = {
licenseStatus: app.licenseStatus,
expirationDateISO: app.expirationDateISO,
checklistItems: app.checklistItems,
};
}
const key = app.professionNameAndLicenseType as LicenseName;
result[key] = {
licenseStatus: app.licenseStatus,
expirationDateISO: app.expirationDateISO,
checklistItems: app.checklistItems,
};
return result;
}, {});
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ export type LicenseApplicationIdResponse = {

export const ACTIVE_STATECODE = 0;
export const MAIN_APP_END_DIGITS = "00";
export const DUPLICATE_LICENSE_TYPE_ERROR = "DUPLICATE_LICENSE_TYPE_ERROR";
2 changes: 1 addition & 1 deletion api/src/domain/user/updateLicenseStatusFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { modifyCurrentBusiness } from "@shared/test";
import { Business, TaskProgress, UserData } from "@shared/userData";

const DEBUG_RegulatedBusinessDynamicsLicenseSearch = false;
const DEBUG_RegulatedBusinessDynamicsLicenseSearch = false; // this variable exists in RegulatedBusinessDynamicsLicenseStatusClient; enable both for debugging

const getLicenseTasksProgress = (licenseStatusResult: LicenseStatusResults): Record<string, TaskProgress> => {
const licenseTasksProgress: Record<string, TaskProgress> = {};
Expand Down

0 comments on commit d9bc270

Please sign in to comment.