Skip to content

Commit a3598cf

Browse files
committed
format
1 parent d187f91 commit a3598cf

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

back-end/test/protected.test.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// set the app NODE_ENV environment variable to 'test' in case the app is set up to alter its behavior in such case
22
// in our case, the morgan logging module is turned off when this is set to 'test'
3-
process.env.NODE_ENV = "test"
3+
process.env.NODE_ENV = "test";
44

55
// include the testing dependencies
6-
const chai = require("chai")
7-
const chaiHttp = require("chai-http")
8-
chai.use(chaiHttp) // use the chai-http middleware to simplify testing routes
9-
const expect = chai.expect // the assertion library in the style using the word 'expect'
10-
const should = chai.should() // the same assertion library in the style using the word 'should'
6+
const chai = require("chai");
7+
const chaiHttp = require("chai-http");
8+
chai.use(chaiHttp); // use the chai-http middleware to simplify testing routes
9+
const expect = chai.expect; // the assertion library in the style using the word 'expect'
10+
const should = chai.should(); // the same assertion library in the style using the word 'should'
1111

1212
// import the server
13-
const server = require("../app")
13+
const server = require("../app");
1414

1515
// a group of tests related to the /protected route
1616
describe("Protected", () => {
@@ -24,11 +24,11 @@ describe("Protected", () => {
2424
.request(server)
2525
.get("/protected")
2626
.end((err, res) => {
27-
res.should.have.status(401) // use 'should' to make BDD-style assertions
28-
done() // resolve the Promise that these tests create so mocha can move on
29-
})
30-
})
31-
})
27+
res.should.have.status(401); // use 'should' to make BDD-style assertions
28+
done(); // resolve the Promise that these tests create so mocha can move on
29+
});
30+
});
31+
});
3232

3333
/**
3434
* test the GET /protected route when logged in
@@ -37,38 +37,38 @@ describe("Protected", () => {
3737
// test a protected route when logged in... passport auth should allow it
3838

3939
// let's first create a valid JWT token to use in the requests where we want to be logged in
40-
const jwt = require("jsonwebtoken")
41-
const User = require("../models/User")
42-
const user = new User({ username: "test", password: "test" })
43-
const token = user.generateJWT()
40+
const jwt = require("jsonwebtoken");
41+
const User = require("../models/User");
42+
const user = new User({ username: "test", password: "test" });
43+
const token = user.generateJWT();
4444

4545
it("it should return a 200 HTTP response code", done => {
4646
chai
4747
.request(server)
4848
.get("/protected")
4949
.set("Authorization", `JWT ${token}`) // set JWT authentication headers to simulate a logged-in user, using the token we created at top
5050
.end((err, res) => {
51-
res.should.have.status(200) // use should to make BDD-style assertions
52-
done() // resolve the Promise that these tests create so mocha can move on
53-
})
54-
})
51+
res.should.have.status(200); // use should to make BDD-style assertions
52+
done(); // resolve the Promise that these tests create so mocha can move on
53+
});
54+
});
5555

5656
it("it should return an object with specific properties", done => {
5757
chai
5858
.request(server)
5959
.get("/protected")
6060
.set("Authorization", `JWT ${token}`) // set JWT authentication headers to simulate a logged-in user, using the token we created at top
6161
.end((err, res) => {
62-
res.body.should.be.a("object") // our route sends back an object
62+
res.body.should.be.a("object"); // our route sends back an object
6363
// res.body.should.have.property("success")
6464
// res.body.should.have.property("user")
6565
// res.body.should.have.property("message")
66-
res.body.should.have.keys("success", "user", "message") // a way to test the presence of an exact set of keys in the response object
67-
expect(res.body).to.have.deep.property("user.id", 1) // check for exact value of a nested value
68-
expect(res.body).to.have.deep.property("user.username") // check for existence of a nested value
66+
res.body.should.have.keys("success", "user", "message"); // a way to test the presence of an exact set of keys in the response object
67+
expect(res.body).to.have.deep.property("user.id", 1); // check for exact value of a nested value
68+
expect(res.body).to.have.deep.property("user.username"); // check for existence of a nested value
6969

70-
done() // resolve the Promise that these tests create so mocha can move on
71-
})
72-
})
73-
})
74-
})
70+
done(); // resolve the Promise that these tests create so mocha can move on
71+
});
72+
});
73+
});
74+
});

0 commit comments

Comments
 (0)