ronantakizawa/codereview-bench huggingface dataset:
Repository: fastify/fastify
File: test/route.3.test.js (JavaScript)

Code before:
      return schema.validate(data)
    }
  }

  fastify.setValidatorCompiler(validatorCompiler)

  fastify.route({
    path: '/foo/:an_id',
    method: 'GET',
    schema: {
      params: { an_id: joi.number() }
    },
    handler (req, res) {
      console.log(req.params)
      t.assert.deepEqual(req.params, { an_id: 42 })
      res.send({ hello: 'world' })
    }
  })

  fastify.inject({
    method: 'GET',
    url: '/foo/42'
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.strictEqual(res.statusCode, 200)
    t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
    done()
  })
})

test('multiple routes with one schema', (t, done) => {
  t.plan(2)

  const fastify = Fastify()

  const schema = {
    query: {
      type: 'object',
      properties: {
        id: { type: 'number' }
      }
    }
  }

  fastify.route({
    schema,
    method: 'GET',
    path: '/first/:id',
    handler (req, res) {
      res.send({ hello: 'world' })
    }

Review comment (suggestion):
```suggestion
    t.assert.deepStrictEqual(res.json(), { hello: 'world' })
```

Code after:
      return schema.validate(data)
    }
  }

  fastify.setValidatorCompiler(validatorCompiler)

  fastify.route({
    path: '/foo/:an_id',
    method: 'GET',
    schema: {
      params: { an_id: joi.number() }
    },
    handler (req, res) {
      t.assert.deepEqual(req.params, { an_id: 42 })
      res.send({ hello: 'world' })
    }
  })

  fastify.inject({
    method: 'GET',
    url: '/foo/42'
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.strictEqual(res.statusCode, 200)
    t.assert.deepStrictEqual(res.json(), { hello: 'world' })
    done()
  })
})

test('multiple routes with one schema', (t, done) => {
  t.plan(2)

  const fastify = Fastify()

  const schema = {
    query: {
      type: 'object',
      properties: {
        id: { type: 'number' }
      }
    }
  }

  fastify.route({
    schema,
    method: 'GET',
    path: '/first/:id',
    handler (req, res) {
      res.send({ hello: 'world' })
    }
  })
Repository: fastify/fastify
File: test/route.3.test.js (JavaScript)

Code before:
  }

  fastify.route({
    method: 'GET',
    path: '/coffee',
    handler: (req, res) => {
      res.send(new Error('Wrong Pot Error'))
    },
    errorHandler: customRouteErrorHandler
  })

  fastify.route({
    method: 'GET',
    path: '/tea',
    handler: (req, res) => {
      res.send(new Error('No tea today'))
    }
  })

  fastify.inject({
    method: 'GET',
    url: '/tea'
  }, (error, res) => {
    t.assert.ifError(error)
    t.assert.strictEqual(res.statusCode, 500)
    t.assert.deepStrictEqual(JSON.parse(res.payload), {
      message: 'No tea today',
      statusCode: 500,
      error: 'Internal Server Error'
    })
    done()
  })
})

test('async error handler for a route', (t, done) => {
  t.plan(4)

  const fastify = Fastify()

  const customRouteErrorHandler = async (error, request, reply) => {
    t.assert.strictEqual(error.message, 'Delayed Pot Error')
    reply.code(418)
    return {
      message: 'Make a brew sometime later',
      statusCode: 418,
      error: 'Delayed Pot Error'
    }
  }

  fastify.route({
    method: 'GET',

Review comment (suggestion):
```suggestion
    t.assert.deepStrictEqual(res.json(), {
```

Code after:

  fastify.route({
    method: 'GET',
    path: '/coffee',
    handler: (req, res) => {
      res.send(new Error('Wrong Pot Error'))
    },
    errorHandler: customRouteErrorHandler
  })

  fastify.route({
    method: 'GET',
    path: '/tea',
    handler: (req, res) => {
      res.send(new Error('No tea today'))
    }
  })

  fastify.inject({
    method: 'GET',
    url: '/tea'
  }, (error, res) => {
    t.assert.ifError(error)
    t.assert.strictEqual(res.statusCode, 500)
    t.assert.deepStrictEqual(res.json(), {
      message: 'No tea today',
      statusCode: 500,
      error: 'Internal Server Error'
    })
    done()
  })
})

test('async error handler for a route', (t, done) => {
  t.plan(4)

  const fastify = Fastify()

  const customRouteErrorHandler = async (error, request, reply) => {
    t.assert.strictEqual(error.message, 'Delayed Pot Error')
    reply.code(418)
    return {
      message: 'Make a brew sometime later',
      statusCode: 418,
      error: 'Delayed Pot Error'
    }
  }

  fastify.route({
    method: 'GET',
    path: '/late-coffee',
Repository: fastify/fastify
File: test/route.3.test.js (JavaScript)

Code before:
  const customRouteErrorHandler = async (error, request, reply) => {
    t.assert.strictEqual(error.message, 'Delayed Pot Error')
    reply.code(418)
    return {
      message: 'Make a brew sometime later',
      statusCode: 418,
      error: 'Delayed Pot Error'
    }
  }

  fastify.route({
    method: 'GET',
    path: '/late-coffee',
    handler: (req, res) => {
      res.send(new Error('Delayed Pot Error'))
    },
    errorHandler: customRouteErrorHandler
  })

  fastify.inject({
    method: 'GET',
    url: '/late-coffee'
  }, (error, res) => {
    t.assert.ifError(error)
    t.assert.strictEqual(res.statusCode, 418)
    t.assert.deepStrictEqual(JSON.parse(res.payload), {
      message: 'Make a brew sometime later',
      statusCode: 418,
      error: 'Delayed Pot Error'
    })
    done()
  })
})


Review comment (suggestion):
```suggestion
    t.assert.deepStrictEqual(res.json(), {
```

Code after:
    t.assert.strictEqual(error.message, 'Delayed Pot Error')
    reply.code(418)
    return {
      message: 'Make a brew sometime later',
      statusCode: 418,
      error: 'Delayed Pot Error'
    }
  }

  fastify.route({
    method: 'GET',
    path: '/late-coffee',
    handler: (req, res) => {
      res.send(new Error('Delayed Pot Error'))
    },
    errorHandler: customRouteErrorHandler
  })

  fastify.inject({
    method: 'GET',
    url: '/late-coffee'
  }, (error, res) => {
    t.assert.ifError(error)
    t.assert.strictEqual(res.statusCode, 418)
    t.assert.deepStrictEqual(res.json(), {
      message: 'Make a brew sometime later',
      statusCode: 418,
      error: 'Delayed Pot Error'
    })
    done()
  })
})
Repository: fastify/fastify
File: test/server.test.js (JavaScript)

Code before:
  }

  try {
    await fastify.listen({ port: '1234hello' })
  } catch (error) {
    t.assert.strictEqual(error.code, 'ERR_SOCKET_BAD_PORT')
  }
})

test('Test for hostname and port', (t, end) => {
  const app = Fastify()
  t.after(() => app.close())
  app.get('/host', (req, res) => {
    const host = 'localhost:8000'
    t.assert.strictEqual(req.host, host)
    t.assert.strictEqual(req.hostname, req.host.split(':')[0])
    t.assert.strictEqual(req.port, Number(req.host.split(':')[1]))
    res.send('ok')
  })

  app.listen({ port: 8000 }, () => {
    sget('http://localhost:8000/host', () => { end() })
  })
})

describe('abort signal', () => {
  test('listen should not start server', (t, end) => {
    t.plan(2)
    function onClose (instance, done) {
      t.assert.equal(instance, fastify)
      done()
      end()
    }
    const controller = new AbortController()

    const fastify = Fastify()
    fastify.addHook('onClose', onClose)
    fastify.listen({ port: 1234, signal: controller.signal }, (err) => {
      t.assert.ifError(err)
    })
    controller.abort()
    t.assert.strictEqual(fastify.server.listening, false)
  })

  test('listen should not start server if already aborted', (t, end) => {
    t.plan(2)
    function onClose (instance, done) {
      t.assert.equal(instance, fastify)
      done()
      end()
    }

Review comment (suggestion):
We don't need to use `describe`. 
```suggestion
test('abort signal', async () => {
```

Also, each subtest should be like:

```js
await t.test('listen should not start server', (t, end) => { end() })
```

Code after:
  }

  try {
    await fastify.listen({ port: '1234hello' })
  } catch (error) {
    t.assert.strictEqual(error.code, 'ERR_SOCKET_BAD_PORT')
  }
})

test('Test for hostname and port', (t, end) => {
  const app = Fastify()
  t.after(() => app.close())
  app.get('/host', (req, res) => {
    const host = 'localhost:8000'
    t.assert.strictEqual(req.host, host)
    t.assert.strictEqual(req.hostname, req.host.split(':')[0])
    t.assert.strictEqual(req.port, Number(req.host.split(':')[1]))
    res.send('ok')
  })

  app.listen({ port: 8000 }, () => {
    sget('http://localhost:8000/host', () => { end() })
  })
})

test('abort signal', async t => {
  await t.test('listen should not start server', (t, end) => {
    t.plan(2)
    function onClose (instance, done) {
      t.assert.equal(instance, fastify)
      done()
      end()
    }
    const controller = new AbortController()

    const fastify = Fastify()
    fastify.addHook('onClose', onClose)
    fastify.listen({ port: 1234, signal: controller.signal }, (err) => {
      t.assert.ifError(err)
    })
    controller.abort()
    t.assert.strictEqual(fastify.server.listening, false)
  })

  await t.test('listen should not start server if already aborted', (t, end) => {
    t.plan(2)
    function onClose (instance, done) {
      t.assert.equal(instance, fastify)
      done()
      end()
    }
Repository: fastify/fastify
File: test/noop-set.test.js (JavaScript)

Code before:
'use strict'

const { test } = require('node:test')
const noopSet = require('../lib/noop-set')

test('does a lot of nothing', async t => {
  const aSet = noopSet()
  t.assert.ok(aSet, 'object')

  const item = {}
  aSet.add(item)
  aSet.add({ another: 'item' })
  aSet.delete(item)
  t.assert.equal(aSet.has(item), true)

  for (const i of aSet) {
    t.fail('should not have any items', i)
  }
})


Review comment (bug):
Also need to updatd `fail` [ref](https://nodejs.org/api/assert.html#assertfailmessage)
```suggestion
    t.assert.fail('should not have any items', i)
```

Code after:
'use strict'

const { test } = require('node:test')
const noopSet = require('../lib/noop-set')

test('does a lot of nothing', async t => {
  const aSet = noopSet()
  t.assert.ok(aSet, 'object')

  const item = {}
  aSet.add(item)
  aSet.add({ another: 'item' })
  aSet.delete(item)
  t.assert.strictEqual(aSet.has(item), true)

  for (const i of aSet) {
    t.assert.fail('should not have any items', i)
  }
})
Repository: fastify/fastify
File: test/noop-set.test.js (JavaScript)

Code before:
'use strict'

const { test } = require('node:test')
const noopSet = require('../lib/noop-set')

test('does a lot of nothing', async t => {
  const aSet = noopSet()
  t.assert.ok(aSet, 'object')

  const item = {}
  aSet.add(item)
  aSet.add({ another: 'item' })
  aSet.delete(item)
  t.assert.equal(aSet.has(item), true)

  for (const i of aSet) {
    t.fail('should not have any items', i)
  }
})


Review comment (suggestion):
nit: can we use `strictEqual` here
```suggestion
  t.assert.strictEqual(aSet.has(item), true)
```

Code after:
'use strict'

const { test } = require('node:test')
const noopSet = require('../lib/noop-set')

test('does a lot of nothing', async t => {
  const aSet = noopSet()
  t.assert.ok(aSet, 'object')

  const item = {}
  aSet.add(item)
  aSet.add({ another: 'item' })
  aSet.delete(item)
  t.assert.strictEqual(aSet.has(item), true)

  for (const i of aSet) {
    t.assert.fail('should not have any items', i)
  }
})
Repository: fastify/fastify
File: test/reply-early-hints.test.js (JavaScript)

Code before:

  fastify.listen({ port: 0 }, (err, address) => {
    t.assert.ifError(err)

    const client = http2.connect(address)
    const req = client.request()

    req.on('headers', (headers) => {
      t.assert.notStrictEqual(headers, undefined)
      t.assert.strictEqual(headers[':status'], 103)
      t.assert.strictEqual(headers.link, '</styles.css>; rel=preload; as=style')
    })

    req.on('response', (headers) => {
      t.assert.strictEqual(headers[':status'], 200)
    })

    let data = ''
    req.on('data', (chunk) => {
      data += chunk
    })

    req.on('end', () => {
      t.assert.strictEqual(data, testResBody)
      client.close()
      fastify.close(t.end)
    })

    req.end()
  })
})


Review comment (refactor):
`t.end` is a `tap` method we should remove this
```suggestion
      fastify.close()
```

Code after:
      link: '</styles.css>; rel=preload; as=style'
    })

    return testResBody
  })

  fastify.listen({ port: 0 }, (err, address) => {
    t.assert.ifError(err)

    const client = http2.connect(address)
    const req = client.request()

    req.on('headers', (headers) => {
      t.assert.notStrictEqual(headers, undefined)
      t.assert.strictEqual(headers[':status'], 103)
      t.assert.strictEqual(headers.link, '</styles.css>; rel=preload; as=style')
    })

    req.on('response', (headers) => {
      t.assert.strictEqual(headers[':status'], 200)
    })

    let data = ''
    req.on('data', (chunk) => {
      data += chunk
    })

    req.on('end', () => {
      t.assert.strictEqual(data, testResBody)
      client.close()
      fastify.close()
      done()
    })

    req.end()
  })
})
Repository: fastify/fastify
File: test/use-semicolon-delimiter.test.js (JavaScript)

Code before:
const sget = require('simple-get').concat

test('use semicolon delimiter default false', t => {
  const fastify = Fastify({})

  t.after(fastify.close())

  fastify.get('/1234;foo=bar', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {})
    })
  })
})

test('use semicolon delimiter set to true', t => {
  const fastify = Fastify({
    useSemicolonDelimiter: true
  })
  t.after(fastify.close())

  fastify.get('/1234', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {
        foo: 'bar'
      })
    })
  })
})


Review comment (suggestion):
Call `done` in after last test assertion
```suggestion
test('use semicolon delimiter set to true', (t, done) => {
  t.plan(4)
```

Code after:
const sget = require('simple-get').concat

test('use semicolon delimiter default false', (t, done) => {
  t.plan(4)

  const fastify = Fastify()

  fastify.get('/1234;foo=bar', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0, }, err => {
    t.assert.ifError(err)
    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {})
      fastify.close()
      done()
    })
  })
})

test('use semicolon delimiter set to true', (t, done) => {
  t.plan(4)
  const fastify = Fastify({
    useSemicolonDelimiter: true
  })

  fastify.get('/1234', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {
        foo: 'bar'
      })
      fastify.close()
      done()
    })
Repository: fastify/fastify
File: test/use-semicolon-delimiter.test.js (JavaScript)

Code before:
  const fastify = Fastify({
    useSemicolonDelimiter: true
  })
  t.after(fastify.close())

  fastify.get('/1234', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {
        foo: 'bar'
      })
    })
  })
})

test('use semicolon delimiter set to false', t => {
  const fastify = Fastify({
    useSemicolonDelimiter: false
  })
  t.after(fastify.close())

  fastify.get('/1234;foo=bar', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {})
    })
  })
})

test('use semicolon delimiter set to false return 404', t => {
  const fastify = Fastify({

Review comment (suggestion):
Call `done` in after last test assertion
```suggestion
test('use semicolon delimiter set to false', (t, done) => {
  t.plan(4)
```

Code after:
test('use semicolon delimiter set to true', (t, done) => {
  t.plan(4)
  const fastify = Fastify({
    useSemicolonDelimiter: true
  })

  fastify.get('/1234', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {
        foo: 'bar'
      })
      fastify.close()
      done()
    })
  })
})

test('use semicolon delimiter set to false', (t, done) => {
  t.plan(4)

  const fastify = Fastify({
    useSemicolonDelimiter: false
  })

  fastify.get('/1234;foo=bar', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {})
      fastify.close()
      done()
Repository: fastify/fastify
File: test/use-semicolon-delimiter.test.js (JavaScript)

Code before:

test('use semicolon delimiter set to false', t => {
  const fastify = Fastify({
    useSemicolonDelimiter: false
  })
  t.after(fastify.close())

  fastify.get('/1234;foo=bar', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {})
    })
  })
})

test('use semicolon delimiter set to false return 404', t => {
  const fastify = Fastify({
    useSemicolonDelimiter: false
  })
  t.after(fastify.close())

  fastify.get('/1234', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 404)
    })
  })
})


Review comment (suggestion):
Call `done` in after last test assertion
```suggestion
test('use semicolon delimiter set to false return 404', (t, done) => {
  t.plan(3)
```

Code after:
    })
  })
})

test('use semicolon delimiter set to false', (t, done) => {
  t.plan(4)

  const fastify = Fastify({
    useSemicolonDelimiter: false
  })

  fastify.get('/1234;foo=bar', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 200)
      t.assert.deepStrictEqual(JSON.parse(body), {})
      fastify.close()
      done()
    })
  })
})

test('use semicolon delimiter set to false return 404', (t, done) => {
  t.plan(3)

  const fastify = Fastify({
    useSemicolonDelimiter: false
  })

  fastify.get('/1234', (req, reply) => {
    reply.send(req.query)
  })

  fastify.listen({ port: 0 }, err => {
    t.assert.ifError(err)

    sget({
      method: 'GET',
      url: 'http://localhost:' + fastify.server.address().port + '/1234;foo=bar'
    }, (err, response, body) => {
      t.assert.ifError(err)
      t.assert.strictEqual(response.statusCode, 404)
Repository: fastify/fastify
File: test/fluent-schema.test.js (JavaScript)

Code before:

  // check body
  fastify.inject({
    method: 'POST',
    url: '/42',
    headers: { 'x-custom': 'me@me.me' },
    query: { surname: 'bar' },
    payload: { name: [1, 2, 3] }
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.strictEqual(res.statusCode, 400)
    t.assert.deepStrictEqual(res.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'body/name must be string' })
  })

  // check response
  fastify.inject({
    method: 'POST',
    url: '/42',
    headers: { 'x-custom': 'me@me.me' },
    query: { surname: 'bar' },
    payload: { name: 'foo' }
  }, (err, res) => {
    t.assert.ifError(err)
    t.assert.strictEqual(res.statusCode, 200)
    t.assert.deepStrictEqual(res.json(), { name: 'a', surname: 'b' })
    done()
  })
})

test('use complex fluent-json-schema object', (t, done) => {
  t.plan(1)
  const fastify = Fastify()

  const addressSchema = S.object()
    .id('#address')
    .prop('line1').required()
    .prop('line2')
    .prop('country').required()
    .prop('city').required()
    .prop('zipcode').required()

  const commonSchemas = S.object()
    .id('https://fastify/demo')
    .definition('addressSchema', addressSchema)

  fastify.addSchema(commonSchemas)

  const bodyJsonSchema = S.object()
    .prop('residence', S.ref('https://fastify/demo#address')).required()
    .prop('office', S.ref('https://fastify/demo#/definitions/addressSchema')).required()


Review comment (suggestion):
This `done` could resolve before the `inject` stuff has completed.

We should migrate this test to `async/await` for simplicity or the `done` must wait all the `inject` calls

Code after:
    payload: { name: [1, 2, 3] }
  })
  t.assert.strictEqual(res4.statusCode, 400)
  t.assert.deepStrictEqual(res4.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'body/name must be string' })

  // check response
  const res5 = await fastify.inject({
    method: 'POST',
    url: '/42',
    headers: { 'x-custom': 'me@me.me' },
    query: { surname: 'bar' },
    payload: { name: 'foo' }
  })
  t.assert.strictEqual(res5.statusCode, 200)
  t.assert.deepStrictEqual(res5.json(), { name: 'a', surname: 'b' })
})

test('use complex fluent-json-schema object', (t, done) => {
  t.plan(1)
  const fastify = Fastify()

  const addressSchema = S.object()
    .id('#address')
    .prop('line1').required()
    .prop('line2')
    .prop('country').required()
    .prop('city').required()
    .prop('zipcode').required()

  const commonSchemas = S.object()
    .id('https://fastify/demo')
    .definition('addressSchema', addressSchema)

  fastify.addSchema(commonSchemas)

  const bodyJsonSchema = S.object()
    .prop('residence', S.ref('https://fastify/demo#address')).required()
    .prop('office', S.ref('https://fastify/demo#/definitions/addressSchema')).required()

  fastify.post('/the/url', { schema: { body: bodyJsonSchema } }, () => { })
  fastify.ready(err => {
    t.assert.ifError(err)
    done()
  })
})

test('use fluent schema and plain JSON schema', (t, done) => {
  t.plan(1)

  const fastify = Fastify()