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

#3258 - CAS supplier errors enhancement and Unit Test #4078

Merged
merged 5 commits into from
Dec 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
initializeService,
mockAuthenticationResponseOnce,
} from "./cas-test.utils";
import { AxiosError, AxiosHeaders, HttpStatusCode } from "axios";
import { CAS_BAD_REQUEST } from "@sims/integrations/constants";

describe("CASService-createSiteForExistingSupplier", () => {
let casService: CASService;
Expand Down Expand Up @@ -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 and some CAS validation failed.", 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: {},
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",
],
}),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,13 @@ export class CASService {
const casKnownErrors = error.response.data[
CAS_RETURNED_MESSAGES
] as string;
const casKnownErrorArray = casKnownErrors
.split("|")
.map((error) => error.trim());
throw new CustomNamedError(
"CAS Bad Request Errors",
CAS_BAD_REQUEST,
casKnownErrors.trim().split(" | "),
casKnownErrorArray,
);
}
throw new Error(defaultMessage, { cause: error });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
v-if="item.errors && item.errors.length > 0"
:icon="
isExpanded(internalItem)
? '$expanderExpandIcon'
: '$expanderCollapseIcon'
? '$expanderCollapseIcon'
: '$expanderExpandIcon'
"
variant="text"
@click="toggleExpand(internalItem)"
Expand Down
Loading