wiki: Thinking in Loopback - use Dredd for smoke testing
In https://github.com/strongloop/loopback-next/wiki/Thinking-in-LoopBack, we have a section about generating smoke tests.
Write a function that generates tests for each url in the spec
Let's rework this section to show people how to use Dredd for configuring and running smoke tests verifying that the app is following the spec.
We should make the setup as easy as possible, here is an example illustrating what I have in mind:
import {verifyApiImplementation} from '@loopback/testlab';
import {MyApplication} from '../..';
describe('Application REST API', () => {
it('correctly implements the API spec', async () => {
const app = new Application(/*configure http port 0*/);
await app.start();
try {
await verifyApiImplementation(app);
} finally {
await app.stop();
}
});
});
See http://dredd.readthedocs.io/en/latest/usage-js.html for documentation onhow to use Dredd from javascript.
To invoke an operation with required arguments, the generator need to know what values to provide. Dredd uses x-example extension for non-object parameters, I think we should mention this in our wiki too.
paths:
/cars:
get:
parameters:
- name: limit
in: query
type: number
x-example: 42
Refs:
x-example: https://dredd.readthedocs.io/en/latest/how-to-guides.html#example-values-for-request-parameters
sample client: https://github.com/apiaryio/gavel.js
OpenAPI spec: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#exampleObject
@Setogit I created a placeholder section for your content - see https://github.com/strongloop/loopback-next/wiki/Thinking-in-LoopBack#smoke-test-your-api-inputoutput
@bajtos I'm implementing it in the hello-world first. This PR includes the impl:
https://github.com/strongloop/loopback-next-hello-world/pull/9
Once the auth component PR (#10) is merged, I will rebase this to the master.
The wiki shows the outline of input/output testing: https://github.com/strongloop/loopback-next/wiki/Thinking-in-LoopBack#smoke-test-your-api-inputoutput
The PR should be close to ready for landing: https://github.com/strongloop/loopback-next-hello-world/pull/13
Closing as done.