api+openapi: GET /api/tech + POST /api/research with 400/404/409/422 mapping

This commit is contained in:
2026-09-29 00:30:10 +00:00
parent 8818f0928d
commit 7b0227cde9
4 changed files with 160 additions and 0 deletions
+19
View File
@@ -8,11 +8,13 @@ describe('OpenAPI spec', () => {
'/api/crew',
'/api/explore',
'/api/jump',
'/api/research',
'/api/ship',
'/api/ship/build',
'/api/ship/expand',
'/api/ship/upgrade',
'/api/system',
'/api/tech',
'/api/version',
'/api/world',
]);
@@ -39,6 +41,23 @@ describe('OpenAPI spec', () => {
}
});
it('describes the tech endpoints: GET /api/tech → Tech[], POST /api/research with error responses', () => {
const tech = openApiSpec.paths['/api/tech'].get.responses[200].content['application/json'].schema;
expect(tech.type).toBe('array');
expect((tech.items as { $ref: string }).$ref).toBe('#/components/schemas/Tech');
const techProps = openApiSpec.components.schemas.Tech.properties;
expect(Object.keys(techProps)).toEqual(['id', 'slug', 'name', 'costKind', 'costQty', 'prereqs', 'effect', 'state', 'missingPrereqs']);
expect((techProps.state as { enum: string[] }).enum).toEqual(['RESEARCHED', 'AVAILABLE', 'LOCKED']);
const post = openApiSpec.paths['/api/research'].post;
expect(post.requestBody.content['application/json'].schema.$ref).toBe('#/components/schemas/ResearchRequest');
expect(post.responses[200].content['application/json'].schema.items.$ref).toBe('#/components/schemas/Tech');
for (const status of ['400', '404', '409', '422'] as const) {
expect(post.responses[status].content['application/json'].schema.$ref).toBe('#/components/schemas/Error');
}
});
it('describes /api/crew as an array of CrewMember and crewFound on ExploreResult', () => {
const crew = openApiSpec.paths['/api/crew'].get.responses[200].content['application/json'].schema;
expect(crew.type).toBe('array');