UNPKG

6-mils

Version:

A JS library for sending, receiving, and parsing cXML messages.

74 lines (60 loc) 2.26 kB
/* eslint-env mocha */ /** * The following statement is required to ensure that no errors are silently * ignored (and thus preventing the tests from behaving as expected). */ 'use strict' /** * Code under test. * @type {any} */ const T = require('./index.js') describe('the "OutboundCxmlMessage" module', function () { it('must export a constructor', function () { const expected = 'function' const actual = typeof T expect(actual).to.equal(expected) }) describe('the exported constructor', function () { const ERR_INVALID_INPUT = 'The constructor for OutboundCxmlMessage reqiures a value from OutboundCxmlMessage.MESSAGE_TYPES.' it('must contain a static method of supported message types', function () { expect(T).to.have.property('MESSAGE_TYPES') }) describe('the "MESSAGE_TYPES" property', function () { it('must be read-only', function () { expect(() => { T.MESSAGE_TYPES = 'something else' }).to.throw() }) it('must return an object that cannot be modified', function () { expect(() => { T.MESSAGE_TYPES.another_type = 'something else' }).to.throw() }) it('must have a property called "test"', function () { expect(T.MESSAGE_TYPES).to.have.property('test') }) it('must have a property called "PunchOutSetupRequest"', function () { expect(T.MESSAGE_TYPES).to.have.property('PunchOutSetupRequest') }) it('must have a property called "OrderRequest"', function () { expect(T.MESSAGE_TYPES).to.have.property('OrderRequest') }) }) it('must throw an error if not called with any parameter', function () { expect(() => { const instance = new T() // eslint-disable-line }).to.throw(ERR_INVALID_INPUT) }) it('must throw an error if not called with a value other than one of the entries from MESSAGE_TYPES', function () { expect(() => { const instance = new T('test') // eslint-disable-line }).to.throw(ERR_INVALID_INPUT) }) it('must create unique instances', function () { const a = new T(T.MESSAGE_TYPES.test) const b = new T(T.MESSAGE_TYPES.test) expect(a).to.not.equal(b) }) }) })