-
Notifications
You must be signed in to change notification settings - Fork 14
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
#3258 - CAS supplier errors enhancement and Unit Test #4078
Conversation
}); | ||
|
||
beforeEach(() => { | ||
beforeEach(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization should of the mocks should happen once and we should try to reset them.
If there is no other solution in sight right now we can consider moving forward with this.
Can you try the below one, please?
it("Should throw error when CAS API to create site for existing supplier with existing SIN payload data was provided.", async () => {
// Arrange
mockAuthenticationResponseOnce(httpService).mockResolvedValue({
data: {
SUPPLIER_NUMBER: "9999999",
SUPPLIER_SITE_CODE: "123",
},
});
const supplierData: CreateExistingSupplierSiteData = {
supplierNumber: "9999999",
emailAddress: "[email protected]",
supplierSite: {
addressLine1: "Street-Special Characters-ãñè-Maximum",
city: "City Name Over Maximum Length",
provinceCode: "BC",
postalCode: "h1h h2h",
},
};
//Act
httpService.axiosRef.post = jest.fn().mockImplementationOnce(() => {
const error = new AxiosError(
"Request failed with status code 400",
"ERR_BAD_REQUEST",
{
headers: new AxiosHeaders(),
},
{},
{
status: HttpStatusCode.BadRequest,
statusText: "Bad Request",
headers: new AxiosHeaders(),
config: { headers: new AxiosHeaders() },
data: {
"CAS-Returned-Messages":
"[0034] SIN is already in use. | [9999] Duplicate Supplier , Reason: [0065]- Possible duplicate exists, please use online form",
},
},
);
throw error;
});
//Assert
await expect(
casService.createSiteForExistingSupplier(supplierData),
).rejects.toThrow(
expect.objectContaining({
message: "CAS Bad Request Errors",
name: CAS_BAD_REQUEST,
objectInfo: [
"[0034] SIN is already in use.",
"[9999] Duplicate Supplier , Reason: [0065]- Possible duplicate exists, please use online form",
],
}),
);
const casKnownErrorArray = casKnownErrors.split("|").map((error) => { | ||
return error.trim(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, it can be simplified as below.
const casKnownErrorArray = casKnownErrors
.split("|")
.map((error) => error.trim());`
@@ -64,4 +66,60 @@ describe("CASService-createSiteForExistingSupplier", () => { | |||
DEFAULT_CAS_AXIOS_AUTH_HEADER, | |||
); | |||
}); | |||
|
|||
it("Should throw error when CAS API to create site for existing supplier with existing SIN payload data was provided.", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please adjust the test description as below?
Should throw error when CAS API to create site for existing supplier with existing SIN payload data was provided and some CAS validation failed.
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick fix, looks good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
CAS supplier errors enhancement and Unit Test