diff --git a/src/services/__tests__/fixtures/callback.json b/src/services/__tests__/fixtures/callback.json new file mode 100644 index 00000000..5ca4af74 --- /dev/null +++ b/src/services/__tests__/fixtures/callback.json @@ -0,0 +1,64 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0", + "title": "Foo" + }, + "components": { + "callbacks": { + "Test": { + "post": { + "operationId": "testCallback", + "description": "Test callback.", + "requestBody": { + "content": { + "application/json": { + "schema": { + "title": "TestTitle", + "type": "object", + "description": "Test description", + "properties": { + "type": { + "type": "string", + "description": "The type of response.", + "enum": [ + "TestResponse.Complete" + ] + }, + "status": { + "type": "string", + "enum": [ + "FAILURE", + "SUCCESS" + ] + } + }, + "required": [ + "status" + ] + } + } + } + }, + "parameters": [ + { + "name": "X-Test-Header", + "in": "header", + "required": true, + "example": "1", + "description": "This is a test header parameter", + "schema": { + "type": "string" + } + } + ], + "responses": { + "204": { + "description": "Test response." + } + } + } + } + } + } + } \ No newline at end of file diff --git a/src/services/__tests__/models/Callback.test.ts b/src/services/__tests__/models/Callback.test.ts new file mode 100644 index 00000000..11f1d6a8 --- /dev/null +++ b/src/services/__tests__/models/Callback.test.ts @@ -0,0 +1,26 @@ +import { CallbackModel } from '../../models/Callback'; +import { OpenAPIParser } from '../../OpenAPIParser'; +import { RedocNormalizedOptions } from '../../RedocNormalizedOptions'; + +const opts = new RedocNormalizedOptions({}); + +describe('Models', () => { + describe('CallbackModel', () => { + let parser; + const spec = require('../fixtures/callback.json'); + parser = new OpenAPIParser(spec, undefined, opts); + + test('basic callback details', () => { + const callback = new CallbackModel( + parser, + 'Test.Callback', + { $ref: '#/components/callbacks/Test' }, + opts, + ); + expect(callback.name).toEqual('Test.Callback'); + expect(callback.operations.length).toEqual(0); + expect(callback.paths).toBeDefined(); + expect(callback.expanded).toBeUndefined(); + }); + }); +});