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

Conversation

guru-aot
Copy link
Collaborator

@guru-aot guru-aot commented Dec 11, 2024

CAS supplier errors enhancement and Unit Test

image

@guru-aot guru-aot self-assigned this Dec 11, 2024
@guru-aot guru-aot added Test Case tickets relating to test cases E2E/Unit tests labels Dec 11, 2024
});

beforeEach(() => {
beforeEach(async () => {
Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot Dec 12, 2024

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",
        ],
      }),
    );

@andrepestana-aot andrepestana-aot self-requested a review December 12, 2024 17:14
Comment on lines 263 to 265
const casKnownErrorArray = casKnownErrors.split("|").map((error) => {
return error.trim();
});
Copy link
Collaborator

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 () => {
Copy link
Collaborator

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.

Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot left a 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 👍

Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 22.05% ( 3786 / 17170 )
Methods: 10.23% ( 219 / 2140 )
Lines: 25.37% ( 3281 / 12935 )
Branches: 13.65% ( 286 / 2095 )

Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 65.43% ( 583 / 891 )
Methods: 59.26% ( 64 / 108 )
Lines: 68.54% ( 464 / 677 )
Branches: 51.89% ( 55 / 106 )

Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 84.94% ( 1342 / 1580 )
Methods: 83.33% ( 135 / 162 )
Lines: 86.45% ( 1129 / 1306 )
Branches: 69.64% ( 78 / 112 )

Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 67.41% ( 5927 / 8792 )
Methods: 65.09% ( 729 / 1120 )
Lines: 71.34% ( 4650 / 6518 )
Branches: 47.49% ( 548 / 1154 )

Copy link
Collaborator

@andrepestana-aot andrepestana-aot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@guru-aot guru-aot added this pull request to the merge queue Dec 12, 2024
Merged via the queue into main with commit 3ae2fa6 Dec 12, 2024
21 checks passed
@guru-aot guru-aot deleted the feature/#3258_CAS_Supplier_Errors_Bug1 branch December 12, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E/Unit tests Test Case tickets relating to test cases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants