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

Commit

Permalink
Test: add test for supported collection versions
Browse files Browse the repository at this point in the history
  • Loading branch information
joolfe committed Sep 24, 2021
1 parent 5daf9c9 commit d55abfd
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 44 deletions.
12 changes: 6 additions & 6 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { version } = require('../package.json')
const OUTPUT_PATH = path.join(__dirname, '/openAPIRes.yml')

const COLLECTION_NO_OPTIONS = './test/resources/input/NoOptionsInBody.json'
const COLLECTION_RAW_BODY = './test/resources/input/RawBody.json'

const EXPECTED_BASIC = readFileSync('./test/resources/output/Basic.yml', 'utf8')
const EXPECTED_INFO_OPTS = readFileSync('./test/resources/output/InfoOpts.yml', 'utf8')
Expand Down Expand Up @@ -113,6 +112,7 @@ describe('Library specs', function () {
const COLLECTION_FORM_URLENCODED = `./test/resources/input/${version}/FormUrlencoded.json`
const COLLECTION_VARIABLES = `./test/resources/input/${version}/Variables.json`
const COLLECTION_BASEURL_VAR = `./test/resources/input/${version}/BasepathVar.json`
const COLLECTION_RAW_BODY = `./test/resources/input/${version}/RawBody.json`

it('should work with a basic transform', async function () {
const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH, {})
Expand Down Expand Up @@ -453,6 +453,11 @@ describe('Library specs', function () {
})
equal(result, EXPECTED_BASEPATH_VAR)
})

it('should try to parse raw body as json but fallback to text', async function () {
const result = await postmanToOpenApi(COLLECTION_RAW_BODY, OUTPUT_PATH, {})
equal(result, EXPECTED_RAW_BODY)
})
})
})

Expand All @@ -461,11 +466,6 @@ describe('Library specs', function () {
equal(result, EXPECTED_BASIC)
})

it('should try to parse raw body as json but fallback to text', async function () {
const result = await postmanToOpenApi(COLLECTION_RAW_BODY, OUTPUT_PATH, {})
equal(result, EXPECTED_RAW_BODY)
})

it('should expose the version of the library', async function () {
equal(postmanToOpenApi.version, version)
})
Expand Down
37 changes: 0 additions & 37 deletions test/resources/input/RawBody.json

This file was deleted.

44 changes: 44 additions & 0 deletions test/resources/input/v2/RawBody.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"info": {
"_postman_id": "b9a3a079-e781-4cb5-9ae6-009640952df5",
"name": "Raw Body",
"description": "Mi super test collection from postman",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "Test Raw Body",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "testesttestest"
},
"url": "https://api.io/test",
"description": "Test Raw Body"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
54 changes: 54 additions & 0 deletions test/resources/input/v21/RawBody.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"info": {
"_postman_id": "b9a3a079-e781-4cb5-9ae6-009640952df5",
"name": "Raw Body",
"description": "Mi super test collection from postman",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Test Raw Body",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "testesttestest"
},
"url": {
"raw": "https://api.io/test",
"protocol": "https",
"host": [
"api",
"io"
],
"path": [
"test"
]
},
"description": "Test Raw Body"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
2 changes: 1 addition & 1 deletion test/resources/output/RawBody.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.0
info:
title: Postman to OpenAPI
title: Raw Body
description: Mi super test collection from postman
version: 1.0.0
servers:
Expand Down

0 comments on commit d55abfd

Please sign in to comment.