Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
joeluong-sfcc committed Jan 30, 2024
1 parent aa3aa95 commit 8d05e14
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/test/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import nock from "nock";
import { expect } from "chai";
import sinon from "sinon";
import { ShopperCustomers } from "../../renderedTemplates/customer/shopperCustomers/shopperCustomers";

const SITE_ID = "SITE_ID";
Expand Down Expand Up @@ -50,7 +51,7 @@ describe("Parameters", () => {
expect(response).to.be.deep.equal(MOCK_RESPONSE);
});

it("throws error on invalid params", async () => {
it("warns user when invalid param is passed", async () => {
const customersClient = new ShopperCustomers({
parameters: {
clientId: CLIENT_ID,
Expand All @@ -62,20 +63,26 @@ describe("Parameters", () => {

const options = {
parameters: {
c_validCustomParam: "custom_param",
invalidQueryParam: "invalid_param",
},
body: { type: "guest" },
};

let expectedError;
try {
await customersClient.authorizeCustomer(options);
} catch (error) {
expectedError = error;
}
expect(expectedError.message).to.be.equal(
"Invalid Parameter: invalidQueryParam"
);
nock(`https://${SHORT_CODE}.api.commercecloud.salesforce.com`)
.post(
`/customer/shopper-customers/v1/organizations/${ORGANIZATION_ID}/customers/actions/login`
)
.query({
siteId: SITE_ID,
clientId: CLIENT_ID,
})
.reply(200, MOCK_RESPONSE);

const warnSpy = sinon.spy(console, "warn");
const response = await customersClient.authorizeCustomer(options);

expect(response).to.be.deep.equal(MOCK_RESPONSE);
expect(warnSpy.calledWith("Invalid Parameter: invalidQueryParam")).to.be
.true;
});
});

0 comments on commit 8d05e14

Please sign in to comment.