in with the new
This commit is contained in:
268
test/core/plugins/ast/ast-manager.js
Normal file
268
test/core/plugins/ast/ast-manager.js
Normal file
@@ -0,0 +1,268 @@
|
||||
/* eslint-env mocha */
|
||||
import expect from "expect"
|
||||
import { pathForPosition, positionRangeForPath } from "corePlugins/ast/ast"
|
||||
|
||||
describe.skip("ASTManager", function() {
|
||||
describe("#pathForPosition", function() {
|
||||
describe("out of range", function() {
|
||||
it("returns empty array for out of range row", function(done) {
|
||||
var position = {line: 3, column: 0}
|
||||
var assertPath = function(path) {
|
||||
expect(path).toEqual([])
|
||||
done()
|
||||
}
|
||||
|
||||
pathForPosition("swagger: 2.0", position)
|
||||
.then(assertPath)
|
||||
})
|
||||
|
||||
it("returns empty array for out of range column", function(done) {
|
||||
var position = {line: 0, column: 100}
|
||||
var assertPath = function(path) {
|
||||
expect(path).toEqual([])
|
||||
done()
|
||||
}
|
||||
|
||||
pathForPosition("swagger: 2.0", position)
|
||||
.then(assertPath)
|
||||
})
|
||||
})
|
||||
|
||||
describe("when document is a simple hash `swagger: 2.0`", function() {
|
||||
it("should return empty array when pointer is at middle of the hash key", function(done) {
|
||||
var position = {line: 0, column: 3}
|
||||
pathForPosition("swagger: 2.0", position).then(function(path) {
|
||||
expect(path).toEqual([])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("should return ['swagger'] when pointer is at the value", function(done) {
|
||||
var position = {line: 0, column: 10}
|
||||
pathForPosition("swagger: 2.0", position).then(function(path) {
|
||||
expect(path).toEqual(["swagger"])
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("when document is an array: ['abc', 'cde']", function() {
|
||||
var yaml = [
|
||||
/*
|
||||
0
|
||||
01234567 */
|
||||
/* 0 */ "- abc",
|
||||
/* 1 */ "- def"
|
||||
].join("\n")
|
||||
|
||||
it("should return empty array when pointer is at array dash", function(done) {
|
||||
var position = {line: 0, column: 0}
|
||||
pathForPosition(yaml, position).then(function(path) {
|
||||
expect(path).toEqual([])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("should return ['0'] when pointer is at abc", function(done) {
|
||||
var position = {line: 0, column: 3}
|
||||
pathForPosition(yaml, position).then(function(path) {
|
||||
expect(path).toEqual(["0"])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("should return ['1'] when pointer is at abc", function(done) {
|
||||
var position = {line: 1, column: 3}
|
||||
pathForPosition(yaml, position).then(function(path) {
|
||||
expect(path).toEqual(["1"])
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("when document is an array of arrays", function() {
|
||||
var yaml = [
|
||||
/*
|
||||
0 10
|
||||
0123456789012345 */
|
||||
/* 0 */ "-",
|
||||
/* 1 */ " - abc",
|
||||
/* 2 */ " - def",
|
||||
/* 3 */ "-",
|
||||
/* 4 */ " - ABC",
|
||||
/* 5 */ " - DEF"
|
||||
].join("\n")
|
||||
|
||||
it("should return ['0', '0'] when pointer is at 'abc'", function(done) {
|
||||
var position = {line: 1, column: 5}
|
||||
pathForPosition(yaml, position).then(function(path) {
|
||||
expect(path).toEqual(["0", "0"])
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("when document is an array of hashs", function() {
|
||||
var yaml = [
|
||||
/*
|
||||
0 10
|
||||
0123456789012345 */
|
||||
/* 0 */ "- key: value",
|
||||
/* 1 */ " num: 1",
|
||||
/* 2 */ "- name: Tesla",
|
||||
/* 3 */ " year: 2016"
|
||||
].join("\n")
|
||||
|
||||
it("should return ['0'] when pointer is at 'key'", function(done) {
|
||||
var position = {line: 0, column: 3}
|
||||
pathForPosition(yaml, position).then(function(path) {
|
||||
expect(path).toEqual(["0"])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("should return ['0', 'key'] when pointer is at 'value'", function(done) {
|
||||
var position = {line: 0, column: 9}
|
||||
pathForPosition(yaml, position).then(function(path) {
|
||||
expect(path).toEqual(["0", "key"])
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("should return ['1', 'year'] when pointer is at '2016'", function(done) {
|
||||
var position = {line: 3, column: 10}
|
||||
pathForPosition(yaml, position).then(function(path) {
|
||||
expect(path).toEqual(["1", "year"])
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("full document", function() {
|
||||
var yaml = [
|
||||
/*
|
||||
0 10 20 30
|
||||
012345678901234567890123456789012345678 */
|
||||
/* 0 */ "swagger: '2.0'",
|
||||
/* 1 */ "info:",
|
||||
/* 2 */ " title: Test document",
|
||||
/* 3 */ " version: 0.0.1",
|
||||
/* 4 */ " contact:",
|
||||
/* 5 */ " name: Sahar",
|
||||
/* 6 */ " url: github.com",
|
||||
/* 7 */ " email: me@example.com",
|
||||
/* 8 */ " "
|
||||
].join("\n")
|
||||
|
||||
it("should return ['info', 'contact', 'email'] when pointer is at me@", function(done) {
|
||||
var position = {line: 7, column: 13}
|
||||
pathForPosition(yaml, position).then(function(path) {
|
||||
expect(path).toEqual(["info", "contact", "email"])
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("#positionRangeForPath", function() {
|
||||
it("return {{-1, -1}, {-1, -1}} for invalid paths", function(done) {
|
||||
var yaml = [
|
||||
"key: value",
|
||||
"anotherKey: value"
|
||||
].join("\n")
|
||||
|
||||
positionRangeForPath(yaml, ["invalid"])
|
||||
.then(function(position) {
|
||||
expect(position.start).toEqual({line: -1, column: -1})
|
||||
expect(position.end).toEqual({line: -1, column: -1})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
describe("when document is a simple hash `swagger: 2.0`", function() {
|
||||
var yaml = "swagger: 2.0"
|
||||
|
||||
it("return {0, 0} for start of empty array path (root)", function(done) {
|
||||
positionRangeForPath(yaml, []).then(function(position) {
|
||||
expect(position.start).toEqual({line: 0, column: 0})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("return {0, 12} for end of empty array path (root)", function(done) {
|
||||
positionRangeForPath(yaml, []).then(function(position) {
|
||||
expect(position.end).toEqual({line: 0, column: 12})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("return {0, 9} for start of ['swagger']", function(done) {
|
||||
positionRangeForPath(yaml, ["swagger"]).then(function(position) {
|
||||
expect(position.start).toEqual({line: 0, column: 9})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("return {0, 12} for end of ['swagger']", function(done) {
|
||||
positionRangeForPath(yaml, ["swagger"]).then(function(position) {
|
||||
expect(position.end).toEqual({line: 0, column: 12})
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("when document is an array of primitives", function() {
|
||||
var yaml = [
|
||||
"key:",
|
||||
" - value1",
|
||||
" - value2"
|
||||
].join("\n")
|
||||
|
||||
it("returns {1, 4} for ['key', '0']", function(done) {
|
||||
positionRangeForPath(yaml, ["key", "0"]).then(function(position) {
|
||||
expect(position.start).toEqual({line: 1, column: 4})
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("full document", function() {
|
||||
var yaml = [
|
||||
/*
|
||||
0 10 20 30
|
||||
012345678901234567890123456789012345678 */
|
||||
/* 0 */ "swagger: '2.0'",
|
||||
/* 1 */ "info:",
|
||||
/* 2 */ " title: Test document",
|
||||
/* 3 */ " version: 0.0.1",
|
||||
/* 4 */ " contact:",
|
||||
/* 5 */ " name: Sahar",
|
||||
/* 6 */ " url: github.com",
|
||||
/* 7 */ " email: me@example.com",
|
||||
/* 8 */ " "
|
||||
].join("\n")
|
||||
|
||||
it("returns {2, 2} for start of ['info']", function(done) {
|
||||
positionRangeForPath(yaml, ["info"]).then(function(position) {
|
||||
expect(position.start).toEqual({line: 2, column: 2})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("returns {5, 10} for start of ['info', 'contact', 'name']", function(done) {
|
||||
positionRangeForPath(yaml, ["info", "contact", "name"]).then(function(position) {
|
||||
expect(position.start).toEqual({line: 5, column: 10})
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it("returns {5, 15} for end of ['info', 'contact', 'name']", function(done) {
|
||||
positionRangeForPath(yaml, ["info", "contact", "name"]).then(function(position) {
|
||||
expect(position.end).toEqual({line: 5, column: 15})
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
40
test/core/plugins/auth-spec-wrap-actions.js
Normal file
40
test/core/plugins/auth-spec-wrap-actions.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/* eslint-env mocha */
|
||||
import expect, { createSpy } from "expect"
|
||||
import { fromJS } from "immutable"
|
||||
import { execute } from "corePlugins/auth/spec-wrap-actions"
|
||||
|
||||
describe("spec plugin - actions", function(){
|
||||
|
||||
describe("execute", function(){
|
||||
|
||||
xit("should add `securities` to the oriAction call", function(){
|
||||
// Given
|
||||
const system = {
|
||||
authSelectors: {
|
||||
authorized: createSpy().andReturn({some: "security"})
|
||||
}
|
||||
}
|
||||
const oriExecute = createSpy()
|
||||
|
||||
// When
|
||||
let executeFn = execute(oriExecute, system)
|
||||
let executePromise = executeFn({})
|
||||
|
||||
// Then
|
||||
expect(oriExecute.calls.length).toEqual(1)
|
||||
expect(oriExecute.calls[0].arguments[0]).toEqual({
|
||||
extras: {
|
||||
security: {
|
||||
some: "security"
|
||||
}
|
||||
},
|
||||
method: undefined,
|
||||
path: undefined,
|
||||
operation: undefined
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
55
test/core/plugins/err/transformers/not-of-type.js
Normal file
55
test/core/plugins/err/transformers/not-of-type.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import expect, { createSpy } from "expect"
|
||||
import { Map, List } from "immutable"
|
||||
import { transform } from "corePlugins/err/error-transformers/transformers/not-of-type"
|
||||
|
||||
describe("err plugin - tranformers - not of type", () => {
|
||||
|
||||
it("should transform a singular not of type(s) error without an inline path", () => {
|
||||
let ori = List([
|
||||
Map({
|
||||
path: "info.version",
|
||||
message: "is not of a type(s) string"
|
||||
})
|
||||
])
|
||||
|
||||
let res = transform(ori).toJS()
|
||||
|
||||
expect(res).toEqual([{
|
||||
path: "info.version",
|
||||
message: "should be a string"
|
||||
}])
|
||||
})
|
||||
|
||||
it("should transform a plural (2) not of type(s) error without an inline path", () => {
|
||||
let ori = List([
|
||||
Map({
|
||||
path: "info.version",
|
||||
message: "is not of a type(s) string,array"
|
||||
})
|
||||
])
|
||||
|
||||
let res = transform(ori).toJS()
|
||||
|
||||
expect(res).toEqual([{
|
||||
path: "info.version",
|
||||
message: "should be a string or array"
|
||||
}])
|
||||
})
|
||||
|
||||
it("should transform a plural (3+) not of type(s) error without an inline path", () => {
|
||||
let ori = List([
|
||||
Map({
|
||||
path: "info.version",
|
||||
message: "is not of a type(s) string,array,number"
|
||||
})
|
||||
])
|
||||
|
||||
let res = transform(ori).toJS()
|
||||
|
||||
expect(res).toEqual([{
|
||||
path: "info.version",
|
||||
message: "should be a string, array, or number"
|
||||
}])
|
||||
})
|
||||
|
||||
})
|
||||
131
test/core/plugins/err/transformers/parameter-oneof.js
Normal file
131
test/core/plugins/err/transformers/parameter-oneof.js
Normal file
@@ -0,0 +1,131 @@
|
||||
import expect, { createSpy } from "expect"
|
||||
import { Map, List, fromJS } from "immutable"
|
||||
import { transform } from "corePlugins/err/error-transformers/transformers/parameter-oneof"
|
||||
|
||||
describe.skip("err plugin - tranformers - parameter oneof", () => {
|
||||
|
||||
describe("parameter.in misuse transformation to fixed value error", () => {
|
||||
|
||||
it("should return a helpful error for invalid 'in' values", () => {
|
||||
const jsSpec = {
|
||||
paths: {
|
||||
"/CoolPath/": {
|
||||
get: {
|
||||
parameters: [
|
||||
{
|
||||
name: "id",
|
||||
in: "heder"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const jsonSchemaError = {
|
||||
"level": "error",
|
||||
"path": "paths.\/CoolPath\/.get.parameters[0]",
|
||||
"message": "is not exactly one from <#\/definitions\/parameter>,<#\/definitions\/jsonReference>",
|
||||
"source": "schema",
|
||||
"type": "spec"
|
||||
}
|
||||
|
||||
let res = transform(fromJS([jsonSchemaError]), { jsSpec })
|
||||
|
||||
expect(res.toJS()).toEqual([{
|
||||
path: "paths./CoolPath/.get.parameters[0].in",
|
||||
message: "Wrong value for the \"in\" keyword. Expected one of: path, query, header, body, formData.",
|
||||
level: "error",
|
||||
source: "schema",
|
||||
type: "spec"
|
||||
}])
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("parameter.collectionFormat misuse transformation to fixed value error", () => {
|
||||
it("should return a helpful error for invalid 'collectionFormat' values", () => {
|
||||
const jsSpec = {
|
||||
paths: {
|
||||
"/CoolPath/": {
|
||||
get: {
|
||||
parameters: [
|
||||
{
|
||||
name: "id",
|
||||
in: "query",
|
||||
collectionFormat: "asdf"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const jsonSchemaError = {
|
||||
"level": "error",
|
||||
"path": "paths.\/CoolPath\/.get.parameters[0]",
|
||||
"message": "is not exactly one from <#\/definitions\/parameter>,<#\/definitions\/jsonReference>",
|
||||
"source": "schema",
|
||||
"type": "spec"
|
||||
}
|
||||
|
||||
let res = transform(fromJS([jsonSchemaError]), { jsSpec })
|
||||
|
||||
expect(res.toJS()).toEqual([{
|
||||
path: "paths./CoolPath/.get.parameters[0].collectionFormat",
|
||||
message: "Wrong value for the \"collectionFormat\" keyword. Expected one of: csv, ssv, tsv, pipes, multi.",
|
||||
level: "error",
|
||||
source: "schema",
|
||||
type: "spec"
|
||||
}])
|
||||
})
|
||||
})
|
||||
|
||||
describe("Integrations", () => {
|
||||
it("should return the correct errors when both 'in' and 'collectionFormat' are incorrect", () => {
|
||||
const jsSpec = {
|
||||
paths: {
|
||||
"/CoolPath/": {
|
||||
get: {
|
||||
parameters: [
|
||||
{
|
||||
name: "id",
|
||||
in: "blah",
|
||||
collectionFormat: "asdf"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const jsonSchemaError = {
|
||||
"level": "error",
|
||||
"path": "paths.\/CoolPath\/.get.parameters[0]",
|
||||
"message": "is not exactly one from <#\/definitions\/parameter>,<#\/definitions\/jsonReference>",
|
||||
"source": "schema",
|
||||
"type": "spec"
|
||||
}
|
||||
|
||||
let res = transform(fromJS([jsonSchemaError]), { jsSpec })
|
||||
|
||||
expect(res.toJS()).toEqual([
|
||||
{
|
||||
path: "paths./CoolPath/.get.parameters[0].in",
|
||||
message: "Wrong value for the \"in\" keyword. Expected one of: path, query, header, body, formData.",
|
||||
level: "error",
|
||||
source: "schema",
|
||||
type: "spec"
|
||||
},
|
||||
{
|
||||
path: "paths./CoolPath/.get.parameters[0].collectionFormat",
|
||||
message: "Wrong value for the \"collectionFormat\" keyword. Expected one of: csv, ssv, tsv, pipes, multi.",
|
||||
level: "error",
|
||||
source: "schema",
|
||||
type: "spec"
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
752
test/core/plugins/samples/fn.js
Normal file
752
test/core/plugins/samples/fn.js
Normal file
@@ -0,0 +1,752 @@
|
||||
import { createXMLExample } from "corePlugins/samples/fn"
|
||||
import expect from "expect"
|
||||
|
||||
|
||||
describe("createXMLExample", function () {
|
||||
var sut = createXMLExample
|
||||
describe("simple types with xml property", function () {
|
||||
it("returns tag <newtagname>string</newtagname> when passing type string and xml:{name: \"newtagname\"}", function () {
|
||||
var definition = {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "newtagname"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>string</newtagname>")
|
||||
})
|
||||
|
||||
it("returns tag <test:newtagname>string</test:newtagname> when passing type string and xml:{name: \"newtagname\", prefix:\"test\"}", function () {
|
||||
var definition = {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "newtagname",
|
||||
prefix: "test"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test:newtagname>string</test:newtagname>")
|
||||
})
|
||||
|
||||
it("returns tag <test:tagname xmlns:sample=\"http://swagger.io/schema/sample\">string</test:tagname> when passing type string and xml:{\"namespace\": \"http://swagger.io/schema/sample\", \"prefix\": \"sample\"}", function () {
|
||||
var definition = {
|
||||
type: "string",
|
||||
xml: {
|
||||
namespace: "http://swagger.io/schema/sample",
|
||||
prefix: "sample",
|
||||
name: "name"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sample:name xmlns:sample=\"http://swagger.io/schema/sample\">string</sample:name>")
|
||||
})
|
||||
|
||||
it("returns tag <test:tagname >string</test:tagname> when passing type string and xml:{\"namespace\": \"http://swagger.io/schema/sample\"}", function () {
|
||||
var definition = {
|
||||
type: "string",
|
||||
xml: {
|
||||
namespace: "http://swagger.io/schema/sample",
|
||||
name: "name"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<name xmlns=\"http://swagger.io/schema/sample\">string</name>")
|
||||
})
|
||||
|
||||
it("returns tag <newtagname>test</newtagname> when passing default value", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>test</newtagname>"
|
||||
var definition = {
|
||||
type: "string",
|
||||
"default": "test",
|
||||
xml: {
|
||||
name: "newtagname"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns default value when enum provided", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>one</newtagname>"
|
||||
var definition = {
|
||||
type: "string",
|
||||
"default": "one",
|
||||
"enum": ["two", "one"],
|
||||
xml: {
|
||||
name: "newtagname"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns example value when provided", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>two</newtagname>"
|
||||
var definition = {
|
||||
type: "string",
|
||||
"default": "one",
|
||||
"example": "two",
|
||||
"enum": ["two", "one"],
|
||||
xml: {
|
||||
name: "newtagname"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("sets first enum if provided", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<newtagname>one</newtagname>"
|
||||
var definition = {
|
||||
type: "string",
|
||||
"enum": ["one", "two"],
|
||||
xml: {
|
||||
name: "newtagname"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe("array", function () {
|
||||
it("returns tag <tagname>string</tagname> when passing string items", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<tagname>string</tagname>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string"
|
||||
},
|
||||
xml: {
|
||||
name: "tagname"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns tag <animal>string</animal> when passing string items with name", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animal>string</animal>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "animal"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns tag <animals><animal>string</animal></animals> when passing string items with name", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>string</animal>\n</animals>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "animal"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true,
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("return correct nested wrapped array", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<dog>string</dog>\n</aliens>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string"
|
||||
},
|
||||
xml: {
|
||||
name: "dog"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true,
|
||||
name: "aliens"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("return correct nested wrapped array with xml", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<dogs>\n\t\t<dog>string</dog>\n\t</dogs>\n</aliens>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "dog"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "dogs",
|
||||
wrapped: true
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true,
|
||||
name: "aliens"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("adds namespace to array", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dog xmlns=\"test\">string</dog>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "dog",
|
||||
namespace: "test"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "aliens",
|
||||
namespace: "test_new"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("adds prefix to array", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test:dog>string</test:dog>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "dog",
|
||||
prefix: "test"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "aliens",
|
||||
prefix: "test_new"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("adds prefix to array with no xml in items", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test:dog>string</test:dog>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string"
|
||||
},
|
||||
xml: {
|
||||
name: "dog",
|
||||
prefix: "test"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("adds namespace to array with no xml in items", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dog xmlns=\"test\">string</dog>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string"
|
||||
},
|
||||
xml: {
|
||||
name: "dog",
|
||||
namespace: "test"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("adds namespace to array with wrapped", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens xmlns=\"test\">\n\t<dog>string</dog>\n</aliens>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "dog"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true,
|
||||
name: "aliens",
|
||||
namespace: "test"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("adds prefix to array with wrapped", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test:aliens>\n\t<dog>string</dog>\n</test:aliens>"
|
||||
var definition = {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "dog"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true,
|
||||
name: "aliens",
|
||||
prefix: "test"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns wrapped array when type is not passed", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>string</animal>\n</animals>"
|
||||
var definition = {
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "animal"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true,
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns array with default values", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animal>one</animal>\n<animal>two</animal>"
|
||||
var definition = {
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "animal"
|
||||
}
|
||||
},
|
||||
"default": ["one", "two"],
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns array with default values with wrapped=true", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>one</animal>\n\t<animal>two</animal>\n</animals>"
|
||||
var definition = {
|
||||
items: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "animal"
|
||||
}
|
||||
},
|
||||
"default": ["one", "two"],
|
||||
xml: {
|
||||
wrapped: true,
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns array with default values", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animal>one</animal>"
|
||||
var definition = {
|
||||
items: {
|
||||
type: "string",
|
||||
"enum": ["one", "two"],
|
||||
xml: {
|
||||
name: "animal"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns array with default values with wrapped=true", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>one</animal>\n</animals>"
|
||||
var definition = {
|
||||
items: {
|
||||
"enum": ["one", "two"],
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "animal"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
wrapped: true,
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe("object", function () {
|
||||
it("returns object with 2 properties", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<alien>string</alien>\n\t<dog>0</dog>\n</aliens>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
alien: {
|
||||
type: "string"
|
||||
},
|
||||
dog: {
|
||||
type: "integer"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "aliens"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with integer property and array property", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<aliens>string</aliens>\n\t<dog>0</dog>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
aliens: {
|
||||
type: "array",
|
||||
items: {
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
dog: {
|
||||
type: "integer"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns nested objects", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<aliens>\n\t\t<alien>string</alien>\n\t</aliens>\n\t<dog>string</dog>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
aliens: {
|
||||
type: "object",
|
||||
properties: {
|
||||
alien: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "alien"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
dog: {
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with no readonly fields for parameter", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
dog: {
|
||||
readOnly: true,
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition, { includeReadOnly: false })).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with passed property as attribute", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals id=\"0\">\n\t<dog>string</dog>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer",
|
||||
xml: {
|
||||
attribute: true
|
||||
}
|
||||
},
|
||||
dog: {
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with passed property as attribute with custom name", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals test=\"0\">\n\t<dog>string</dog>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer",
|
||||
xml: {
|
||||
attribute: true,
|
||||
name: "test"
|
||||
}
|
||||
},
|
||||
dog: {
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with example values in attribute", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user id=\"42\">\n\t<role>admin</role>\n</user>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer",
|
||||
xml: {
|
||||
attribute: true
|
||||
}
|
||||
},
|
||||
role:{
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "user"
|
||||
},
|
||||
example: {
|
||||
id: 42,
|
||||
role: "admin"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with enum values in attribute", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user id=\"one\">\n\t<role>string</role>\n</user>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "string",
|
||||
"enum": ["one", "two"],
|
||||
xml: {
|
||||
attribute: true
|
||||
}
|
||||
},
|
||||
role:{
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "user"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with default values in attribute", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user id=\"one\">\n\t<role>string</role>\n</user>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "string",
|
||||
"default": "one",
|
||||
xml: {
|
||||
attribute: true
|
||||
}
|
||||
},
|
||||
role:{
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "user"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with default values in attribute", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user id=\"one\">\n\t<role>string</role>\n</user>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "string",
|
||||
"example": "one",
|
||||
xml: {
|
||||
attribute: true
|
||||
}
|
||||
},
|
||||
role:{
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "user"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with example value", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>\n\t<id>42</id>\n\t<role>admin</role>\n</user>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
role:{
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "user"
|
||||
},
|
||||
example: {
|
||||
id: 42,
|
||||
role: "admin"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with additional props", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<dog>string</dog>\n\t<additionalProp>string</additionalProp>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
dog: {
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
additionalProperties: {
|
||||
type: "string"
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with additional props =true", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<dog>string</dog>\n\t<additionalProp>Anything can be here</additionalProp>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
dog: {
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
additionalProperties: true,
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with 2 properties with no type passed but properties", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<aliens>\n\t<alien>string</alien>\n\t<dog>0</dog>\n</aliens>"
|
||||
var definition = {
|
||||
properties: {
|
||||
alien: {
|
||||
type: "string"
|
||||
},
|
||||
dog: {
|
||||
type: "integer"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "aliens"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with additional props with no type passed", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<additionalProp>string</additionalProp>\n</animals>"
|
||||
var definition = {
|
||||
additionalProperties: {
|
||||
type: "string"
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
})
|
||||
})
|
||||
135
test/core/plugins/spec-actions.js
Normal file
135
test/core/plugins/spec-actions.js
Normal file
@@ -0,0 +1,135 @@
|
||||
/* eslint-env mocha */
|
||||
import expect, { createSpy } from "expect"
|
||||
import { fromJS } from "immutable"
|
||||
import { execute, executeRequest } from "corePlugins/spec/actions"
|
||||
|
||||
describe("spec plugin - actions", function(){
|
||||
|
||||
describe("execute", function(){
|
||||
|
||||
xit("should collect a full request and call fn.executeRequest", function(){
|
||||
// Given
|
||||
const system = {
|
||||
fn: {
|
||||
fetch: 1
|
||||
},
|
||||
specActions: {
|
||||
executeRequest: createSpy()
|
||||
},
|
||||
specSelectors: {
|
||||
spec: () => fromJS({spec: 1}),
|
||||
parameterValues: () => fromJS({values: 2}),
|
||||
contentTypeValues: () => fromJS({requestContentType: "one", responseContentType: "two"})
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
let executeFn = execute({ path: "/one", method: "get"})
|
||||
let executePromise = executeFn(system)
|
||||
|
||||
// Then
|
||||
expect(system.specActions.executeRequest.calls[0].arguments[0]).toEqual({
|
||||
fetch: 1,
|
||||
method: "get",
|
||||
pathName: "/one",
|
||||
parameters: {
|
||||
values: 2
|
||||
},
|
||||
requestContentType: "one",
|
||||
responseContentType: "two",
|
||||
spec: {
|
||||
spec: 1
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
xit("should allow passing _extra_ properties to executeRequest", function(){
|
||||
|
||||
// Given
|
||||
const system = {
|
||||
fn: {},
|
||||
specActions: {
|
||||
executeRequest: createSpy()
|
||||
},
|
||||
specSelectors: {
|
||||
spec: () => fromJS({}),
|
||||
parameterValues: () => fromJS({}),
|
||||
contentTypeValues: () => fromJS({})
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
let executeFn = execute({ hi: "hello" })
|
||||
let executePromise = executeFn(system)
|
||||
|
||||
// Then
|
||||
expect(system.specActions.executeRequest.calls[0].arguments[0]).toInclude({hi: "hello"})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("executeRequest", function(){
|
||||
|
||||
xit("should call fn.execute with arg ", function(){
|
||||
|
||||
const response = {}
|
||||
const system = {
|
||||
fn: {
|
||||
execute: createSpy().andReturn(Promise.resolve())
|
||||
},
|
||||
specActions: {
|
||||
setResponse: createSpy()
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
let executeFn = executeRequest({one: 1})
|
||||
let res = executeFn(system)
|
||||
|
||||
// Then
|
||||
expect(res).toBeA(Promise)
|
||||
expect(system.fn.execute.calls.length).toEqual(1)
|
||||
expect(system.fn.execute.calls[0].arguments[0]).toEqual({
|
||||
one: 1
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
xit("should call specActions.setResponse, when fn.execute resolves", function(){
|
||||
|
||||
const response = {serverResponse: true}
|
||||
const system = {
|
||||
fn: {
|
||||
execute: createSpy().andReturn(Promise.resolve(response))
|
||||
},
|
||||
specActions: {
|
||||
setResponse: createSpy()
|
||||
},
|
||||
errActions: {
|
||||
newSpecErr: createSpy()
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
let executeFn = executeRequest({
|
||||
pathName: "/one",
|
||||
method: "GET"
|
||||
})
|
||||
let executePromise = executeFn(system)
|
||||
|
||||
// Then
|
||||
return executePromise.then( () => {
|
||||
expect(system.specActions.setResponse.calls.length).toEqual(1)
|
||||
expect(system.specActions.setResponse.calls[0].arguments).toEqual([
|
||||
"/one",
|
||||
"GET",
|
||||
response
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it.skip("should call errActions.newErr, if the fn.execute rejects", function(){
|
||||
})
|
||||
|
||||
})
|
||||
95
test/core/plugins/spec-selectors.js
Normal file
95
test/core/plugins/spec-selectors.js
Normal file
@@ -0,0 +1,95 @@
|
||||
/* eslint-env mocha */
|
||||
import expect, { createSpy } from "expect"
|
||||
import { fromJS } from "immutable"
|
||||
import { parameterValues, contentTypeValues } from "corePlugins/spec/selectors"
|
||||
|
||||
describe("spec plugin - selectors", function(){
|
||||
|
||||
describe("parameterValue", function(){
|
||||
|
||||
it("should return Map({}) if no path found", function(){
|
||||
|
||||
// Given
|
||||
const spec = fromJS({ })
|
||||
|
||||
// When
|
||||
let paramValues = parameterValues(spec, ["/one", "get"])
|
||||
|
||||
// Then
|
||||
expect(paramValues.toJS()).toEqual({})
|
||||
|
||||
})
|
||||
|
||||
it("should return a hash of [parameterName]: value", function(){
|
||||
|
||||
// Given
|
||||
const spec = fromJS({
|
||||
resolved: {
|
||||
paths: {
|
||||
"/one": {
|
||||
get: {
|
||||
parameters: [
|
||||
{ name: "one", value: 1},
|
||||
{ name: "two", value: "duos"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
let paramValues = parameterValues(spec, ["/one", "get"])
|
||||
|
||||
// Then
|
||||
expect(paramValues.toJS()).toEqual({
|
||||
one: 1,
|
||||
two: "duos"
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("contentTypeValues", function(){
|
||||
|
||||
it("should return { requestContentType, responseContentType } from an operation", function(){
|
||||
// Given
|
||||
let state = fromJS({
|
||||
resolved: {
|
||||
paths: {
|
||||
"/one": {
|
||||
get: {
|
||||
"consumes_value": "one",
|
||||
"produces_value": "two"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
let contentTypes = contentTypeValues(state, [ "/one", "get" ])
|
||||
// Then
|
||||
expect(contentTypes.toJS()).toEqual({
|
||||
requestContentType: "one",
|
||||
responseContentType: "two"
|
||||
})
|
||||
})
|
||||
|
||||
it("should be ok, if no operation found", function(){
|
||||
// Given
|
||||
let state = fromJS({ })
|
||||
|
||||
// When
|
||||
let contentTypes = contentTypeValues(state, [ "/one", "get" ])
|
||||
// Then
|
||||
expect(contentTypes.toJS()).toEqual({
|
||||
requestContentType: undefined,
|
||||
responseContentType: undefined
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user