feat(api): GET /api/missions + POST /api/missions/{id}/accept

Routes call ensureSave first (mission functions assume an initialized save),
map MissionError to 404/409 and non-integer path ids to 400. OpenAPI spec in
code gains both paths + the Mission schema (12 -> 14 paths); openapi.test.ts
covers the new shapes.
This commit is contained in:
2026-09-29 01:55:41 +00:00
parent f356ffbe93
commit 786a5ec001
4 changed files with 138 additions and 0 deletions
+19
View File
@@ -8,6 +8,8 @@ describe('OpenAPI spec', () => {
'/api/crew',
'/api/explore',
'/api/jump',
'/api/missions',
'/api/missions/{id}/accept',
'/api/research',
'/api/ship',
'/api/ship/build',
@@ -58,6 +60,23 @@ describe('OpenAPI spec', () => {
}
});
it('describes the mission endpoints: GET /api/missions → Mission[], POST accept with error responses', () => {
const missions = openApiSpec.paths['/api/missions'].get.responses[200].content['application/json'].schema;
expect(missions.type).toBe('array');
expect((missions.items as { $ref: string }).$ref).toBe('#/components/schemas/Mission');
const props = openApiSpec.components.schemas.Mission.properties;
expect(Object.keys(props)).toEqual(['id', 'type', 'description', 'targetSystemId', 'conditionKind', 'progressTarget', 'progress', 'rewardKind', 'rewardQty', 'state']);
expect((props.type as { enum: string[] }).enum).toEqual(['DELIVER', 'EXPLORE', 'FIND']);
expect((props.state as { enum: string[] }).enum).toEqual(['AVAILABLE', 'ACTIVE', 'DONE']);
const post = openApiSpec.paths['/api/missions/{id}/accept'].post;
expect(post.responses[200].content['application/json'].schema.items.$ref).toBe('#/components/schemas/Mission');
for (const status of ['400', '404', '409'] 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');