-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marco Friso
committed
Apr 1, 2020
1 parent
1cee7cf
commit ea4487b
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/fury-adapter-oas3-parser/lib/parser/oas/parseServersArray.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const R = require('ramda'); | ||
const pipeParseResult = require('../../pipeParseResult'); | ||
const parseArray = require('../parseArray'); | ||
const parseServerObject = require('./parseServerObject'); | ||
|
||
const name = 'Security Requirements Array'; | ||
|
||
/** | ||
* Parse Servers Array | ||
* | ||
* @param namespace {Namespace} | ||
* @param element {Element} | ||
* @returns ParseResult | ||
* | ||
* @private | ||
*/ | ||
function parseServersArray(context, element) { | ||
const { namespace } = context; | ||
|
||
const parseServers = pipeParseResult(namespace, | ||
parseArray(context, name, R.curry(parseServerObject)(context))); | ||
return parseServers(element); | ||
} | ||
|
||
module.exports = R.curry(parseServersArray); |
74 changes: 74 additions & 0 deletions
74
packages/fury-adapter-oas3-parser/test/unit/parser/oas/parseServersArray-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const { Fury } = require('fury'); | ||
const { expect } = require('../../chai'); | ||
const parse = require('../../../../lib/parser/oas/parseServersArray'); | ||
const Context = require('../../../../lib/context'); | ||
|
||
const { minim: namespace } = new Fury(); | ||
|
||
describe('Servers Array', () => { | ||
let context; | ||
|
||
beforeEach(() => { | ||
context = new Context(namespace); | ||
}); | ||
|
||
it('warns when it is not an array', () => { | ||
const servers = new namespace.elements.Object(); | ||
|
||
const parseResult = parse(context, servers); | ||
|
||
expect(parseResult.length).to.equal(1); | ||
expect(parseResult).to.contain.warning("'Security Requirements Array' is not an array"); | ||
}); | ||
|
||
it('parses correctly when there is a single security requirement', () => { | ||
const server = new namespace.elements.Array([ | ||
{ | ||
url: 'https://user.server.com/1.0', | ||
description: 'The production API server', | ||
}, | ||
]); | ||
|
||
const parseResult = parse(context, server); | ||
|
||
expect(parseResult.length).to.equal(1); | ||
|
||
const servers = parseResult.get(0); | ||
|
||
expect(servers).to.be.instanceof(namespace.elements.Array); | ||
expect(servers.length).to.equal(1); | ||
expect(servers.get(0)).to.be.instanceof(namespace.elements.Resource); | ||
expect(servers.get(0).meta.content[0].content.value.content[0].content).to.equal('host'); | ||
expect(servers.get(0).meta.content[1].content.value.content).to.equal('The production API server'); | ||
expect(servers.get(0).attributes.content[0].content.value.content).to.equal('https://user.server.com/1.0'); | ||
}); | ||
|
||
it('parses correctly when there are multiple servers', () => { | ||
const server = new namespace.elements.Array([ | ||
{ | ||
url: 'https://user.server.com/1.0', | ||
}, | ||
{ | ||
url: 'https://user.server.com/2.0', | ||
description: 'The production API server', | ||
}, | ||
]); | ||
|
||
const parseResult = parse(context, server); | ||
|
||
expect(parseResult.length).to.equal(1); | ||
|
||
const servers = parseResult.get(0); | ||
|
||
expect(servers).to.be.instanceof(namespace.elements.Array); | ||
expect(servers.length).to.equal(2); | ||
expect(servers.get(0)).to.be.instanceof(namespace.elements.Resource); | ||
expect(servers.get(0).meta.content[0].content.value.content[0].content).to.equal('host'); | ||
expect(servers.get(0).attributes.content[0].content.value.content).to.equal('https://user.server.com/1.0'); | ||
|
||
expect(servers.get(1)).to.be.instanceof(namespace.elements.Resource); | ||
expect(servers.get(1).meta.content[0].content.value.content[0].content).to.equal('host'); | ||
expect(servers.get(1).meta.content[1].content.value.content).to.equal('The production API server'); | ||
expect(servers.get(1).attributes.content[0].content.value.content).to.equal('https://user.server.com/2.0'); | ||
}); | ||
}); |