-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.spec.js
39 lines (32 loc) · 1.36 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";
const swaggerMethods = require("../");
const swaggerSchema = require("swagger-schema-official/schema");
const httpMethods = require("methods");
const { expect } = require("chai");
describe("swagger-methods", () => {
it("should be a non-empty array", () => {
expect(swaggerMethods).to.be.an("array").with.length.above(0);
});
it("should be all lowercase strings", () => {
swaggerMethods.forEach((method) => {
expect(method).to.be.a("string").and.equal(method.toLowerCase());
});
});
it("should only have valid HTTP methods", () => {
swaggerMethods.forEach((method) => {
expect(httpMethods).to.include(method);
});
});
it("should match the Swagger 2.0 schema", () => {
// "pathItem" is the Swagger object that defines the allowed HTTP methods
// (see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#path-item-object)
let pathItemProps = swaggerSchema.definitions.pathItem.properties;
// We only care about the "operation" properties
// (see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#operationObject)
let operations = Object.keys(pathItemProps).filter((key) => {
let pathItemProp = pathItemProps[key];
return pathItemProp.$ref === "#/definitions/operation";
});
expect(swaggerMethods).to.have.same.members(operations);
});
});