8000 chore: removed simple-get from lock test (#6186) · fastify/fastify@a6b357c · GitHub
[go: up one dir, main page]

Skip to content

Commit a6b357c

Browse files
authored
chore: removed simple-get from lock test (#6186)
1 parent 0a0b969 commit a6b357c

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

test/http-methods/lock.test.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const { test } = require('node:test')
4-
const sget = require('simple-get').concat
54
const fastify = require('../../fastify')()
65
fastify.addHttpMethod('LOCK', { hasBody: true })
76

@@ -57,52 +56,53 @@ test('can be created - lock', t => {
5756
})
5857

5958
test('lock test', async t => {
60-
await fastify.listen({ port: 0 })
59+
const fastifyServer = await fastify.listen({ port: 0 })
6160
t.after(() => {
6261
fastify.close()
6362
})
6463
// the body test uses a text/plain content type instead of application/xml because it requires
6564
// a specific content type parser
66-
await t.test('request with body - lock', (t, done) => {
65+
await t.test('request with body - lock', async (t) => {
6766
t.plan(3)
68-
sget({
69-
url: `http://localhost:${fastify.server.address().port}/test/a.txt`,
67+
68+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
69+
method: 'LOCK',
7070
headers: { 'content-type': 'text/plain' },
71-
body: bodySample,
72-
method: 'LOCK'
73-
}, (err, response, body) => {
74-
t.assert.ifError(err)
75-
t.assert.strictEqual(response.statusCode, 200)
76-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
77-
done()
71+
body: bodySample
7872
})
73+
74+
t.assert.ok(result.ok)
75+
t.assert.strictEqual(result.status, 200)
76+
const body = await result.text()
77+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
7978
})
8079

81-
await t.test('request with body and no content type (415 error) - lock', (t, done) => {
80+
await t.test('request with body and no content type (415 error) - lock', async (t) => {
8281
t.plan(3)
83-
sget({
84-
url: `http://localhost:${fastify.server.address().port}/test/a.txt`,
82+
83+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
84+
method: 'LOCK',
8585
body: bodySample,
86-
method: 'LOCK'
87-
}, (err, response, body) => {
88-
t.assert.ifError(err)
89-
t.assert.strictEqual(response.statusCode, 415)
90-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
91-
done()
86+
headers: { 'content-type': undefined }
9287
})
88+
89+
t.assert.ok(!result.ok)
90+
t.assert.strictEqual(result.status, 415)
91+
const body = await result.text()
92+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
9393
})
9494

95-
await t.test('request without body - lock', (t, done) => {
95+
await t.test('request without body - lock', async (t) => {
9696
t.plan(3)
97-
sget({
98-
url: `http://localhost:${fastify.server.address().port}/test/a.txt`,
99-
headers: { 'content-type': 'text/plain' },
100-
method: 'LOCK'
101-
}, (err, response, body) => {
102-
t.assert.ifError(err)
103-
t.assert.strictEqual(response.statusCode, 200)
104-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
105-
done()
97+
98+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
99+
method: 'LOCK',
100+
headers: { 'content-type': 'text/plain' }
106101
})
102+
103+
t.assert.ok(result.ok)
104+
t.assert.strictEqual(result.status, 200)
105+
const body = await result.text()
106+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
107107
})
108108
})

0 commit comments

Comments
 (0)
0