From 9ac0dd159515734c4c65c9d4cee5495693cea7fb Mon Sep 17 00:00:00 2001 From: Zenedith Date: Sat, 5 Mar 2016 10:30:21 +0100 Subject: [PATCH] Renamed Brand to Trade --- index.js | 3 --- lib/model/trade.js | 26 +++++++++++++++++++++++++- lib/tradeConverter.js | 32 -------------------------------- test/model/tradeTest.js | 16 ++++++++++++++++ test/tradeConverterTest.js | 21 --------------------- 5 files changed, 41 insertions(+), 57 deletions(-) delete mode 100644 lib/tradeConverter.js delete mode 100644 test/tradeConverterTest.js diff --git a/index.js b/index.js index 4e3ad92..4eb20a9 100644 --- a/index.js +++ b/index.js @@ -16,9 +16,6 @@ module.exports = { InvalidPhoneError: require('./lib/error/invalidPhoneError').InvalidPhoneError, InvalidTradeError: require('./lib/error/invalidTradeError').InvalidTradeError }, - converter: { - tradeConverter: require('./lib/tradeConverter').tradeConverter - }, enum: { Trade: require('./lib/model/trade').Trade, Currency: require('./lib/model/currency').Currency, diff --git a/lib/model/trade.js b/lib/model/trade.js index 9ce0ff3..dfc6ebf 100644 --- a/lib/model/trade.js +++ b/lib/model/trade.js @@ -3,9 +3,33 @@ var Trade = { PRIVATE_MEDIC_DENTAL: 'PRIVATE_MEDIC_DENTAL', OTHER: 'OTHER', + map: { + '5602c71013287705788b4567': 'HAIRDRESSING', + '5602c71013287705788b4568': 'PRIVATE_MEDIC_DENTAL', + '': 'OTHER' + }, + + getTradeFromId: function getTradeFromId(id) { + if (Trade.map.hasOwnProperty(id)) { + return Trade.map[id]; + } + + return Trade.OTHER; + }, + + getIdFromTrade: function getIdFromTrade(trade) { + for (var id in Trade.map) { + if (Trade.map[id] === trade) { + return id; + } + } + + return ''; + }, + getTrade: function (type) { - if (this.hasOwnProperty(type)) { + if (Trade.hasOwnProperty(type)) { return Trade[type]; } diff --git a/lib/tradeConverter.js b/lib/tradeConverter.js deleted file mode 100644 index 7ac1f33..0000000 --- a/lib/tradeConverter.js +++ /dev/null @@ -1,32 +0,0 @@ -var extend = require('util')._extend; -var Trade = require('./model/trade').Trade; - -var map = { - '5602c71013287705788b4567': Trade.HAIRDRESSING, - '5602c71013287705788b4568': Trade.PRIVATE_MEDIC_DENTAL, - '': Trade.OTHER -}; - -var getTradeFromId = function getTradeFromId(id) { - if (map.hasOwnProperty(id)) { - return map[id]; - } - - return Trade.OTHER; -}; - -var getIdFromTrade = function getIdFromTrade(trade) { - for (var id in map) { - if (map[id] === trade) { - return id; - } - } - - return ''; -}; - - -module.exports = { - getTradeFromId: getTradeFromId, - getIdFromTrade: getIdFromTrade -}; \ No newline at end of file diff --git a/test/model/tradeTest.js b/test/model/tradeTest.js index 43f9292..b3b5947 100644 --- a/test/model/tradeTest.js +++ b/test/model/tradeTest.js @@ -1,5 +1,6 @@ var chai = require('chai'); var should = chai.should(); +var expect = chai.expect; var Trade = require('../../lib/model/trade').Trade; describe('trade enum test', function () { @@ -28,4 +29,19 @@ describe('trade enum test', function () { done(); }); + + it('should get trade from id', function (done) { + var trade = Trade.getTradeFromId('5602c71013287705788b4567'); + + expect(trade).to.be.equal(Trade.HAIRDRESSING); + done(); + }); + + it('should get id from trade', function (done) { + var id = Trade.getIdFromTrade(Trade.PRIVATE_MEDIC_DENTAL); + + expect(id).to.be.equal('5602c71013287705788b4568'); + done(); + }); + }); diff --git a/test/tradeConverterTest.js b/test/tradeConverterTest.js deleted file mode 100644 index 15db7d2..0000000 --- a/test/tradeConverterTest.js +++ /dev/null @@ -1,21 +0,0 @@ -var tradeConverter = require('../lib/tradeConverter'); -var chai = require('chai'); -var should = chai.should(); -var expect = chai.expect; - -describe('trade converter test', function () { - - it('should get trade from id', function (done) { - var trade = tradeConverter.getTradeFromId('5602c71013287705788b4567'); - - expect(trade).to.be.equal('HAIRDRESSING'); - done(); - }); - - it('should get id from trade', function (done) { - var id = tradeConverter.getIdFromTrade('PRIVATE_MEDIC_DENTAL'); - - expect(id).to.be.equal('5602c71013287705788b4568'); - done(); - }); -});