From dd4d5e62c7ee86a496ed42856b9346215d526a5c Mon Sep 17 00:00:00 2001 From: Denise Scollo Date: Wed, 8 Jul 2020 15:44:18 -0300 Subject: [PATCH] Increase code coverage in botbuilder library - StatusCodeError class (#2494) * Add statusCodeError unit tests * Encapsulate tests in constructor() Co-authored-by: Joel Mut <62260472+sw-joelmut@users.noreply.github.com> Co-authored-by: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com> --- .../botbuilder/tests/statusCodeError.test.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 libraries/botbuilder/tests/statusCodeError.test.js diff --git a/libraries/botbuilder/tests/statusCodeError.test.js b/libraries/botbuilder/tests/statusCodeError.test.js new file mode 100644 index 0000000000..232fcb93b1 --- /dev/null +++ b/libraries/botbuilder/tests/statusCodeError.test.js @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +const assert = require('assert'); +const { StatusCodeError } = require('../'); +const { StatusCodes } = require('botbuilder-core'); + +describe(`StatusCodeError`, function() { + describe('constructor()', () => { + it(`should work with a message.`, done => { + try { + const message = 'This is an error message'; + const error = new StatusCodeError(StatusCodes.NOT_FOUND, message); + + assert.strictEqual(error.message, message, `message should be equal to "${message}".`) + assert.strictEqual(error.statusCode, StatusCodes.NOT_FOUND, `statusCode should be the code ${StatusCodes.NOT_FOUND}`) + done(); + } catch (error) { + done(error); + } + }); + + it(`should work without a message.`, done => { + try { + const error = new StatusCodeError(StatusCodes.NOT_FOUND); + + assert.strictEqual(error.message, '', 'message should be empty.') + assert.strictEqual(error.statusCode, StatusCodes.NOT_FOUND, `statusCode should be the code ${StatusCodes.NOT_FOUND}`) + done(); + } catch (error) { + done(error); + } + }); + + it(`should statusCode be undefined if not passed as a parameter.`, done => { + try { + const error = new StatusCodeError(); + + assert.strictEqual(error.statusCode, undefined, 'statusCode should be undefined.') + done(); + } catch (error) { + done(error); + } + }); + }); +});