-
Notifications
You must be signed in to change notification settings - Fork 2
/
favorites.test.js
54 lines (43 loc) · 1.97 KB
/
favorites.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { request, expect } = require("./config");
describe("POST /favorites", function () {
it("requires authentication", async function () {
const response = await request.post("/favorites").send({
airport_id: "JFK",
note: "My usual layover when visiting family",
});
expect(response.status).to.eql(401);
});
it("allows an user to save and delete their favorite airports", async function () {
// Check that a user can create a favorite.
const postResponse = await request
.post("/favorites")
.set("Authorization", `Bearer token=${process.env.AIRPORT_GAP_TOKEN}`)
.send({
airport_id: "JFK",
note: "My usual layover when visiting family",
});
expect(postResponse.status).to.eql(201);
expect(postResponse.body.data.attributes.airport.name).to.eql("John F Kennedy International Airport");
expect(postResponse.body.data.attributes.note).to.eql("My usual layover when visiting family");
const favoriteId = postResponse.body.data.id;
// Check that a user can update the note of the created favorite.
const putResponse = await request
.put(`/favorites/${favoriteId}`)
.set("Authorization", `Bearer token=${process.env.AIRPORT_GAP_TOKEN}`)
.send({
note: "My usual layover when visiting family and friends",
});
expect(putResponse.status).to.eql(200);
expect(putResponse.body.data.attributes.note).to.eql("My usual layover when visiting family and friends");
// Check that a user can delete the created favorite.
const deleteResponse = await request
.delete(`/favorites/${favoriteId}`)
.set("Authorization", `Bearer token=${process.env.AIRPORT_GAP_TOKEN}`);
expect(deleteResponse.status).to.eql(204);
// Verify that the record was deleted.
const getResponse = await request
.get(`/favorites/${favoriteId}`)
.set("Authorization", `Bearer token=${process.env.AIRPORT_GAP_TOKEN}`);
expect(getResponse.status).to.eql(404);
});
});