Skip to content

Commit

Permalink
test: 2 failing tests
Browse files Browse the repository at this point in the history
amended test to catch error, need help

Signed-off-by: Douglas McConnachie <[email protected]>
  • Loading branch information
dougal83 committed Apr 16, 2020
1 parent 3a4ddd5 commit 3fe2df2
Showing 1 changed file with 96 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

import {Application, createBindingFromClass} from '@loopback/core';
import {
aComponentsSpec,
anOpenApiSpec,
anOperationSpec,
OpenApiSpecBuilder,
OperationSpecBuilder,
} from '@loopback/openapi-spec-builder';
import {get, post, requestBody} from '@loopback/openapi-v3';
import {model, property} from '@loopback/repository';
Expand Down Expand Up @@ -420,11 +419,35 @@ describe('RestServer.getApiSpec()', () => {
server = await app.getServer(RestServer);
await server.start();

const INPUT_SPEC = new OpenApiSpecBuilder()
server.api(
anOpenApiSpec()
.withOperation(
'get',
'/',
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
schema: {
title: 'loopback.example',
properties: {
test: {
type: 'string',
},
},
},
},
},
}),
)
.build(),
);

const EXPECTED_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/',
new OperationSpecBuilder().withResponse(200, {
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
Expand All @@ -441,9 +464,76 @@ describe('RestServer.getApiSpec()', () => {
}),
)
.build();
server.api(INPUT_SPEC);

const spec = await server.getApiSpec();
expect(spec).to.eql(EXPECTED_SPEC);

await server.stop();
});

it('runs consolidator if consolidate is set to true', async () => {
const options: {rest: RestServerConfig} = {
rest: {openApiSpec: {consolidate: true}},
};
options.rest = givenHttpServerConfig(options.rest);
app = new Application(options);
app.component(RestComponent);
server = await app.getServer(RestServer);
await server.start();

server.api(
anOpenApiSpec()
.withOperation(
'get',
'/',
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
schema: {
title: 'loopback.example',
properties: {
test: {
type: 'string',
},
},
},
},
},
}),
)
.build(),
);

const EXPECTED_SPEC = anOpenApiSpec()
.withOperation(
'get',
'/',
anOperationSpec().withResponse(200, {
description: 'Example',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/loopback.example',
},
},
},
}),
)
.withComponents(
aComponentsSpec().withSchema('loopback.example', {
title: 'loopback.example',
properties: {
test: {
type: 'string',
},
},
}),
)
.build();

const spec = await server.getApiSpec();
expect(spec).to.eql(INPUT_SPEC);
expect(spec).to.eql(EXPECTED_SPEC);

await server.stop();
});
Expand Down

0 comments on commit 3fe2df2

Please sign in to comment.