|
| 1 | +import { loadTemplate, openApiSchema } from './helpers' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | + |
| 4 | +const template = loadTemplate('private-api.yaml') |
| 5 | + |
| 6 | +const paths = template['paths'] as Record<string, Record<string, unknown>> |
| 7 | + |
| 8 | +describe('private-api.yaml structure', () => { |
| 9 | + it('is a valid OpenAPI 3.x document', () => { |
| 10 | + expect(openApiSchema.safeParse(template).success).toBe(true) |
| 11 | + }) |
| 12 | + |
| 13 | + it('has title', () => { |
| 14 | + const info = template['info'] as Record<string, string> |
| 15 | + expect(info['title']).toBe('Open Banking Credential Issuer Private API') |
| 16 | + }) |
| 17 | +}) |
| 18 | + |
| 19 | +describe('private-api.yaml paths', () => { |
| 20 | + const expectedPaths = ['/basic-function', '/authorization', '/session'] |
| 21 | + |
| 22 | + it.each(expectedPaths)('has path: %s', (path) => { |
| 23 | + expect(paths).toHaveProperty(path) |
| 24 | + }) |
| 25 | + |
| 26 | + it('/basic-function has POST with aws_proxy integration', () => { |
| 27 | + const post = paths['/basic-function']?.['post'] as Record<string, unknown> |
| 28 | + const integration = post['x-amazon-apigateway-integration'] as Record<string, string> |
| 29 | + expect(integration['type']).toBe('aws_proxy') |
| 30 | + }) |
| 31 | + |
| 32 | + it('/authorization has GET method', () => { |
| 33 | + expect(paths['/authorization']).toHaveProperty('get') |
| 34 | + }) |
| 35 | + |
| 36 | + it('/session has POST method', () => { |
| 37 | + expect(paths['/session']).toHaveProperty('post') |
| 38 | + }) |
| 39 | +}) |
| 40 | + |
| 41 | +describe('private-api.yaml components', () => { |
| 42 | + const components = template['components'] as Record<string, Record<string, unknown>> |
| 43 | + |
| 44 | + it('defines SessionHeader parameter', () => { |
| 45 | + expect(components['parameters']).toHaveProperty('SessionHeader') |
| 46 | + }) |
| 47 | + |
| 48 | + it('defines required schemas', () => { |
| 49 | + const schemas = components['schemas'] |
| 50 | + expect(schemas).toHaveProperty('Authorization') |
| 51 | + expect(schemas).toHaveProperty('AuthorizationResponse') |
| 52 | + expect(schemas).toHaveProperty('Error') |
| 53 | + expect(schemas).toHaveProperty('Session') |
| 54 | + }) |
| 55 | +}) |
| 56 | + |
| 57 | +describe('private-api.yaml request validators', () => { |
| 58 | + const validators = template['x-amazon-apigateway-request-validators'] as Record<string, unknown> |
| 59 | + |
| 60 | + it('defines Validate both', () => { |
| 61 | + expect(validators).toHaveProperty('Validate both') |
| 62 | + }) |
| 63 | + |
| 64 | + it('defines Validate Param only', () => { |
| 65 | + expect(validators).toHaveProperty('Validate Param only') |
| 66 | + }) |
| 67 | +}) |
0 commit comments