36 lines
902 B
TypeScript
36 lines
902 B
TypeScript
import Fastify from 'fastify'
|
|
import apophisPlugin from 'apophis-fastify'
|
|
|
|
const fastify = Fastify()
|
|
|
|
// APOPHIS auto-registers @fastify/swagger
|
|
await fastify.register(apophisPlugin, {})
|
|
|
|
// Behavioral contract: what you send is what you get back.
|
|
// This is not a structural test — the schema already validates shape.
|
|
// This checks that the server does not mutate or drop fields.
|
|
fastify.post('/echo', {
|
|
schema: {
|
|
'x-category': 'observer',
|
|
'x-ensures': [
|
|
'response_body(this) == request_body(this)'
|
|
],
|
|
body: {
|
|
type: 'object',
|
|
properties: { message: { type: 'string' } }
|
|
},
|
|
response: {
|
|
200: {
|
|
type: 'object',
|
|
properties: { message: { type: 'string' } }
|
|
}
|
|
}
|
|
}
|
|
}, async (req) => req.body)
|
|
|
|
await fastify.ready()
|
|
|
|
// Run contract tests
|
|
const result = await fastify.apophis.contract({ runs: 10 })
|
|
console.log(result.summary)
|