Skip to content

(Nice-to-have) - Read dereferenced Swagger from file #48

Open
@rob4629

Description

@rob4629

I'd like to have a central (common) instance of the hippieSwaggerApp() function, to make it cleaner for each of my tests to call it. As a workaround, within each Test Suite, I've duplicated the function:

import hippie from "hippie-swagger";
import { username, password } from "common/resources/httpAuth.json";

describe("Test Swagger examples for Foo", () => {
  let dereferencedSwagger;

  function myApp() {
    return hippie(dereferencedSwagger).base(baseUrl).auth(username, password).json();
  }

  before(async () => {
    dereferencedSwagger = await parseSwaggerDoc(mySwaggerDoc);
  });

  context("<Foo>", () => {
    it("Returns 200, when sending a valid request", async () => {
      await myApp()
        .header("Auth-Type", "auth")
        .header("Auth-Token", authToken)
        .get(`my/route/{id}`)
        .pathParams({
          id: my.id,
        })
        .expectStatus(200)
        .end();
    });

However, it would be really nice to have a setup script which parses the Swagger Doc (as we have multiple APIs), and writes the dereferenced contents to a temp file. Allowing for:

// common/path/commonHippieApp.js 
import hippie from "hippie-swagger";
import { username, password } from "common/resources/httpAuth.json";

export const commonHippieApp = (pathToSwaggerDoc, baseUrl) => {
  return hippie(pathToSwaggerDoc).base(baseUrl).auth(username, password).json();
}
// service/path/myHippieApp.js 
import commonHippieApp from "common/path/commonHippieApp";

const swaggerPath = "path/to/dereferencedSwagger.json"

export const myHippieApp = () => {
  return commonHippieApp(swaggerPath, "http://some.base/uri");
}
// tests.spec.js
import myHippieApp from "service/path/myHippieApp";

describe("Test Swagger examples for Foo", () => {
  context("<Foo>", () => {
    it("Returns 200, when sending a valid request", async () => {
      await myHippieApp()
        .header("Auth-Type", "auth")
        .header("Auth-Token", authToken)
        .get(`my/route/{id}`)
        .pathParams({
          id: my.id,
        })
        .expectStatus(200)
        .end();
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions