Skip to content

Commit

Permalink
test(@nestjs/swagger): test patched document for yaml and json route …
Browse files Browse the repository at this point in the history
…using fastify
  • Loading branch information
botflux committed Jun 30, 2023
1 parent 3e297ad commit bc70d13
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion e2e/fastify.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ describe('Fastify Swagger', () => {
);
SwaggerModule.setup('api', app, swaggerDocument, {
jsonDocumentUrl: JSON_CUSTOM_URL,
yamlDocumentUrl: YAML_CUSTOM_URL
yamlDocumentUrl: YAML_CUSTOM_URL,
patchDocument: (req, res, document) => ({
...document,
info: {
...document.info,
description: (req as Record<string, any>).query.description
}
})
});

await app.init();
Expand All @@ -134,12 +141,27 @@ describe('Fastify Swagger', () => {
expect(Object.keys(response.body).length).toBeGreaterThan(0);
});

it('patched JSON document should be served', async () => {
const response = await request(app.getHttpServer()).get(
`${JSON_CUSTOM_URL}?description=My%20custom%20description`
);

expect(response.body.info.description).toBe("My custom description");
});

it('yaml document should be server in the custom url', async () => {
const response = await request(app.getHttpServer()).get(YAML_CUSTOM_URL);

expect(response.status).toEqual(200);
expect(response.text.length).toBeGreaterThan(0);
});

it('patched YAML document should be served', async () => {
const response = await request(app.getHttpServer()).get(
`${YAML_CUSTOM_URL}?description=My%20custom%20description`
);
expect(response.text).toContain("My custom description");
});
});

describe('custom documents endpoints with global prefix', () => {
Expand Down

0 comments on commit bc70d13

Please sign in to comment.