Skip to content

Commit

Permalink
Adding tests for openapi2postman executable
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijitpostman committed Dec 17, 2018
1 parent b018d9e commit 799f91f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/*
.coverage/*
npm-debug.log
npm-debug.log.*
tempOutput.json
33 changes: 33 additions & 0 deletions test/data/invalid_openapi/multiple-components.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
openapi: 3.0.0
info:
title: 'multi-component-failure'
description: 'multi-component-failure'
version: '0.1'

# Basic authentication
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic

# Describe your paths here
paths:
/v1:
get:
summary: Sample summary
description: Sample description
operationId: sampleOperation
responses:
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Error:
type: object
properties:
status:
type: string
34 changes: 34 additions & 0 deletions test/unit/bin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var expect = require('chai').expect,
fs = require('fs'),
exec = require('child_process').exec,
collection;

describe('openapi2postmanv2 ', function() {
it('should print to console', function(done) {
exec('./bin/openapi2postmanv2.js -s test/data/valid_openapi/petstore.json', function(err, stdout) {
expect(err).to.be.null;
expect(stdout).to.include('Swagger Petstore');
done();
});
});

it('should print to file', function(done) {
exec('./bin/openapi2postmanv2.js -s test/data/valid_openapi/petstore.json -o tempOutput.json', function(err) {
expect(err).to.be.null;
fs.readFile('tempOutput.json', 'utf8', (err, data) => {
collection = JSON.parse(data);
expect(collection.info.name).to.equal('Swagger Petstore');
expect(collection.item.length).to.equal(1);
done();
});
});
});

it('should show appropriate messages for invalid input', function (done) {
exec('./bin/openapi2postmanv2.js -s test/data/invalid_openapi/multiple-components.yaml', function(err, stdout) {
expect(err).to.be.null;
expect(stdout).to.include('duplicated mapping key');
done();
});
});
});
2 changes: 1 addition & 1 deletion test/unit/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var path = '../../',
packageJson = require(path + '/package.json');

/* global describe, it */
describe(packageJson.name, function() {
describe('Plugin ' + packageJson.name, function() {
var sampleInput = packageJson.com_postman_plugin.sample_input;

it('should contain all com_postman_plugin attributes', function (done) {
Expand Down

0 comments on commit 799f91f

Please sign in to comment.