-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathparameters.test.ts
More file actions
100 lines (88 loc) · 2.7 KB
/
parameters.test.ts
File metadata and controls
100 lines (88 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import nock from "nock";
import { expect } from "chai";
import sinon from "sinon";
import { ShopperProducts } from "../../renderedTemplates";
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 productClient = new ShopperProducts.ShopperProducts({
parameters: {
clientId: CLIENT_ID,
organizationId: ORGANIZATION_ID,
shortCode: SHORT_CODE,
siteId: SITE_ID,
},
});
const options = {
parameters: {
ids: ["ids"],
c_validCustomParam: "custom_param",
},
};
nock(`https://${SHORT_CODE}.api.commercecloud.salesforce.com`)
.get(
`/product/shopper-products/v1/organizations/${ORGANIZATION_ID}/products`
)
.query({
siteId: SITE_ID,
ids: "ids",
c_validCustomParam: "custom_param",
})
.reply(200, MOCK_RESPONSE);
const response = await productClient.getProducts(options);
expect(response).to.be.deep.equal(MOCK_RESPONSE);
});
it("warns user when an unknown param is passed", async () => {
const productClient = new ShopperProducts.ShopperProducts({
parameters: {
clientId: CLIENT_ID,
organizationId: ORGANIZATION_ID,
shortCode: SHORT_CODE,
siteId: SITE_ID,
},
});
const options = {
parameters: {
ids: ["ids"],
unknownParam1: "param1",
unknownParam2: "param2",
},
};
nock.cleanAll();
nock(`https://${SHORT_CODE}.api.commercecloud.salesforce.com`)
.get(
`/product/shopper-products/v1/organizations/${ORGANIZATION_ID}/products`
)
.query({
siteId: SITE_ID,
ids: "ids",
unknownParam1: "param1",
unknownParam2: "param2",
})
.reply(200, MOCK_RESPONSE);
const warnSpy = sinon.spy(console, "warn");
const response = await productClient.getProducts(options);
expect(response).to.be.deep.equal(MOCK_RESPONSE);
expect(
warnSpy.calledWith(
"Found unknown parameter for getProducts: unknownParam1, adding as query parameter anyway"
)
).to.be.true;
expect(
warnSpy.calledWith(
"Found unknown parameter for getProducts: unknownParam2, adding as query parameter anyway"
)
).to.be.true;
});
});