|
1 |
| -const { test } = require("tap"); |
| 1 | +const { test } = require('tap') |
2 | 2 |
|
3 |
| -test("Should return 200 on GET request", async t => { |
4 |
| - t.plan(1); |
| 3 | +test('Should return 200 on GET request', async t => { |
| 4 | + t.plan(1) |
5 | 5 |
|
6 |
| - const app = require("fastify")(); |
| 6 | + const app = require('fastify')() |
7 | 7 |
|
8 |
| - app.register(require("..")); |
9 |
| - app.get("/", (req, reply) => { |
10 |
| - return { hello: "world" }; |
11 |
| - }); |
| 8 | + app.register(require('..')) |
| 9 | + app.get('/', (req, reply) => { |
| 10 | + return { hello: 'world' } |
| 11 | + }) |
12 | 12 |
|
13 |
| - await app.ready(); |
| 13 | + await app.ready() |
14 | 14 |
|
15 |
| - const response = await app.inject({ |
16 |
| - method: "GET", |
17 |
| - url: "/", |
18 |
| - }); |
| 15 | + const response = await app.inject({ |
| 16 | + method: 'GET', |
| 17 | + url: '/' |
| 18 | + }) |
19 | 19 |
|
20 |
| - t.equal(response.statusCode, 200); |
21 |
| -}); |
| 20 | + t.equal(response.statusCode, 200) |
| 21 | +}) |
22 | 22 |
|
23 |
| -test("Should return 405 on POST request", async t => { |
24 |
| - t.plan(1); |
| 23 | +test('Should return 405 on POST request', async t => { |
| 24 | + t.plan(1) |
25 | 25 |
|
26 |
| - const app = require("fastify")(); |
| 26 | + const app = require('fastify')() |
27 | 27 |
|
28 |
| - app.register(require("..")); |
29 |
| - app.post("/", (req, reply) => { |
30 |
| - return { hello: "world" }; |
31 |
| - }); |
| 28 | + app.register(require('..')) |
| 29 | + app.post('/', (req, reply) => { |
| 30 | + return { hello: 'world' } |
| 31 | + }) |
32 | 32 |
|
33 |
| - await app.ready(); |
| 33 | + await app.ready() |
34 | 34 |
|
35 |
| - const response = await app.inject({ |
36 |
| - method: "POST", |
37 |
| - url: "/", |
38 |
| - }); |
| 35 | + const response = await app.inject({ |
| 36 | + method: 'POST', |
| 37 | + url: '/' |
| 38 | + }) |
39 | 39 |
|
40 |
| - t.equal(response.statusCode, 405); |
41 |
| -}); |
| 40 | + t.equal(response.statusCode, 405) |
| 41 | +}) |
42 | 42 |
|
43 |
| -test("Should return default body if none is specified", async t => { |
44 |
| - t.plan(1); |
| 43 | +test('Should return default body if none is specified', async t => { |
| 44 | + t.plan(1) |
45 | 45 |
|
46 |
| - const app = require("fastify")(); |
| 46 | + const app = require('fastify')() |
47 | 47 |
|
48 |
| - app.register(require("..")); |
49 |
| - app.post("/", (req, reply) => { |
50 |
| - return { hello: "world" }; |
51 |
| - }); |
| 48 | + app.register(require('..')) |
| 49 | + app.post('/', (req, reply) => { |
| 50 | + return { hello: 'world' } |
| 51 | + }) |
52 | 52 |
|
53 |
| - await app.ready(); |
| 53 | + await app.ready() |
54 | 54 |
|
55 |
| - const response = await app.inject({ |
56 |
| - method: "POST", |
57 |
| - url: "/", |
58 |
| - }); |
| 55 | + const response = await app.inject({ |
| 56 | + method: 'POST', |
| 57 | + url: '/' |
| 58 | + }) |
59 | 59 |
|
60 |
| - const bodyResponse = JSON.parse(response.body); |
61 |
| - t.same(bodyResponse, { error: "Method not allowed" }); |
62 |
| -}); |
| 60 | + const bodyResponse = JSON.parse(response.body) |
| 61 | + t.same(bodyResponse, { error: 'Method not allowed' }) |
| 62 | +}) |
63 | 63 |
|
64 |
| -test("Should return custom body if it is specified", async t => { |
65 |
| - t.plan(1); |
| 64 | +test('Should return custom body if it is specified', async t => { |
| 65 | + t.plan(1) |
66 | 66 |
|
67 |
| - const app = require("fastify")(); |
| 67 | + const app = require('fastify')() |
68 | 68 |
|
69 |
| - const customPayload = { error: "Custom error" }; |
70 |
| - app.register(require(".."), { errorPayload: customPayload }); |
71 |
| - app.post("/", (req, reply) => { |
72 |
| - return { hello: "world" }; |
73 |
| - }); |
| 69 | + const customPayload = { error: 'Custom error' } |
| 70 | + app.register(require('..'), { errorPayload: customPayload }) |
| 71 | + app.post('/', (req, reply) => { |
| 72 | + return { hello: 'world' } |
| 73 | + }) |
74 | 74 |
|
75 |
| - await app.ready(); |
| 75 | + await app.ready() |
76 | 76 |
|
77 |
| - const response = await app.inject({ |
78 |
| - method: "POST", |
79 |
| - url: "/", |
80 |
| - }); |
| 77 | + const response = await app.inject({ |
| 78 | + method: 'POST', |
| 79 | + url: '/' |
| 80 | + }) |
81 | 81 |
|
82 |
| - const bodyResponse = JSON.parse(response.body); |
83 |
| - t.same(bodyResponse, customPayload); |
84 |
| -}); |
| 82 | + const bodyResponse = JSON.parse(response.body) |
| 83 | + t.same(bodyResponse, customPayload) |
| 84 | +}) |
85 | 85 |
|
86 |
| -test("Should return custom code if it is specified", async t => { |
87 |
| - t.plan(1); |
| 86 | +test('Should return custom code if it is specified', async t => { |
| 87 | + t.plan(1) |
88 | 88 |
|
89 |
| - const app = require("fastify")(); |
| 89 | + const app = require('fastify')() |
90 | 90 |
|
91 |
| - const customPayload = { error: "Custom error" }; |
92 |
| - app.register(require(".."), { httpStatusCode: 500 }); |
93 |
| - app.post("/", (req, reply) => { |
94 |
| - return { hello: "world" }; |
95 |
| - }); |
| 91 | + app.register(require('..'), { httpStatusCode: 500 }) |
| 92 | + app.post('/', (req, reply) => { |
| 93 | + return { hello: 'world' } |
| 94 | + }) |
96 | 95 |
|
97 |
| - await app.ready(); |
| 96 | + await app.ready() |
98 | 97 |
|
99 |
| - const response = await app.inject({ |
100 |
| - method: "POST", |
101 |
| - url: "/", |
102 |
| - }); |
| 98 | + const response = await app.inject({ |
| 99 | + method: 'POST', |
| 100 | + url: '/' |
| 101 | + }) |
103 | 102 |
|
104 |
| - t.equal(response.statusCode, 500); |
105 |
| -}); |
| 103 | + t.equal(response.statusCode, 500) |
| 104 | +}) |
0 commit comments