Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit 9fe6c7d

Browse files
committed
Add acceptance tests checking documentation tutorials
1 parent 9bc0836 commit 9fe6c7d

11 files changed

Lines changed: 336 additions & 70 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"parser": "flow"
1616
}
1717
],
18+
"no-undef": "error",
1819
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]
1920
},
2021
"extends": ["prettier"],

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ module.exports = {
2828
testEnvironment: "node",
2929

3030
// The glob patterns Jest uses to detect test files
31-
testMatch: ["**/test/unit/**/?(*.)+(spec|test).js?(x)"],
31+
testMatch: ["**/test/unit/**/?(*.)+(spec|test).js?(x)"]
3232
//testMatch: ["**/test/unit/**/options.spec.js"]
3333
};

package-lock.json

Lines changed: 41 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"mocks-server": "./bin/mocks-server"
3131
},
3232
"scripts": {
33-
"lint": "eslint index.js lib test",
33+
"lint": "eslint index.js lib test jest.config.js jest.acceptance.config.js",
3434
"lint-staged": "lint-staged",
3535
"test": "jest",
3636
"test-acceptance": "jest --config=jest.acceptance.config.js",
@@ -64,11 +64,16 @@
6464
"jest": "24.9.0",
6565
"lint-staged": "^9.4.2",
6666
"prettier": "^1.18.2",
67+
"request": "^2.88.0",
68+
"request-promise": "^4.2.5",
6769
"sinon": "^7.5.0"
6870
},
6971
"lint-staged": {
7072
"lib/**/*.js": "eslint",
71-
"test/**/*.js": "eslint"
73+
"test/**/*.js": "eslint",
74+
"index.js": "eslint",
75+
"jest.config.js": "eslint",
76+
"jest.acceptance.config.js": "eslint"
7277
},
7378
"husky": {
7479
"hooks": {

test/.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"globals": {
3+
"jest": true,
4+
"beforeAll": true,
5+
"beforeEach": true,
6+
"afterEach": true,
7+
"afterAll": true,
8+
"describe": true,
9+
"expect": true,
10+
"it": true
11+
}
12+
}

test/acceptance/mocks-server-bin.spec.js renamed to test/acceptance/cli/mocks-server-bin.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Unless required by applicable law or agreed to in writing, software distributed
1111

1212
const path = require("path");
1313

14-
const { CliRunner } = require("../utils");
14+
const { CliRunner } = require("../../utils");
1515

1616
describe("when mocks-server binary is executed", () => {
17-
const binFile = path.resolve(__dirname, "..", "..", "bin", "mocks-server");
17+
const binFile = path.resolve(__dirname, "..", "..", "..", "bin", "mocks-server");
1818
let cliRunner;
1919

2020
it("should throw a controlled error if no behaviors folder is provided", async () => {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright 2019 Javier Brea
3+
4+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
9+
*/
10+
11+
const INITIAL_USERS = [
12+
{
13+
id: 1,
14+
name: "John Doe"
15+
},
16+
{
17+
id: 2,
18+
name: "Jane Doe"
19+
}
20+
];
21+
22+
const getUsers = {
23+
url: "/api/users",
24+
method: "GET",
25+
response: {
26+
status: 200,
27+
body: INITIAL_USERS
28+
}
29+
};
30+
31+
const getUser = {
32+
url: "/api/users/:id",
33+
method: "GET",
34+
response: {
35+
status: 200,
36+
body: {
37+
id: 1,
38+
name: "John Doe"
39+
}
40+
}
41+
};
42+
43+
const getUser2 = {
44+
url: "/api/users/:id",
45+
method: "GET",
46+
response: {
47+
status: 200,
48+
body: {
49+
id: 2,
50+
name: "Jane Doe"
51+
}
52+
}
53+
};
54+
55+
const getRealUser = {
56+
url: "/api/users/:id",
57+
method: "GET",
58+
response: (req, res) => {
59+
const userId = req.params.id;
60+
const user = INITIAL_USERS.find(userData => userData.id === Number(userId));
61+
if (user) {
62+
res.status(200);
63+
res.send(user);
64+
} else {
65+
res.status(404);
66+
res.send({
67+
message: "User not found"
68+
});
69+
}
70+
}
71+
};
72+
73+
module.exports = {
74+
getUsers,
75+
getUser,
76+
getUser2,
77+
getRealUser
78+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2019 Javier Brea
3+
4+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
9+
*/
10+
11+
// /mocks/behaviors.js
12+
13+
const { Behavior } = require("../../../../../index");
14+
15+
const { getUsers, getUser, getUser2, getRealUser } = require("./fixtures/users");
16+
17+
const standard = new Behavior([getUsers, getUser]);
18+
19+
// Extends the standard behavior adding "getUser2" fixture.
20+
const user2 = standard.extend([getUser2]);
21+
22+
// Extends the standard behavior adding "getRealUser" dynamic fixture.
23+
const dynamic = standard.extend([getRealUser]);
24+
25+
module.exports = {
26+
standard,
27+
user2,
28+
dynamic
29+
};

0 commit comments

Comments
 (0)