-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkaoApp.test.js
44 lines (35 loc) · 1.06 KB
/
kaoApp.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
const { t } = require("tap")
const request = require("supertest")
const listen = require("./koaApp")
t.test("server tests", t => {
// Start a server on a random port for all tests
const server = listen()
// Before ending the tests, close the server and free the port
t.tearDown(() => server.close())
t.test("create counter with basic auth", async t => {
const { headers } = await request(server)
.post("/counter")
.auth("The Dude", "abides")
.expect(201)
.expect("Location", /counter/)
t.test("and access it with correct credentials", async t => {
await request(headers.location)
.get("")
.auth("The Dude", "abides")
.expect(200)
})
t.test("and access it with invalid credentials", async t => {
await request(headers.location)
.get("")
.auth("The Dude", "does abide")
.expect(403)
})
t.test("and access it without credentials", async t => {
await request(headers.location)
.get("")
.expect(401)
})
t.end()
})
t.end()
})