Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 97df704

Browse files
committed
Add unit test for config method
1 parent f3d8dcb commit 97df704

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

src/commands.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
const { settings, config } = require("@mocks-server/admin-api-client");
1+
const adminApiClient = require("@mocks-server/admin-api-client");
22

33
const setBehavior = behavior => {
4-
return settings.update({
4+
return adminApiClient.settings.update({
55
behavior
66
});
77
};
88

99
const setDelay = delay => {
10-
return settings.update({
10+
return adminApiClient.settings.update({
1111
delay
1212
});
1313
};
1414

1515
const setSettings = newSettings => {
16-
return settings.update(newSettings);
16+
return adminApiClient.settings.update(newSettings);
1717
};
1818

1919
// TODO, remove when admin-api-client supports adminApiPath option
2020
const mapConfig = customConfig => {
21-
const configToSet = customConfig;
21+
const configToSet = {};
2222
if (customConfig.adminApiPath) {
2323
configToSet.apiPath = customConfig.adminApiPath;
2424
}
25-
return config(configToSet);
25+
if (customConfig.baseUrl) {
26+
configToSet.baseUrl = customConfig.baseUrl;
27+
}
28+
return adminApiClient.config(configToSet);
2629
};
2730

2831
module.exports = {

test-e2e/app-data-provider/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "app-fetch",
2+
"name": "app-data-provider",
33
"version": "1.0.0",
44
"private": true,
55
"dependencies": {

test/commands.spec.js

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,71 @@
11
const sinon = require("sinon");
2-
const { settings } = require("@mocks-server/admin-api-client");
2+
const adminApiClient = require("@mocks-server/admin-api-client");
33

4-
const { setBehavior, setDelay, setSettings } = require("../src/commands");
4+
const { setBehavior, setDelay, setSettings, config } = require("../src/commands");
55

6-
describe("register", () => {
6+
describe("commands", () => {
77
let sandbox;
88

99
beforeEach(() => {
1010
sandbox = sinon.createSandbox();
11-
sandbox.stub(settings, "update");
11+
sandbox.stub(adminApiClient.settings, "update");
12+
sandbox.stub(adminApiClient, "config");
1213
});
1314

1415
afterEach(() => {
1516
sandbox.restore();
1617
});
1718

18-
describe("commands", () => {
19-
describe("setBehavior command", () => {
20-
it("should call to update behavior", () => {
21-
setBehavior("foo-behavior");
22-
expect(
23-
settings.update.calledWith({
24-
behavior: "foo-behavior"
25-
})
26-
).toBe(true);
27-
});
19+
describe("setBehavior command", () => {
20+
it("should call to update behavior", () => {
21+
setBehavior("foo-behavior");
22+
expect(
23+
adminApiClient.settings.update.calledWith({
24+
behavior: "foo-behavior"
25+
})
26+
).toBe(true);
27+
});
28+
});
29+
30+
describe("setDelay command", () => {
31+
it("should call to update delay", () => {
32+
setDelay(3000);
33+
expect(
34+
adminApiClient.settings.update.calledWith({
35+
delay: 3000
36+
})
37+
).toBe(true);
2838
});
39+
});
40+
41+
describe("setSettings command", () => {
42+
it("should call to update delay", () => {
43+
setSettings("foo");
44+
expect(adminApiClient.settings.update.calledWith("foo")).toBe(true);
45+
});
46+
});
2947

30-
describe("setDelay command", () => {
31-
it("should call to update delay", () => {
32-
setDelay(3000);
33-
expect(
34-
settings.update.calledWith({
35-
delay: 3000
36-
})
37-
).toBe(true);
48+
describe("config method", () => {
49+
it("should call to config admin-api-client baseUrl", () => {
50+
config({
51+
baseUrl: "foo"
3852
});
53+
expect(
54+
adminApiClient.config.calledWith({
55+
baseUrl: "foo"
56+
})
57+
).toBe(true);
3958
});
4059

41-
describe("setSettings command", () => {
42-
it("should call to update delay", () => {
43-
setSettings("foo");
44-
expect(settings.update.calledWith("foo")).toBe(true);
60+
it("should call to config admin-api-client apiPath with adminApiPath value", () => {
61+
config({
62+
adminApiPath: "foo"
4563
});
64+
expect(
65+
adminApiClient.config.calledWith({
66+
apiPath: "foo"
67+
})
68+
).toBe(true);
4669
});
4770
});
4871
});

0 commit comments

Comments
 (0)