From 27477dd9e248d6b9eef31c6a7bb38d88c9f6a544 Mon Sep 17 00:00:00 2001 From: suchothendav Date: Fri, 9 Sep 2016 14:20:03 -0700 Subject: [PATCH] Unit test for promise response if callback is not provided as an argument #20 --- package.json | 2 +- tests/params_mockgen.js | 44 +++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index de89817..8e496f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swagmock", - "version": "0.0.4", + "version": "1.0.0-alpha.1", "description": "Mock data generator for swagger api", "main": "lib/index.js", "engines": { diff --git a/tests/params_mockgen.js b/tests/params_mockgen.js index 0c3520e..6232d91 100644 --- a/tests/params_mockgen.js +++ b/tests/params_mockgen.js @@ -1,37 +1,36 @@ -var Assert = require('assert'); -var Swagmock = require('../lib'); -var Path = require('path') -//isInteger pollyfil for pre es6 -Number.isInteger = Number.isInteger || function(value) { - return typeof value === "number" && - isFinite(value) && - Math.floor(value) === value; -}; +const Assert = require('assert'); +const Swagmock = require('../lib'); +const Path = require('path') -describe('Parameters Mock generator', function () { - var apiPath = Path.resolve(__dirname, 'fixture/petstore.json'); - var swagmock = Swagmock(apiPath); - it('should generate parameter mock for path /store/order/{orderId} for all operations', function(done) { - swagmock.parameters({ +describe('Parameters Mock generator', () => { + let apiPath = Path.resolve(__dirname, 'fixture/petstore.json'); + let swagmock = Swagmock(apiPath); + it('should generate parameter mock for path /store/order/{orderId} for all operations', (done) => { + let mockgen = swagmock.parameters({ path: '/store/order/{orderId}' - }, function(err, mock) { - Assert.ok(!err, 'No error'); + }); + //Promise test case + mockgen.then(mock => { Assert.ok(mock, 'Generated mock'); Assert.ok(mock.get, 'Generated mock for get operation'); Assert.ok(mock.delete, 'Generated mock for delete operation'); - var params = mock.get.parameters; + let params = mock.get.parameters; Assert.ok(params, 'Generated parameters'); Assert.ok(params.path, 'Generated path parameter'); Assert.ok(params.path[0].name === 'orderId', 'generated mock parameter for orderId'); Assert.ok(params.path[0].value > 0 && params.path[0].value < 10, 'OK value for orderId'); done(); + }).catch(err => { + Assert.ok(!err, 'No error'); + done(); }); }); - it('should generate parameter mock for all the path', function(done) { - swagmock.parameters({}, function(err, mock) { - var testMock; - Assert.ok(!err, 'No error'); + it('should generate parameter mock for all the path', (done) => { + let mockgen = swagmock.parameters({}); + //Promise test case + mockgen.then(mock => { + let testMock; Assert.ok(mock, 'Generated mock'); Assert.ok(mock['/pet'], 'Generated mock for path /pet'); Assert.ok(mock['/pet/findByStatus'], 'Generated mock for path /pet/findByStatus'); @@ -54,6 +53,9 @@ describe('Parameters Mock generator', function () { testMock = mock['/user/createWithList'].post.parameters.body[0].value; Assert.ok(testMock.length <= 4, 'body parameter should have maximum 4 items'); done(); + }).catch(err => { + Assert.ok(!err, 'No error'); + done(); }); }); });