Add callback model test

This commit is contained in:
Jonathan Bailey 2019-11-13 14:14:08 -05:00
parent 44ce9c5ddb
commit 43142d5384
2 changed files with 90 additions and 0 deletions

View File

@ -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."
}
}
}
}
}
}
}

View File

@ -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();
});
});
});