Skip to content

Commit 8284b9c

Browse files
committed
Fix lint errors
1 parent 785af73 commit 8284b9c

File tree

4 files changed

+45
-47
lines changed

4 files changed

+45
-47
lines changed

features/env/database.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
1-
const {Before, AfterAll, BeforeAll} = require('cucumber');
1+
/* eslint no-console: off */
2+
const { Before, AfterAll } = require('cucumber');
23
const mongoose = require('mongoose');
34
const sinon = require('sinon');
45

56
const userSchema = require('../../human-connection-api/server/models/users.model.js');
67
const contributionSchema = require('../../human-connection-api/server/models/contributions.model.js');
78

8-
mongoose.connect("mongodb://localhost/hc_api_test");
9+
mongoose.connect('mongodb://localhost/hc_api_test');
910
const db = mongoose.connection;
1011

11-
let app = sinon.stub();
12-
sinon.stub(app, 'get').callsFake(function() {
13-
return mongoose;
14-
});
12+
const app = sinon.stub();
13+
sinon.stub(app, 'get').callsFake(() => mongoose);
1514

16-
let User, Contribution;
15+
let User;
16+
let Contribution;
1717
db.on('error', console.error.bind(console, 'connection error:'));
18-
db.once('open', function() {
18+
db.once('open', () => {
1919
// initialize models needed in step definitions
2020
User = userSchema(app);
2121
Contribution = contributionSchema(app);
2222
});
2323

2424
// Asynchronous Promise
25-
Before(function(_, callback) {
26-
let promises = [User, Contribution].map((model) => {
27-
return model.remove();
28-
});
25+
Before((_, callback) => {
26+
const promises = [User, Contribution].map(model => model.remove());
2927
Promise.all(promises).then(() => {
3028
callback();
3129
});
3230
});
3331

34-
AfterAll(function(callback) {
32+
AfterAll((callback) => {
3533
db.close();
3634
callback();
3735
});

features/env/hooks.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
const {AfterAll, BeforeAll} = require('cucumber');
1+
/* eslint no-console: off */
2+
const { AfterAll, BeforeAll } = require('cucumber');
23
const { spawn } = require('child_process');
34
const waitOn = require('wait-on');
45

56
let hcApi;
67

78
// Asynchronous Callback
8-
BeforeAll({timeout: 30*1000}, function (callback) {
9+
BeforeAll({ timeout: 30 * 1000 }, (callback) => {
910
hcApi = spawn('node', ['server/'], {
1011
cwd: './human-connection-api/',
1112
env: {
12-
'NODE_ENV': 'test'
13-
}
13+
NODE_ENV: 'test',
14+
},
1415
});
1516

1617
hcApi.stdout.on('data', (data) => {
@@ -21,15 +22,15 @@ BeforeAll({timeout: 30*1000}, function (callback) {
2122
console.log(`stderr: ${data}`);
2223
});
2324

24-
waitOn({ resources: ['tcp:3030'], timeout: 30000 }, function (err) {
25-
if (err) { return handleError(err); }
26-
callback();
25+
waitOn({ resources: ['tcp:3030'], timeout: 30000 }, (err) => {
26+
if (err) throw (err);
27+
return callback();
2728
});
2829
});
2930

3031
// Asynchronous Promise
31-
AfterAll(function () {
32+
AfterAll(() => {
3233
// perform some shared teardown
3334
hcApi.kill();
34-
return Promise.resolve()
35+
return Promise.resolve();
3536
});

features/step_definitions/steps.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
const { Given, When, Then } = require('cucumber');
22
const fetch = require('node-fetch');
33
const mongoose = require('mongoose');
4-
const expect = require('chai').expect;
4+
const { expect } = require('chai');
55
// Hack: Directly accessing the default password hashing function
66
const encrypt = require('../../node_modules/feathers-authentication-local/lib/utils/hash');
77

8-
let currentUser, currentUserPassword, httpResponse, currentUserAccessToken;
8+
let currentUser;
9+
let currentUserPassword;
10+
let httpResponse;
11+
let currentUserAccessToken;
912
const hcBackendUrl = 'http://localhost:3030';
1013

1114

12-
function authenticate(email, plainTextPassword){
15+
function authenticate(email, plainTextPassword) {
1316
const formData = {
14-
email: email,
17+
email,
1518
password: plainTextPassword,
1619
strategy: 'local',
1720
};
1821
return fetch(`${hcBackendUrl}/authentication`, {
1922
method: 'post',
2023
body: JSON.stringify(formData),
2124
headers: { 'Content-Type': 'application/json' },
22-
}).then(response => response.json()).then((json) => {
23-
return json.accessToken;
24-
});
25+
}).then(response => response.json()).then(json => json.accessToken);
2526
}
2627

27-
Given('the Human Connection API is up and running', function () {
28+
Given('the Human Connection API is up and running', () => {
2829
// Just documentation
2930
});
3031

31-
Given("there is a 3rd party application running, e.g. 'Democracy'", function () {
32+
Given("there is a 3rd party application running, e.g. 'Democracy'", () => {
3233
// Just documentation
3334
});
3435

35-
Given('there is an organization in Human Connection with these credentials:', function (dataTable) {
36+
Given('there is an organization in Human Connection with these credentials:', (dataTable) => {
3637
const User = mongoose.model('users');
37-
params = dataTable.hashes()[0];
38+
const params = dataTable.hashes()[0];
3839
return encrypt(params.password).then((hashedPassword) => {
3940
currentUserPassword = params.password; // remember plain text password
4041
params.password = hashedPassword; // hashed password goes into db
@@ -43,22 +44,20 @@ Given('there is an organization in Human Connection with these credentials:', fu
4344
});
4445
});
4546

46-
Given('I am authenticated', function () {
47-
return authenticate(currentUser.email, currentUserPassword).then((accessToken) => {
48-
currentUserAccessToken = accessToken;
49-
});
50-
});
47+
Given('I am authenticated', () => authenticate(currentUser.email, currentUserPassword).then((accessToken) => {
48+
currentUserAccessToken = accessToken;
49+
}));
5150

52-
Given('my user account is verified', function () {
51+
Given('my user account is verified', () => {
5352
// Write code here that turns the phrase above into concrete actions
5453
currentUser.isVerified = true;
5554
return currentUser.save();
5655
});
5756

58-
When('I send a POST request to {string} with:', function (route, body, callback) {
59-
let params = {
57+
When('I send a POST request to {string} with:', (route, body, callback) => {
58+
const params = {
6059
method: 'post',
61-
body: body,
60+
body,
6261
headers: { 'Content-Type': 'application/json' },
6362
};
6463
if (currentUserAccessToken) {
@@ -70,15 +69,15 @@ When('I send a POST request to {string} with:', function (route, body, callback)
7069
});
7170
});
7271

73-
Then('there is an access token in the response:', function (docString) {
72+
Then('there is an access token in the response:', () => {
7473
expect(httpResponse.accessToken).to.be.a('string');
7574
expect(httpResponse.accessToken.length).to.eq(342);
7675
});
7776

78-
Then('a new post should be created', function (callback) {
77+
Then('a new post should be created', (callback) => {
7978
const Contribution = mongoose.model('contributions');
80-
Contribution.find({}, function(err, contributions){
81-
if(err) throw(err);
79+
Contribution.find({}, (err, contributions) => {
80+
if (err) throw (err);
8281
expect(contributions).to.have.lengthOf(1);
8382
expect(contributions[0].type).to.eq('post');
8483
callback();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"author": "Robert Schaefer <[email protected]>",
1919
"license": "MIT",
2020
"scripts": {
21-
"lint": "eslint --ext mjs .",
21+
"lint": "eslint features/ index.mjs",
2222
"start": "node --experimental-modules index.mjs",
2323
"test": "cucumber-js"
2424
},

0 commit comments

Comments
 (0)