loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

wiki: Thinking in Loopback - use Dredd for smoke testing

Open bajtos opened this issue 9 years ago • 6 comments

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

bajtos avatar Jul 27 '17 09:07 bajtos

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 avatar Aug 16 '17 13:08 Setogit

@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 avatar Aug 16 '17 14:08 bajtos

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

Setogit avatar Aug 17 '17 05:08 Setogit

The wiki shows the outline of input/output testing: https://github.com/strongloop/loopback-next/wiki/Thinking-in-LoopBack#smoke-test-your-api-inputoutput

Setogit avatar Aug 17 '17 05:08 Setogit

The PR should be close to ready for landing: https://github.com/strongloop/loopback-next-hello-world/pull/13

Setogit avatar Aug 22 '17 18:08 Setogit

Closing as done.

bajtos avatar Aug 31 '17 13:08 bajtos