Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
test: improve coverage of license and contact
Browse files Browse the repository at this point in the history
  • Loading branch information
joolfe committed Aug 5, 2020
1 parent 40785f4 commit a5662e3
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Is as easy as define the values in the "Edit Collection" form page inside the ta

![contact and license variables](images/variables.png)

The variables names will be in dot notation, for example for `contact` fields will be as `contact.name`, `contact.url`... Take into account that some of this fields are required as described in OpenAPI specs if not provided all the section will be ignored.
The variables names will be in dot notation, for example for `contact` fields will be as `contact.name`, `contact.url`... Take into account that fields that are required by OpenAPI specs, as `contact.name`, if not provided then all the section will be ignored.

You can also customize this information using the [Info option](#info-(object)), note that info provided by options will overwrite the variables inside the Postman collection (has more priority) but values will be merged from both sources (postman variables and options).

Expand Down
34 changes: 33 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const EXPECTED_SERVERS_OPTIONS = readFileSync('./test/resources/output/ServersOp
const EXPECTED_NO_SERVERS = readFileSync('./test/resources/output/NoServers.yml', 'utf8')
const EXPECTED_LICENSE_CONTACT = readFileSync('./test/resources/output/LicenseContact.yml', 'utf8')
const EXPECTED_LICENSE_CONTACT_OPT = readFileSync('./test/resources/output/LicenseContactOpts.yml', 'utf8')
const EXPECTED_LICENSE_CONTACT_PARTIAL = readFileSync('./test/resources/output/LicenseContactPartial.yml', 'utf8')
const EXPECTED_LICENSE_CONTACT_PARTIAL_2 = readFileSync('./test/resources/output/LicenseContactPartial2.yml', 'utf8')

describe('Library specs', function () {
afterEach('remove file', function () {
Expand Down Expand Up @@ -160,7 +162,7 @@ describe('Library specs', function () {
equal(result, EXPECTED_LICENSE_CONTACT)
})

it('should use license from options', async function () {
it('should use license and contact from options', async function () {
const result = await postmanToOpenApi(COLLECTION_LICENSE_CONTACT, OUTPUT_PATH,
{
info: {
Expand All @@ -177,4 +179,34 @@ describe('Library specs', function () {
})
equal(result, EXPECTED_LICENSE_CONTACT_OPT)
})

it('should support optional params in license and contact options', async function () {
const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH,
{
info: {
license: {
name: 'MIT'
},
contact: {
name: 'My Support'
}
}
})
equal(result, EXPECTED_LICENSE_CONTACT_PARTIAL)
})

it('should support optional params in license and contact options (2)', async function () {
const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH,
{
info: {
license: {
name: 'MIT'
},
contact: {
url: 'http://www.api.com/support'
}
}
})
equal(result, EXPECTED_LICENSE_CONTACT_PARTIAL_2)
})
})
63 changes: 63 additions & 0 deletions test/resources/output/LicenseContactPartial.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
openapi: 3.0.0
info:
title: Postman to OpenAPI
description: Mi super test collection from postman
version: 1.1.0
contact:
name: My Support
license:
name: MIT
servers:
- url: 'https://api.io'
paths:
/users:
post:
tags:
- default
summary: Create new User
description: Create a new user into your amazing API
requestBody:
content:
application/json:
schema:
type: object
example:
example: field
other:
data1: 'yes'
data2: 'no'
responses:
'200':
description: Successful response
content:
application/json: {}
/posts:
post:
tags:
- default
summary: Create a post
requestBody:
content:
text/plain: {}
responses:
'200':
description: Successful response
content:
application/json: {}
/note:
post:
tags:
- default
summary: Create a note
description: Just an example of text raw body
requestBody:
content:
application/json:
schema:
type: string
example: This is an example Note
responses:
'200':
description: Successful response
content:
application/json: {}
63 changes: 63 additions & 0 deletions test/resources/output/LicenseContactPartial2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
openapi: 3.0.0
info:
title: Postman to OpenAPI
description: Mi super test collection from postman
version: 1.1.0
contact:
url: 'http://www.api.com/support'
license:
name: MIT
servers:
- url: 'https://api.io'
paths:
/users:
post:
tags:
- default
summary: Create new User
description: Create a new user into your amazing API
requestBody:
content:
application/json:
schema:
type: object
example:
example: field
other:
data1: 'yes'
data2: 'no'
responses:
'200':
description: Successful response
content:
application/json: {}
/posts:
post:
tags:
- default
summary: Create a post
requestBody:
content:
text/plain: {}
responses:
'200':
description: Successful response
content:
application/json: {}
/note:
post:
tags:
- default
summary: Create a note
description: Just an example of text raw body
requestBody:
content:
application/json:
schema:
type: string
example: This is an example Note
responses:
'200':
description: Successful response
content:
application/json: {}

0 comments on commit a5662e3

Please sign in to comment.