Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rob4629 opened this issue Sep 1, 2020 · 0 comments
Open

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

rob4629 opened this issue Sep 1, 2020 · 0 comments

Comments

@rob4629
Copy link

rob4629 commented Sep 1, 2020

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();
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant