in with the new
This commit is contained in:
174
test/core/curlify.js
Normal file
174
test/core/curlify.js
Normal file
@@ -0,0 +1,174 @@
|
||||
import expect from "expect"
|
||||
import Im from "immutable"
|
||||
import curl from "core/curlify"
|
||||
|
||||
describe("curlify", function() {
|
||||
|
||||
it("prints a curl statement with custom content-type", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
method: "POST",
|
||||
body: {
|
||||
id: 0,
|
||||
name: "doggie",
|
||||
status: "available"
|
||||
},
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"content-type": "application/json"
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X POST http://example.com -H "Accept: application/json" -H "content-type: application/json" -d {"id":0,"name":"doggie","status":"available"}')
|
||||
})
|
||||
|
||||
it("does not change the case of header in curl", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"conTenT Type": "application/Moar"
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X POST http://example.com -H "conTenT Type: application/Moar"')
|
||||
})
|
||||
|
||||
it("prints a curl statement with an array of query params", function() {
|
||||
var req = {
|
||||
url: "http://swaggerhub.com/v1/one?name=john|smith",
|
||||
method: "GET"
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X GET http://swaggerhub.com/v1/one?name=john|smith')
|
||||
})
|
||||
|
||||
it("prints a curl statement with an array of query params and auth", function() {
|
||||
var req = {
|
||||
url: "http://swaggerhub.com/v1/one?name=john|smith",
|
||||
method: "GET",
|
||||
headers: {
|
||||
authorization: "Basic Zm9vOmJhcg=="
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X GET http://swaggerhub.com/v1/one?name=john|smith -H "authorization: Basic Zm9vOmJhcg=="')
|
||||
})
|
||||
|
||||
it("prints a curl statement with html", function() {
|
||||
var req = {
|
||||
url: "http://swaggerhub.com/v1/one?name=john|smith",
|
||||
method: "GET",
|
||||
headers: {
|
||||
accept: "application/json"
|
||||
},
|
||||
body: {
|
||||
description: '<b>Test</b>'
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X GET http://swaggerhub.com/v1/one?name=john|smith -H "accept: application/json" -d {"description":"<b>Test</b>"}')
|
||||
})
|
||||
|
||||
it("handles post body with html", function() {
|
||||
var req = {
|
||||
url: "http://swaggerhub.com/v1/one?name=john|smith",
|
||||
method: "POST",
|
||||
headers: {
|
||||
accept: "application/json"
|
||||
},
|
||||
body: {
|
||||
description: '<b>Test</b>'
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X POST http://swaggerhub.com/v1/one?name=john|smith -H "accept: application/json" -d {"description":"<b>Test</b>"}')
|
||||
})
|
||||
|
||||
it("handles post body with special chars", function() {
|
||||
var req = {
|
||||
url: "http://swaggerhub.com/v1/one?name=john|smith",
|
||||
method: "POST",
|
||||
body: {
|
||||
description: '@prefix nif:<http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#> .\n' +
|
||||
'@prefix itsrdf: <http://www.w3.org/2005/11/its/rdf#> .'
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X POST http://swaggerhub.com/v1/one?name=john|smith -d {"description":"@prefix nif:<http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#> .@prefix itsrdf: <http://www.w3.org/2005/11/its/rdf#> ."}')
|
||||
})
|
||||
|
||||
it("handles delete form with parameters", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
accept: "application/x-www-form-urlencoded"
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X DELETE http://example.com -H "accept: application/x-www-form-urlencoded"')
|
||||
})
|
||||
|
||||
it("should print a curl with formData", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
method: "POST",
|
||||
headers: { "content-type": "multipart/form-data" },
|
||||
body: "id=123&name=Sahar"
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X POST http://example.com -H "content-type: multipart/form-data" -F id=123 -F name=Sahar')
|
||||
})
|
||||
|
||||
it("prints a curl post statement from an object", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
method: "POST",
|
||||
headers: {
|
||||
accept: "application/json"
|
||||
},
|
||||
body: {
|
||||
id: 10101
|
||||
}
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X POST http://example.com -H "accept: application/json" -d {"id":10101}')
|
||||
})
|
||||
|
||||
it("prints a curl post statement from a string containing a single quote", function() {
|
||||
var req = {
|
||||
url: "http://example.com",
|
||||
method: "POST",
|
||||
headers: {
|
||||
accept: "application/json"
|
||||
},
|
||||
body: '{"id":"foo\'bar"}'
|
||||
}
|
||||
|
||||
let curlified = curl(Im.fromJS(req))
|
||||
|
||||
expect(curlified).toEqual('curl -X POST http://example.com -H "accept: application/json" -d "{\\"id\\":\\"foo\'bar\\"}"')
|
||||
})
|
||||
|
||||
})
|
||||
183
test/core/path-translator.js
Normal file
183
test/core/path-translator.js
Normal file
@@ -0,0 +1,183 @@
|
||||
/* eslint-env mocha */
|
||||
import expect, { createSpy } from "expect"
|
||||
import { transformPathToArray } from "core/path-translator"
|
||||
|
||||
describe("validation plugin - path translator", function(){
|
||||
|
||||
describe("string paths", function(){
|
||||
|
||||
it("should translate a simple string path to an array", function(){
|
||||
// Given
|
||||
let jsSpec = {
|
||||
one: {
|
||||
a: "a thing",
|
||||
b: "another thing",
|
||||
c: "one more thing"
|
||||
},
|
||||
two: 2
|
||||
}
|
||||
|
||||
let path = "instance.one.a"
|
||||
|
||||
// Then
|
||||
expect(transformPathToArray(path, jsSpec)).toEqual(["one", "a"])
|
||||
|
||||
})
|
||||
|
||||
it("should translate an ambiguous string path to an array", function(){
|
||||
// Since JSONSchema uses periods to mark different properties,
|
||||
// a key with a period in it is ambiguous, because it can mean at least two things.
|
||||
// In our case, the path can mean:
|
||||
// ["google", "com", "a"] or ["google.com", "a"]
|
||||
|
||||
// Given
|
||||
let jsSpec = {
|
||||
"google.com": {
|
||||
a: "a thing",
|
||||
b: "another thing",
|
||||
c: "one more thing"
|
||||
},
|
||||
"gmail.com": {
|
||||
d: "more stuff",
|
||||
e: "even more stuff"
|
||||
}
|
||||
}
|
||||
|
||||
let path = "instance.google.com.a"
|
||||
|
||||
// Then
|
||||
expect(transformPathToArray(path, jsSpec)).toEqual(["google.com", "a"])
|
||||
|
||||
})
|
||||
|
||||
it("should translate an doubly ambiguous string path to an array", function(){
|
||||
// Since JSONSchema uses periods to mark different properties,
|
||||
// a key with two periods in it (like "www.google.com") is doubly ambiguous,
|
||||
// because it can mean at least three things.
|
||||
|
||||
|
||||
// Given
|
||||
let jsSpec = {
|
||||
"www.google.com": {
|
||||
a: "a thing",
|
||||
b: "another thing",
|
||||
c: "one more thing"
|
||||
},
|
||||
"gmail.com": {
|
||||
d: "more stuff",
|
||||
e: "even more stuff"
|
||||
}
|
||||
}
|
||||
|
||||
let path = "instance.www.google.com.a"
|
||||
|
||||
// Then
|
||||
expect(transformPathToArray(path, jsSpec)).toEqual(["www.google.com", "a"])
|
||||
|
||||
})
|
||||
|
||||
it("should return null for an invalid path", function(){
|
||||
|
||||
// Given
|
||||
let jsSpec = {
|
||||
"google.com": {
|
||||
a: "a thing",
|
||||
b: "another thing",
|
||||
c: "one more thing"
|
||||
},
|
||||
"gmail.com": {
|
||||
d: "more stuff",
|
||||
e: "even more stuff"
|
||||
}
|
||||
}
|
||||
|
||||
let path = "instance.google.net.a"
|
||||
|
||||
// Then
|
||||
expect(transformPathToArray(path, jsSpec)).toEqual(null)
|
||||
|
||||
})
|
||||
|
||||
it("should return inline array indices in their own value", function(){
|
||||
// "a[1]" => ["a", "1"]
|
||||
|
||||
// Given
|
||||
let jsSpec = {
|
||||
"google.com": {
|
||||
a: [
|
||||
"hello",
|
||||
"here is the target"
|
||||
],
|
||||
b: "another thing",
|
||||
c: "one more thing"
|
||||
},
|
||||
"gmail.com": {
|
||||
d: "more stuff",
|
||||
e: "even more stuff"
|
||||
}
|
||||
}
|
||||
|
||||
let path = "instance.google.com.a[1]"
|
||||
|
||||
// Then
|
||||
expect(transformPathToArray(path, jsSpec)).toEqual(["google.com", "a", "1"])
|
||||
|
||||
})
|
||||
|
||||
it("should return the correct path when the last part is ambiguous", function(){
|
||||
|
||||
// Given
|
||||
let jsSpec = {
|
||||
"google.com": {
|
||||
a: [
|
||||
"hello",
|
||||
{
|
||||
"gmail.com": 1234
|
||||
}
|
||||
],
|
||||
b: "another thing",
|
||||
c: "one more thing"
|
||||
},
|
||||
"gmail.com": {
|
||||
d: "more stuff",
|
||||
e: "even more stuff"
|
||||
}
|
||||
}
|
||||
|
||||
let path = "instance.google.com.a[1].gmail.com"
|
||||
|
||||
// Then
|
||||
expect(transformPathToArray(path, jsSpec)).toEqual(["google.com", "a", "1", "gmail.com"])
|
||||
|
||||
})
|
||||
|
||||
it("should return the correct path when the last part is doubly ambiguous", function(){
|
||||
|
||||
// Given
|
||||
let jsSpec = {
|
||||
"google.com": {
|
||||
a: [
|
||||
"hello",
|
||||
{
|
||||
"www.gmail.com": 1234
|
||||
}
|
||||
],
|
||||
b: "another thing",
|
||||
c: "one more thing"
|
||||
},
|
||||
"gmail.com": {
|
||||
d: "more stuff",
|
||||
e: "even more stuff"
|
||||
}
|
||||
}
|
||||
|
||||
let path = "instance.google.com.a[1].www.gmail.com"
|
||||
|
||||
// Then
|
||||
expect(transformPathToArray(path, jsSpec)).toEqual(["google.com", "a", "1", "www.gmail.com"])
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
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
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
330
test/core/system.js
Normal file
330
test/core/system.js
Normal file
@@ -0,0 +1,330 @@
|
||||
/* eslint-env mocha */
|
||||
import expect from "expect"
|
||||
import System from "core/system"
|
||||
import { fromJS } from "immutable"
|
||||
|
||||
describe("bound system", function(){
|
||||
|
||||
describe("wrapActions", function(){
|
||||
|
||||
it("should replace an action", function(){
|
||||
// Given
|
||||
const system = new System({
|
||||
plugins: {
|
||||
statePlugins: {
|
||||
josh: {
|
||||
actions: {
|
||||
simple: () => {
|
||||
return { type: "simple" }
|
||||
}
|
||||
},
|
||||
wrapActions: {
|
||||
simple: () => () => {
|
||||
return { type: "newSimple" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
var action = system.getSystem().joshActions.simple(1)
|
||||
expect(action).toEqual({
|
||||
type: "newSimple"
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
it("should expose the original action, and the system as args", function(){
|
||||
// Given
|
||||
const simple = () => ({type: "simple" })
|
||||
const system = new System({
|
||||
plugins: {
|
||||
statePlugins: {
|
||||
josh: {
|
||||
actions: { simple },
|
||||
wrapActions: {
|
||||
simple: (oriAction, system) => (actionArg) => {
|
||||
return {
|
||||
type: "newSimple",
|
||||
oriActionResult: oriAction(),
|
||||
system: system.getSystem(),
|
||||
actionArg
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
var action = system.getSystem().joshActions.simple(1)
|
||||
expect(action).toEqual({
|
||||
type: "newSimple",
|
||||
oriActionResult: { type: "simple" },
|
||||
system: system.getSystem(),
|
||||
actionArg: 1
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
it("should support multiple wraps of the same action", function(){
|
||||
const system = new System({
|
||||
plugins: [
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
actions: {
|
||||
simple: () => {
|
||||
return {
|
||||
type: "simple",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
wrapActions: {
|
||||
simple: (ori) => () => {
|
||||
return {
|
||||
...ori(),
|
||||
firstWrap: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
wrapActions: {
|
||||
simple: (ori) => () => {
|
||||
return {
|
||||
...ori(),
|
||||
secondWrap: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// When
|
||||
var action = system.getSystem().kyleActions.simple(1)
|
||||
expect(action).toEqual({
|
||||
type: "simple",
|
||||
firstWrap: true,
|
||||
secondWrap: true,
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
it("should execute wrapActions in the order they appear ( via plugins )", function(){
|
||||
const system = new System({
|
||||
plugins: [
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
actions: {
|
||||
simple: () => {
|
||||
return {
|
||||
type: "one",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
wrapActions: {
|
||||
simple: (ori) => () => {
|
||||
const obj = ori()
|
||||
obj.type += "-two"
|
||||
return obj
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
wrapActions: {
|
||||
simple: (ori) => () => {
|
||||
const obj = ori()
|
||||
obj.type += "-three"
|
||||
return obj
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// When
|
||||
var action = system.getSystem().kyleActions.simple(1)
|
||||
expect(action.type).toEqual("one-two-three")
|
||||
|
||||
})
|
||||
|
||||
it("should have a the latest system", function(){
|
||||
// Given
|
||||
const system = new System({
|
||||
plugins: [
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
actions: {
|
||||
simple: () => {
|
||||
return {
|
||||
type: "one",
|
||||
}
|
||||
}
|
||||
},
|
||||
wrapActions: {
|
||||
simple: (ori, {joshActions}) => () => {
|
||||
return joshActions.hello()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
// When
|
||||
const kyleActions = system.getSystem().kyleActions
|
||||
|
||||
system.register({
|
||||
statePlugins: {
|
||||
josh: {
|
||||
actions: {
|
||||
hello(){ return {type: "hello" } }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const action = kyleActions.simple()
|
||||
expect(action).toEqual({ type: "hello"})
|
||||
})
|
||||
|
||||
it.skip("should be able to create async actions", function(){
|
||||
const system = new System({
|
||||
plugins: [
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
actions: {
|
||||
simple: () => {
|
||||
return {
|
||||
type: "one",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
statePlugins: {
|
||||
kyle: {
|
||||
wrapActions: {
|
||||
simple: (ori) => (arg) => (sys) => {
|
||||
return { type: "called" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
// When
|
||||
var action = system.getSystem().kyleActions.simple(1)
|
||||
expect(action.type).toEqual("called")
|
||||
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
describe("selectors", function(){
|
||||
|
||||
it("should have the first arg be the nested state, and all other args to follow", function(){
|
||||
|
||||
// Given
|
||||
const system = new System({
|
||||
state: {
|
||||
josh: {
|
||||
one: 1
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
statePlugins: {
|
||||
josh: {
|
||||
selectors: {
|
||||
simple: (state, arg1) => {
|
||||
return { state, arg1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
// When
|
||||
var res = system.getSystem().joshSelectors.simple(1)
|
||||
expect(res).toEqual({
|
||||
state: fromJS({
|
||||
one: 1
|
||||
}),
|
||||
arg1: 1
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("when selector returns a funtcion", function(){
|
||||
|
||||
it("should pass the system to that function", function(){
|
||||
|
||||
// Given
|
||||
const system = new System({
|
||||
plugins: {
|
||||
statePlugins: {
|
||||
josh: {
|
||||
selectors: {
|
||||
advanced: () => (mySystem) => {
|
||||
// Then
|
||||
expect(mySystem).toEqual(system.getSystem())
|
||||
return "hi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
// When
|
||||
var res = system.getSystem().joshSelectors.advanced(1)
|
||||
expect(res).toEqual("hi")
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
75
test/core/utils.js
Normal file
75
test/core/utils.js
Normal file
@@ -0,0 +1,75 @@
|
||||
/* eslint-env mocha */
|
||||
import expect, { createSpy } from "expect"
|
||||
import { fromJS } from "immutable"
|
||||
import { mapToList } from "core/utils"
|
||||
|
||||
describe("utils", function(){
|
||||
|
||||
describe("mapToList", function(){
|
||||
|
||||
it("should convert a map to a list, setting `key`", function(){
|
||||
// With
|
||||
const aMap = fromJS({
|
||||
a: {
|
||||
one: 1,
|
||||
},
|
||||
b: {
|
||||
two: 2,
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
const aList = mapToList(aMap, "someKey")
|
||||
|
||||
// Then
|
||||
expect(aList.toJS()).toEqual([
|
||||
{ someKey: "a", one: 1 },
|
||||
{ someKey: "b", two: 2 },
|
||||
])
|
||||
})
|
||||
|
||||
it("should flatten an arbitrarily deep map", function(){
|
||||
// With
|
||||
const aMap = fromJS({
|
||||
a: {
|
||||
one: {
|
||||
alpha: true
|
||||
}
|
||||
},
|
||||
b: {
|
||||
two: {
|
||||
bravo: true
|
||||
},
|
||||
three: {
|
||||
charlie: true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
const aList = mapToList(aMap, ["levelA", "levelB"])
|
||||
|
||||
// Then
|
||||
expect(aList.toJS()).toEqual([
|
||||
{ levelA: "a", levelB: "one", alpha: true },
|
||||
{ levelA: "b", levelB: "two", bravo: true },
|
||||
{ levelA: "b", levelB: "three", charlie: true },
|
||||
])
|
||||
|
||||
})
|
||||
|
||||
it("should handle an empty map", function(){
|
||||
// With
|
||||
const aMap = fromJS({})
|
||||
|
||||
// When
|
||||
const aList = mapToList(aMap, ["levelA", "levelB"])
|
||||
|
||||
// Then
|
||||
expect(aList.toJS()).toEqual([])
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user