Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joeluong-sfcc committed May 10, 2024
1 parent d1217ae commit 862b8d3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 54 deletions.
1 change: 1 addition & 0 deletions src/lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("setupApis", () => {
"pricing",
"product",
"search",
"seller",
]);
});
});
3 changes: 2 additions & 1 deletion src/static/helperTemplates/index.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
*/

export * as slasHelpers from "./slas";
export * as helpers from "./shopperCustomer";
export const helpers = {}
{{!-- ^ TODO: fix this once custom API PR gets merged in --}}
40 changes: 0 additions & 40 deletions src/static/helperTemplates/shopperCustomer.ts.hbs

This file was deleted.

27 changes: 14 additions & 13 deletions src/test/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
import nock from "nock";
import { expect } from "chai";
import sinon from "sinon";
import { ShopperCustomers } from "../../renderedTemplates/customer/shopperCustomers/shopperCustomers";
import { ShopperProducts } from "../../renderedTemplates/product/shopperProducts/shopperProducts";

const SITE_ID = "SITE_ID";
const CLIENT_ID = "CLIENT_ID";
const SHORT_CODE = "SHORT_CODE";
const ORGANIZATION_ID = "ORGANIZATION_ID";

const MOCK_RESPONSE = { mockResponse: true };

describe("Parameters", () => {
afterEach(() => nock.cleanAll());

it("allow custom query params", async () => {
const customersClient = new ShopperCustomers({
const productClient = new ShopperProducts({
parameters: {
clientId: CLIENT_ID,
organizationId: ORGANIZATION_ID,
Expand All @@ -31,28 +32,28 @@ describe("Parameters", () => {

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

nock(`https://${SHORT_CODE}.api.commercecloud.salesforce.com`)
.post(
`/customer/shopper-customers/v1/organizations/${ORGANIZATION_ID}/customers/actions/login`
.get(
`/product/shopper-products/v1/organizations/${ORGANIZATION_ID}/products`
)
.query({
siteId: SITE_ID,
clientId: CLIENT_ID,
ids: "ids",
c_validCustomParam: "custom_param",
})
.reply(200, MOCK_RESPONSE);

const response = await customersClient.authorizeCustomer(options);
const response = await productClient.getProducts(options);
expect(response).to.be.deep.equal(MOCK_RESPONSE);
});

it("warns user when invalid param is passed", async () => {
const customersClient = new ShopperCustomers({
const productClient = new ShopperProducts({
parameters: {
clientId: CLIENT_ID,
organizationId: ORGANIZATION_ID,
Expand All @@ -63,23 +64,23 @@ describe("Parameters", () => {

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

nock(`https://${SHORT_CODE}.api.commercecloud.salesforce.com`)
.post(
`/customer/shopper-customers/v1/organizations/${ORGANIZATION_ID}/customers/actions/login`
.get(
`/product/shopper-products/v1/organizations/${ORGANIZATION_ID}/products`
)
.query({
siteId: SITE_ID,
clientId: CLIENT_ID,
ids: "ids",
})
.reply(200, MOCK_RESPONSE);

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

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

0 comments on commit 862b8d3

Please sign in to comment.