Skip to content

Commit 3b284b8

Browse files
committed
Rewrite Express kata for Jest/supertest
0 parents  commit 3b284b8

16 files changed

+714
-0
lines changed

.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
],
5+
"plugins": [
6+
"@babel/plugin-proposal-class-properties",
7+
"@babel/plugin-proposal-export-namespace-from",
8+
"@babel/plugin-proposal-object-rest-spread",
9+
"@babel/plugin-proposal-export-default-from",
10+
"@babel/plugin-proposal-optional-chaining"
11+
]
12+
}

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
root = true

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env

.eslintrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"extends": [
3+
"airbnb-base",
4+
"plugin:prettier/recommended"
5+
],
6+
"plugins": [
7+
"import",
8+
"prettier"
9+
],
10+
"env": {
11+
"jest": true
12+
},
13+
"parser": "babel-eslint",
14+
"rules": {
15+
"no-unused-vars": [
16+
"error",
17+
{
18+
"argsIgnorePattern": "next"
19+
}
20+
]
21+
}
22+
}

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
package-lock.json
25+
26+
# Manchester Codes Staff
27+
.walkthrough

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package.json
2+
package-lock.json

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

.vscode/settings.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"[javascript]": {
4+
"editor.formatOnSave": false
5+
},
6+
"[javascriptreact]": {
7+
"editor.formatOnSave": false
8+
},
9+
"prettier.disableLanguages": [
10+
"javascript",
11+
"javascriptreact"
12+
],
13+
"editor.insertSpaces": true,
14+
"editor.tabSize": 2,
15+
"editor.codeActionsOnSave": {
16+
"source.fixAll.eslint": true
17+
}
18+
}

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Express Bootstrap
2+
3+
This project is a boilerplate for Node.js/Express applications. It also comes included with Jest, and Supertest for end-to-end testing.
4+
5+
## Getting started
6+
7+
Ensure your Visual Studio Code application is up to date, and that you have the [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) installed and enabled.
8+
9+
Replace `your-project-folder-name` with the folder name you wish to create for your project and run the below inside your `Projects` folder.
10+
11+
```bash
12+
git clone [email protected]:MCRcodes/express-bootstrap.git your-project-folder-name
13+
cd your-project-folder-name
14+
npm install
15+
npm start
16+
```
17+
18+
Visit [http://localhost:3000/] in your browser and you should see `Hello world!`. You can dive in and start coding your own routes in `src/app.js`.
19+
20+
## Running tests
21+
22+
You can run tests with the `npm test` command.
23+
24+
## Remember: READMEs are important!
25+
26+
When you're finished, be sure to rewrite this one so it's more specific to your project.

__tests__/arrays.test.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const request = require('supertest');
2+
const app = require('../src/app');
3+
4+
describe('/arrays', () => {
5+
describe('POST /element-at-index/{index}', () => {
6+
xit('returns the element at the given index', done => {
7+
request(app)
8+
.post('/arrays/element-at-index/2')
9+
.send({ array: ['cat', 'dog', 'elephant', 'fox'] })
10+
.then(res => {
11+
expect(res.status).toEqual(200);
12+
expect(res.body).toEqual({ result: 'elephant' });
13+
done();
14+
});
15+
});
16+
});
17+
18+
describe('POST /to-string', () => {
19+
xit('returns the stringified array', done => {
20+
request(app)
21+
.post('/arrays/to-string')
22+
.send({ array: ['cat', 'dog', 'elephant', 'fox'] })
23+
.then(res => {
24+
expect(res.status).toEqual(200);
25+
expect(res.body).toEqual({ result: 'cat,dog,elephant,fox' });
26+
done();
27+
});
28+
});
29+
});
30+
31+
describe('POST /append', () => {
32+
xit('returns an array with the value appended', done => {
33+
request(app)
34+
.post('/arrays/append')
35+
.send({
36+
array: ['cat', 'dog', 'elephant', 'fox'],
37+
value: 'gorilla',
38+
})
39+
.then(res => {
40+
expect(res.status).toEqual(200);
41+
expect(res.body).toEqual({ result: ['cat', 'dog', 'elephant', 'fox', 'gorilla'] });
42+
done();
43+
});
44+
});
45+
});
46+
47+
describe('POST /starts-with-vowel', () => {
48+
xit('returns a filtered array of elements starting with a vowel', done => {
49+
request(app)
50+
.post('/arrays/starts-with-vowel')
51+
.send({ array: ['cat', 'dog', 'elephant', 'fox'] })
52+
.then(res => {
53+
expect(res.status).toEqual(200);
54+
expect(res.body).toEqual({ result: ['elephant'] });
55+
done();
56+
});
57+
});
58+
});
59+
60+
describe('POST /remove-element?index={index}', () => {
61+
xit('returns an array with the first element removed', done => {
62+
request(app)
63+
.post('/arrays/remove-element')
64+
.send({ array: ['cat', 'dog', 'elephant', 'fox'] })
65+
.then(res => {
66+
expect(res.status).toEqual(200);
67+
expect(res.body).toEqual({ result: ['dog', 'elephant', 'fox'] });
68+
done();
69+
});
70+
});
71+
72+
xit('returns an array with the element at the given index removed', done => {
73+
request(app)
74+
.post('/arrays/remove-element')
75+
.send({ array: ['cat', 'dog', 'elephant', 'fox'] })
76+
.query({ index: 2 })
77+
.then(res => {
78+
expect(res.status).toEqual(200);
79+
expect(res.body).toEqual({ result: ['cat', 'dog', 'fox'] });
80+
done();
81+
});
82+
});
83+
});
84+
});

0 commit comments

Comments
 (0)