Skip to content

Commit ed8fc5b

Browse files
committed
Adding prettier
1 parent 44aa817 commit ed8fc5b

11 files changed

Lines changed: 63 additions & 50 deletions

File tree

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"semi": true,
3+
"printWidth": 120,
4+
"tabWidth": 2,
5+
"useTabs": false,
6+
"singleQuote": true,
7+
"trailingComma": "all",
8+
"bracketSpacing": true,
9+
"jsxBracketSameLine": false,
10+
"arrowParens": "avoid"
11+
}

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
"main": "index.js",
66
"scripts": {
77
"start": "node index.js",
8-
"test:acceptance": "NODE_ENV=test mocha --opts test/acceptance/mocha.opts test/acceptance --recursive",
98
"test": "jest",
109
"lint": "eslint .",
11-
"lint:fix": "eslint --fix ."
10+
"lint:fix": "eslint --fix .",
11+
"prettier:check": "prettier -c 'src/**/*.js'",
12+
"prettier:fix": "prettier --write 'src/**/*.js'"
1213
},
1314
"engines": {
1415
"node": ">=8.4.0"
@@ -34,6 +35,7 @@
3435
"jest": "^24.8.0",
3536
"nock": "^10.0.6",
3637
"nodemon": "^1.19.0",
38+
"prettier": "1.17.0",
3739
"supertest": "^4.0.2"
3840
}
3941
}

src/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ const Github = require('./resources/github');
66

77
const app = express();
88

9-
const setupApp = async(githubResource = new Github()) => {
9+
const setupApp = async (githubResource = new Github()) => {
1010
app.use(bodyParser.json());
1111
app.use('/', routeSetup(githubResource));
1212

1313
await database.connect();
1414

1515
return app;
1616
};
17-
const closeApp = async() => await database.close();
17+
const closeApp = async () => await database.close();
1818

1919
module.exports = {
2020
setupApp,
21-
closeApp
21+
closeApp,
2222
};

src/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const bunyan = require('bunyan');
22

3-
module.exports = bunyan.createLogger({name: 'nasa_app'});
3+
module.exports = bunyan.createLogger({ name: 'nasa_app' });

src/resources/__tests__/github.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ const Github = require('../github');
22

33
describe('Github Resource', () => {
44
const fakeRequest = {
5-
get: jest.fn()
5+
get: jest.fn(),
66
};
77
const githubResource = new Github(fakeRequest);
88
afterEach(() => jest.clearAllMocks());
99

10-
it('should return the followers count for a given github user', async() => {
11-
fakeRequest.get.mockResolvedValueOnce({data: {followers: 120}});
10+
it('should return the followers count for a given github user', async () => {
11+
fakeRequest.get.mockResolvedValueOnce({ data: { followers: 120 } });
1212

1313
const response = await githubResource.getFollowerCount('waldemarnt');
14-
expect(response).toEqual({followers:120});
14+
expect(response).toEqual({ followers: 120 });
1515
});
16-
it('should return not found when the user doenst exist', async() => {
17-
fakeRequest.get.mockRejectedValueOnce({response: {data: 'Not Found', status: 404}});
16+
it('should return not found when the user doenst exist', async () => {
17+
fakeRequest.get.mockRejectedValueOnce({ response: { data: 'Not Found', status: 404 } });
1818

1919
const response = await githubResource.getFollowerCount('odkasodksaodk');
20-
expect(response).toEqual({error: 'Not Found'});
20+
expect(response).toEqual({ error: 'Not Found' });
2121
});
22-
it('should return error when a general error happens', async() => {
23-
fakeRequest.get.mockRejectedValueOnce({response: {data: 'Error', status: 500}});
22+
it('should return error when a general error happens', async () => {
23+
fakeRequest.get.mockRejectedValueOnce({ response: { data: 'Error', status: 500 } });
2424

2525
const response = await githubResource.getFollowerCount('waldemarnt');
26-
expect(response).toEqual({error: 'Error'});
26+
expect(response).toEqual({ error: 'Error' });
2727
});
2828
});

src/resources/github.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class Github {
99
let response;
1010
try {
1111
const { data } = await this.request.get(`https://api.github.com/users/${login}`);
12-
response = {followers: data.followers};
13-
} catch(error) {
14-
const {status, data } = error.response;
15-
if(status == 404) {
16-
response = {error: data}
17-
}else {
18-
response = {error: 'Error'}
12+
response = { followers: data.followers };
13+
} catch (error) {
14+
const { status, data } = error.response;
15+
if (status == 404) {
16+
response = { error: data };
17+
} else {
18+
response = { error: 'Error' };
1919
}
2020
}
2121
return response;

src/routes/__tests__/index.di.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,29 @@ describe('Github resource with di', () => {
1010
request = supertest(app);
1111
});
1212

13-
afterAll(async() => await closeApp());
13+
afterAll(async () => await closeApp());
1414

1515
describe('route /', () => {
1616
describe('when a GET request is done to / endpoint', () => {
17-
18-
test('should respond with the followers count', async() => {
17+
test('should respond with the followers count', async () => {
1918
const fakeRequest = {
20-
get: () => Promise.resolve({data: { followers: 120 } })
19+
get: () => Promise.resolve({ data: { followers: 120 } }),
2120
};
2221
githubResource.request = fakeRequest;
2322

2423
const response = await request.get('/waldemarnt/followers');
25-
expect(response.body).toEqual({followers:120});
24+
expect(response.body).toEqual({ followers: 120 });
2625
});
2726

28-
test('should throw error when the user is not found', async() => {
27+
test('should throw error when the user is not found', async () => {
2928
const fakeRequest = {
30-
get: () => Promise.reject({response: {data: 'Not Found', status: 404}})
29+
get: () => Promise.reject({ response: { data: 'Not Found', status: 404 } }),
3130
};
3231
githubResource.request = fakeRequest;
3332

3433
const response = await request.get('/an_invalid_user/followers');
35-
expect(response.body).toEqual({error: 'Not Found'});
34+
expect(response.body).toEqual({ error: 'Not Found' });
3635
});
3736
});
3837
});
39-
4038
});

src/routes/__tests__/index.jest.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@ describe('Github resource with jest', () => {
1111
request = supertest(app);
1212
});
1313

14-
afterAll(async() => await closeApp());
14+
afterAll(async () => await closeApp());
1515

1616
describe('route /', () => {
1717
describe('when a GET request is done to / endpoint', () => {
18-
19-
test('should respond with the followers count', async() => {
20-
axios.get.mockResolvedValue({data: { followers: 120 } });
18+
test('should respond with the followers count', async () => {
19+
axios.get.mockResolvedValue({ data: { followers: 120 } });
2120

2221
const response = await request.get('/waldemarnt/followers');
23-
expect(response.body).toEqual({followers:120});
22+
expect(response.body).toEqual({ followers: 120 });
2423
});
2524

26-
test('should throw error when the user is not found', async() => {
27-
axios.get.mockRejectedValue({response: {data: 'Not Found', status: 404}});
25+
test('should throw error when the user is not found', async () => {
26+
axios.get.mockRejectedValue({ response: { data: 'Not Found', status: 404 } });
2827

2928
const response = await request.get('/an_invalid_user/followers');
30-
expect(response.body).toEqual({error: 'Not Found'});
29+
expect(response.body).toEqual({ error: 'Not Found' });
3130
});
3231
});
3332
});
34-
3533
});

src/routes/__tests__/index.nock.test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,30 @@ describe('Github resource with nock', () => {
1313
afterEach(() => {
1414
nock.cleanAll();
1515
});
16-
afterAll(async() => await closeApp());
16+
afterAll(async () => await closeApp());
1717

1818
describe('route /', () => {
1919
describe('when a GET request is done to / endpoint', () => {
20-
21-
test('should respond with the followers count', async() => {
20+
test('should respond with the followers count', async () => {
2221
nock('https://api.github.com')
2322
.defaultReplyHeaders({ 'access-control-allow-origin': '*' })
2423
.get('/users/waldemarnt')
2524
.reply(200, {
26-
followers: 120
25+
followers: 120,
2726
});
2827

2928
const response = await request.get('/waldemarnt/followers');
30-
expect(response.body).toEqual({followers:120});
29+
expect(response.body).toEqual({ followers: 120 });
3130
});
3231

33-
test('should throw error when the user is not found', async() => {
32+
test('should throw error when the user is not found', async () => {
3433
nock('https://api.github.com')
3534
.defaultReplyHeaders({ 'access-control-allow-origin': '*' })
3635
.get('/users/an_invalid_user')
3736
.reply(404, 'Not Found');
3837
const response = await request.get('/an_invalid_user/followers');
39-
expect(response.body).toEqual({error: 'Not Found'});
38+
expect(response.body).toEqual({ error: 'Not Found' });
4039
});
4140
});
4241
});
43-
4442
});

0 commit comments

Comments
 (0)