mirror of
https://github.com/sourcey/spectacle.git
synced 2024-10-05 17:38:59 +03:00
Drafted tests for reference resolving.
This commit is contained in:
parent
20fce13763
commit
8a22c8b279
26
test/fixtures/basic-path.yaml
vendored
Normal file
26
test/fixtures/basic-path.yaml
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
get:
|
||||
description: Get a basic response.
|
||||
responses:
|
||||
"200":
|
||||
description: The basic response.
|
||||
"500":
|
||||
description: An error occured.
|
||||
post:
|
||||
description: Send some data.
|
||||
produces:
|
||||
- application/json
|
||||
- text/html
|
||||
parameters:
|
||||
- name: type
|
||||
in: query
|
||||
type: string
|
||||
description: The type of response (JSON/HTML) requested.
|
||||
- name: id
|
||||
in: formData
|
||||
type: string
|
||||
description: The data to store.
|
||||
responses:
|
||||
"200":
|
||||
description: The basic response.
|
||||
"409":
|
||||
description: An ID conflict occured.
|
9
test/minimal.js
Normal file
9
test/minimal.js
Normal file
@ -0,0 +1,9 @@
|
||||
/** The minimal OpenAPI spec with all required fields. */
|
||||
exports.minimal = minimal = {
|
||||
swagger: "2.0",
|
||||
info: {
|
||||
title: "Test File",
|
||||
version: "0.0.0",
|
||||
},
|
||||
paths: {},
|
||||
};
|
106
test/test-preprocessor-references.js
Normal file
106
test/test-preprocessor-references.js
Normal file
@ -0,0 +1,106 @@
|
||||
var chai = require("chai");
|
||||
var should = chai.should();
|
||||
|
||||
var preprocessor = require("../app/lib/preprocessor");
|
||||
|
||||
var minimal = require("./minimal").minimal;
|
||||
|
||||
describe("preprocessor referencing", function() {
|
||||
|
||||
var spec = null;
|
||||
var processed = null;
|
||||
|
||||
beforeEach(function() {
|
||||
spec = Object.assign({}, minimal);
|
||||
});
|
||||
|
||||
describe("local documents", function() {
|
||||
|
||||
describe("for paths", function() {
|
||||
|
||||
beforeEach(function() {
|
||||
spec = Object.assign({}, spec, {
|
||||
paths: {
|
||||
"/": {
|
||||
"$ref": "./fixtures/basic-path.yaml",
|
||||
},
|
||||
},
|
||||
});
|
||||
processed = preprocessor({}, spec);
|
||||
});
|
||||
|
||||
it("should include the path section", function() {
|
||||
processed.paths.should.have.key("/");
|
||||
processed.paths["/"].should.be.an.object;
|
||||
});
|
||||
|
||||
it.skip("should include the imported paths", function() {
|
||||
processed.paths["/"].should.have.key("get");
|
||||
processed.paths["/"].should.have.key("post");
|
||||
});
|
||||
|
||||
it.skip("should include the reference path ('/' path)", function() {
|
||||
processed.paths["/"].should.have.property("x-external", "./fixtures/basic-path.yaml");
|
||||
});
|
||||
|
||||
it.skip("should include the reference path ('get', 'post')", function() {
|
||||
processed.paths["/"].get.should.have.property("x-external", "./fixtures/basic-path.yaml#get");
|
||||
processed.paths["/"].post.should.have.property("x-external", "./fixtures/basic-path.yaml#post");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("for schema", function() {
|
||||
|
||||
var response;
|
||||
|
||||
beforeEach(function() {
|
||||
spec = Object.assign({}, spec, { paths: { "/": { get: {
|
||||
description: "Returns the current user.",
|
||||
produces: ["application/json"],
|
||||
responses: { "200": {
|
||||
description: "Current user",
|
||||
schema: {
|
||||
"$ref": "fixtures/User.yaml"
|
||||
}
|
||||
}
|
||||
}}}}});
|
||||
processed = preprocessor({}, spec);
|
||||
response = processed.paths["/"].get.responses["200"];
|
||||
});
|
||||
|
||||
it("should include path", function() {
|
||||
processed.paths.should.have.property("/");
|
||||
processed.paths["/"].should.have.property("get");
|
||||
processed.paths["/"].get.should.have.property("responses");
|
||||
processed.paths["/"].get.responses.should.have.property("200");
|
||||
processed.paths["/"].get.responses["200"].should.have.property("schema");
|
||||
});
|
||||
|
||||
it.skip("should remove '$ref'", function() {
|
||||
response.schema.should.not.have.key("$ref");
|
||||
});
|
||||
|
||||
it.skip("should include the reference path", function() {
|
||||
response.schema.should.have.property("x-external", "./fixtures/User.yaml");
|
||||
});
|
||||
|
||||
it.skip("should include the schema", function() {
|
||||
var schema = response.schema;
|
||||
schema.should.have.property("type", "object");
|
||||
schema.should.have.property("properties");
|
||||
schema.properties.should.have.property("name");
|
||||
schema.properties.name.should.deep.equal({ type: "string" });
|
||||
});
|
||||
|
||||
it.skip("should include the definition globally", function() {
|
||||
processed.definitions.should.be.an.object;
|
||||
processed.definitions.should.have.property("./fixtures/User.yaml");
|
||||
processed.definitions["./fixtures/User.yaml"].should.deep.equal(response.schema);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -3,7 +3,7 @@ var should = chai.should();
|
||||
|
||||
var preprocessor = require("../app/lib/preprocessor");
|
||||
|
||||
var minimal = require("./minimal");
|
||||
var minimal = require("./minimal").minimal;
|
||||
|
||||
describe("preprocessor", function() {
|
||||
|
||||
|
0
test/utils.js
Normal file
0
test/utils.js
Normal file
Loading…
Reference in New Issue
Block a user