Skip to content

Commit

Permalink
added test for ref strategy (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlalmes authored Aug 8, 2022
1 parent d98f5b8 commit efd94e5
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions test/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2024,4 +2024,105 @@ describe('generator', () => {
`);
}
});

test('with no refs', () => {
const schemas = { emails: z.array(z.string().email()) };

const appRouter = trpc.router<any, OpenApiMeta>().mutation('refs', {
meta: { openapi: { enabled: true, method: 'POST', path: '/refs' } },
input: z.object({ allowed: schemas.emails, blocked: schemas.emails }),
output: z.object({ allowed: schemas.emails, blocked: schemas.emails }),
resolve: () => ({ allowed: [], blocked: [] }),
});

const openApiDocument = generateOpenApiDocument(appRouter, {
title: 'tRPC OpenAPI',
version: '1.0.0',
baseUrl: 'http://localhost:3000/api',
});

expect(openApiSchemaValidator.validate(openApiDocument).errors).toEqual([]);
expect(openApiDocument.paths['/refs']!.post!.requestBody).toMatchInlineSnapshot(`
Object {
"content": Object {
"application/json": Object {
"schema": Object {
"additionalProperties": false,
"properties": Object {
"allowed": Object {
"items": Object {
"format": "email",
"type": "string",
},
"type": "array",
},
"blocked": Object {
"items": Object {
"format": "email",
"type": "string",
},
"type": "array",
},
},
"required": Array [
"allowed",
"blocked",
],
"type": "object",
},
},
},
"required": true,
}
`);
expect(openApiDocument.paths['/refs']!.post!.responses[200]).toMatchInlineSnapshot(`
Object {
"content": Object {
"application/json": Object {
"schema": Object {
"additionalProperties": false,
"properties": Object {
"data": Object {
"additionalProperties": false,
"properties": Object {
"allowed": Object {
"items": Object {
"format": "email",
"type": "string",
},
"type": "array",
},
"blocked": Object {
"items": Object {
"format": "email",
"type": "string",
},
"type": "array",
},
},
"required": Array [
"allowed",
"blocked",
],
"type": "object",
},
"ok": Object {
"enum": Array [
true,
],
"type": "boolean",
},
},
"required": Array [
"ok",
"data",
],
"type": "object",
},
},
},
"description": "Successful response",
}
`);
});
});

0 comments on commit efd94e5

Please sign in to comment.