Skip to content

Commit e313699

Browse files
committed
8.1 time middleware
1 parent d2be926 commit e313699

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎test/server.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ describe("server", () => {
8383
const result = spy.calledWith("GET /json - ::ffff:127.0.0.1");
8484
assert.ok(result);
8585
});
86+
// 8.1
87+
it('should return json `{ time: timestamp }` from the "/now" endpoint', () => {
88+
return request(server)
89+
.get("/now")
90+
.expect("Content-type", /application\/json/)
91+
.expect(200)
92+
.then(response => {
93+
assert.ok(response.body, "Body does not contain json");
94+
// TODO: validate uses middleware
95+
const now = +new Date();
96+
const sendTime = +new Date(response.body.time);
97+
const withinRange = now - sendTime < 3000;
98+
assert.ok(
99+
withinRange,
100+
`Timestamp ${response.body.time} is not within range of 3 seconds`
101+
);
102+
});
103+
});
86104
after(() => {
87105
server.close();
88106
});

0 commit comments

Comments
 (0)