UNPKG

@fye/xservices-client

Version:

FYE Micros Xservices Client

641 lines (563 loc) 22.8 kB
var expect = require('expect.js'); var TransactionService = require('../lib/transaction'); var config = require('./service_config.json'); describe('TransactionService', function() { this.timeout(200000); var service = new TransactionService(config.service.opts, config.service.conns); describe('._formatTransaction', function() { var basicJSON = require(__dirname + '/fixtures/format_transaction_1.json'); var singleItemJSON = require(__dirname + '/fixtures/format_transaction_2.json'); var multiItemJSON = require(__dirname + '/fixtures/format_transaction_3.json'); describe('- Basic Transaction', function() { var transaction = service._formatTransaction(basicJSON); it('should parse a basic transaction', function() { expect(transaction).to.be.an('object'); }); it('should have the basic fields', function() { expect(transaction).to.have.keys([ 'amountDue', 'businessDate', 'cashierId', 'changed', 'totalItemSold', 'totalTaxAmt', 'totalTenderAmt', 'transSeq', 'transSubTotal', 'transTotal', 'giftReceiptFlag' ]); }); it('should properly format the data', function() { var date = new Date('2014-09-10T00:00:00-04:00'); expect(transaction.amountDue).to.be(0); expect(transaction.businessDate).to.eql(date); expect(transaction.cashierId).to.be('55555'); expect(transaction.changed).to.be(false); expect(transaction.totalItemSold).to.be(0); expect(transaction.totalTaxAmt).to.be(0); expect(transaction.totalTenderAmt).to.be(0); expect(transaction.transSeq).to.be(137); expect(transaction.transSubTotal).to.be(0); expect(transaction.transTotal).to.be(0); expect(transaction.giftReceiptFlag).to.be(false); }); }); describe('- Single Item Transaction', function() { var transaction = service._formatTransaction(singleItemJSON); it('should parse the transaction', function() { expect(transaction).to.be.an('object'); }); it('should have the basic fields', function() { expect(transaction).to.have.keys([ 'amountDue', 'businessDate', 'cashierId', 'changed', 'totalItemSold', 'totalTaxAmt', 'totalTenderAmt', 'transSeq', 'transSubTotal', 'transTotal', 'giftReceiptFlag', 'saleLines' ]); }); it('should have saleLines as an array', function() { expect(transaction.saleLines).to.be.an('array'); }); it('should properly format the data', function() { var date = new Date('2014-09-10T00:00:00-04:00'); var line = transaction.saleLines[0]; var item = line.item; expect(transaction.amountDue).to.be(10.59); expect(transaction.businessDate).to.eql(date); expect(transaction.cashierId).to.be('55555'); expect(transaction.changed).to.be(true); expect(transaction.totalItemSold).to.be(1); expect(transaction.totalTaxAmt).to.be(0.60); expect(transaction.totalTenderAmt).to.be(0.00); expect(transaction.transSeq).to.be(151); expect(transaction.transSubTotal).to.be(9.99); expect(transaction.transTotal).to.be(10.59); expect(transaction.giftReceiptFlag).to.be(false); expect(line.changed).to.be(true); expect(line.giftReceiptFlag).to.be(false); expect(item.departmentId).to.be('0001'); expect(item.desc).to.be('BARE BONES 0309'); expect(item.dimensionSummary).to.be(''); expect(item.disallowSendSale).to.be(false); expect(item.giftCard).to.be(false); expect(item.itemClassId).to.be('000100070076'); expect(item.subdepartmentId).to.be('00010007'); expect(item.itemId).to.be('11661327221'); expect(item.itemLevelCode).to.be('ITEM'); expect(item.itemTypeCode).to.be('STANDARD'); expect(item.minAgeRequired).to.be(0); expect(item.promptForDescription).to.be(false); expect(item.promptForPrice).to.be(false); expect(item.promptForQty).to.be(false); expect(item.promptForWeight).to.be(false); expect(item.qtyScale).to.be(1); expect(item.quantityOnHand).to.be(0); expect(item.serializeItem).to.be(false); }); }); describe('- Multiple Item Transaction', function() { var transaction = service._formatTransaction(multiItemJSON); it('should parse the transaction', function() { expect(transaction).to.be.an('object'); }); it('should have the basic fields', function() { expect(transaction).to.have.keys([ 'amountDue', 'businessDate', 'cashierId', 'changed', 'totalItemSold', 'totalTaxAmt', 'totalTenderAmt', 'transSeq', 'transSubTotal', 'transTotal', 'giftReceiptFlag', 'saleLines' ]); }); it('should have saleLines as an array', function() { expect(transaction.saleLines).to.be.an('array'); }); it('should have two sale lines', function() { expect(transaction.saleLines).to.have.length(2); }); it('should properly format the data', function() { var date = new Date('2014-09-11T00:00:00-04:00'); var line = transaction.saleLines[0]; var item = line.item; expect(transaction.businessDate).to.eql(date); expect(transaction.amountDue).to.be(37.07); expect(transaction.cashierId).to.be('55555'); expect(transaction.changed).to.be(true); expect(transaction.totalItemSold).to.be(3); expect(transaction.totalTaxAmt).to.be(2.10); expect(transaction.totalTenderAmt).to.be(0.00); expect(transaction.transSubTotal).to.be(34.97); expect(transaction.transTotal).to.be(37.07); expect(transaction.giftReceiptFlag).to.be(false); expect(line.changed).to.be(true); expect(line.giftReceiptFlag).to.be(false); expect(line.itemDescription).to.be('BRAVEHEART 314'); expect(line.itemId).to.be('99923241027'); expect(line.lineNumber).to.be(1); expect(line.qty).to.be(1); expect(line.saleItemType).to.be('SALE'); expect(line.totalLineDiscountAmount).to.be(0.00); expect(line.totalLinePrice).to.be(14.99); expect(line.unitPrice).to.be(14.99); expect(line.voidFlag).to.be(false); expect(item.departmentId).to.be('0001'); expect(item.desc).to.be('BRAVEHEART 314'); expect(item.dimensionSummary).to.be(''); expect(item.disallowSendSale).to.be(false); expect(item.giftCard).to.be(false); expect(item.itemClassId).to.be('000100030030'); expect(item.subdepartmentId).to.be('00010003'); expect(item.itemId).to.be('99923241027'); expect(item.itemLevelCode).to.be('ITEM'); expect(item.itemTypeCode).to.be('STANDARD'); expect(item.minAgeRequired).to.be(0); expect(item.promptForDescription).to.be(false); expect(item.promptForPrice).to.be(false); expect(item.promptForQty).to.be(false); expect(item.promptForWeight).to.be(false); expect(item.qtyScale).to.be(1); expect(item.quantityOnHand).to.be(0); expect(item.serializeItem).to.be(false); line = transaction.saleLines[1]; item = line.item; expect(line.changed).to.be(true); expect(line.giftReceiptFlag).to.be(false); expect(line.itemDescription).to.be('AMERICAN PSYCHO 040'); expect(line.itemId).to.be('99923816423'); expect(line.lineNumber).to.be(3); expect(line.qty).to.be(2); expect(line.saleItemType).to.be('SALE'); expect(line.totalLineDiscountAmount).to.be(0.00); expect(line.totalLinePrice).to.be(19.98); expect(line.unitPrice).to.be(9.99); expect(line.voidFlag).to.be(false); expect(item.departmentId).to.be('0001'); expect(item.desc).to.be('AMERICAN PSYCHO 040'); expect(item.dimensionSummary).to.be(''); expect(item.disallowSendSale).to.be(false); expect(item.giftCard).to.be(false); expect(item.itemClassId).to.be('000100010212'); expect(item.subdepartmentId).to.be('00010001'); expect(item.itemId).to.be('99923816423'); expect(item.itemLevelCode).to.be('ITEM'); expect(item.itemTypeCode).to.be('STANDARD'); expect(item.minAgeRequired).to.be(0); expect(item.promptForDescription).to.be(false); expect(item.promptForPrice).to.be(false); expect(item.promptForQty).to.be(false); expect(item.promptForWeight).to.be(false); expect(item.qtyScale).to.be(1); expect(item.quantityOnHand).to.be(0); expect(item.serializeItem).to.be(false); }); }); }); describe('.createNewRetailTransaction', function() { var transaction; var error; before(function(done) { service.createNewRetailTransaction({ serviceContext: config.context }, function(err, trans) { transaction = trans; error = err; done(); }); }); it('should not return an error when passed context', function() { expect(error).to.be(null); }); it('should return an error when not passed a context', function(done) { service.createNewRetailTransaction({ }, function(err, trans) { expect(err).to.be.an(Error); done(); }); }) it('should return a transaction object', function() { expect(transaction).to.be.an('object'); }); it('should have the basic transaction fields', function() { expect(transaction).to.have.keys([ 'amountDue', 'businessDate', 'cashierId', 'changed', 'totalItemSold', 'totalTaxAmt', 'totalTenderAmt', 'transSeq', 'transSubTotal', 'transTotal', 'giftReceiptFlag' ]); }); it('should properly convert data types', function() { expect(transaction.amountDue).to.be.a('number'); expect(transaction.businessDate).to.be.a(Date); expect(transaction.cashierId).to.be.a('string'); expect(transaction.changed).to.be.a('boolean'); expect(transaction.totalItemSold).to.be.a('number'); expect(transaction.totalTaxAmt).to.be.a('number'); expect(transaction.totalTenderAmt).to.be.a('number'); expect(transaction.transSeq).to.be.a('number'); expect(transaction.transSubTotal).to.be.a('number'); expect(transaction.transTotal).to.be.a('number'); expect(transaction.giftReceiptFlag).to.be.a('boolean'); }); }); describe('.cancelRetailTransaction', function() { var seq; var error; var result = false; before(function(done) { service.createNewRetailTransaction({ serviceContext: config.context }, function(err, trans) { seq = (trans || {}).transSeq; done(err); }); }); before(function(done) { service.cancelRetailTransaction({ serviceContext: config.context, transSeq: seq }, function(err, success) { result = success; error = err; done(); }); }); it('should not return an error', function() { expect(error).to.be(null); }); it('should return success when passed real transaction', function() { expect(result).to.be.ok() }); it('should return success when called multiple times', function(done) { service.cancelRetailTransaction({ serviceContext: config.context, transSeq: seq }, function(err, success) { expect(err).to.be(null); expect(success).to.be.ok(); done(); }); }); it('should return success when called with bogus transaction', function(done) { service.cancelRetailTransaction({ serviceContext: config.context, transSeq: 765432 }, function(err, success) { expect(err).to.be(null); expect(success).to.be.ok(); done(); }); }); }); describe('.suspendRetailTransaction', function() { var seq; var error; var result = false; before(function(done) { service.createNewRetailTransaction({ serviceContext: config.context }, function(err, trans) { seq = (trans || {}).transSeq; done(err); }); }); before(function(done) { service.suspendRetailTransaction({ serviceContext: config.context, transSeq: seq }, function(err, success) { result = success; error = err; done(); }); }); it('should not return an error', function() { expect(error).to.be(null); }); it('should return success when passed real transaction', function() { expect(result).to.be.ok() }); it('should fail when called multiple times', function(done) { service.suspendRetailTransaction({ serviceContext: config.context, transSeq: seq }, function(err, success) { expect(err).to.be(null); expect(success).to.not.be.ok(); done(); }); }); it('should fail when called with bogus transaction', function(done) { service.suspendRetailTransaction({ serviceContext: config.context, transSeq: 765432 }, function(err, success) { expect(err).to.be(null); expect(success).to.not.be.ok(); done(); }); }); }); describe('.addCustomerToRetailTrans', function() { var seq; var error; var transaction; before(function(done) { service.createNewRetailTransaction({ serviceContext: config.context }, function(err, trans) { seq = (trans || {}).transSeq; done(err); }); }); before(function(done) { service.addCustomerToRetailTrans({ serviceContext: config.context, transSeq: seq, partyId: '43001000112' }, function(err, trans) { error = err; transaction = trans; done(); }); }); it('should not return an error', function() { expect(error).to.be(null); }); it('should return a transaction object', function() { expect(transaction).to.be.an('object'); }); it('should be marked as changed', function() { expect(transaction.changed).to.be.ok(); }); it('should have the same transSeq', function() { expect(transaction.transSeq).to.be(seq); }); it('should have added Nicholas Penree as a customer', function() { expect(transaction.customerEmailAddress).to.be('npenree@fye.com'); expect(transaction.customerFirstName).to.be('Nicholas'); expect(transaction.customerLastName).to.be('Penree'); }); }); describe('.addSaleLineItem', function() { var seq; var error; var transaction; before(function(done) { service.createNewRetailTransaction({ serviceContext: config.context }, function(err, trans) { seq = (trans || {}).transSeq; done(err); }); }); before(function(done) { service.addSaleLineItem({ serviceContext: config.context, transSeq: seq, itemId: '790692075812', qty: 1, price: 5.99 }, function(err, trans) { error = err; transaction = trans; done(); }); }); it('should not return an error for item on file', function() { expect(error).to.be(null); }); it('should return a transaction object with saleLines', function() { expect(transaction).to.be.an('object'); expect(transaction.saleLines).to.be.an('array'); expect(transaction.saleLines).to.have.length(1); }); it('should be marked as changed', function() { expect(transaction.changed).to.be.ok(); }); it('should have the same transSeq', function() { expect(transaction.transSeq).to.be(seq); }); it('should add single item to the transaction', function() { var line = transaction.saleLines[0]; var item = line.item; var fixture = require('./fixtures/add_sale_line_item1.json'); var fixtureLine = fixture.saleLines[0]; var fixtureItem = fixtureLine.item; expect(transaction.amountDue).to.be(fixture.amountDue); expect(transaction.cashierId).to.be(fixture.cashierId); expect(transaction.changed).to.be(fixture.changed); expect(transaction.totalItemSold).to.be(fixture.totalItemSold); expect(transaction.totalTaxAmt).to.be(fixture.totalTaxAmt); expect(transaction.totalTenderAmt).to.be(fixture.totalTenderAmt); expect(transaction.transSubTotal).to.be(fixture.transSubTotal); expect(transaction.transTotal).to.be(fixture.transTotal); expect(transaction.giftReceiptFlag).to.be(fixture.giftReceiptFlag); expect(line.changed).to.be(fixtureLine.changed); expect(line.giftReceiptFlag).to.be(fixtureLine.giftReceiptFlag); expect(line.itemDescription).to.be(fixtureLine.itemDescription); expect(line.itemId).to.be(fixtureLine.itemId); expect(line.lineNumber).to.be(fixtureLine.lineNumber); expect(line.qty).to.be(fixtureLine.qty); expect(line.saleItemType).to.be(fixtureLine.saleItemType); expect(line.totalLineDiscountAmount).to.be(fixtureLine.totalLineDiscountAmount); expect(line.totalLinePrice).to.be(fixtureLine.totalLinePrice); expect(line.unitPrice).to.be(fixtureLine.unitPrice); expect(line.voidFlag).to.be(fixtureLine.voidFlag); expect(item.departmentId).to.be(fixtureItem.departmentId); expect(item.desc).to.be(fixtureItem.desc); expect(item.dimensionSummary).to.be(fixtureItem.dimensionSummary); expect(item.disallowSendSale).to.be(fixtureItem.disallowSendSale); expect(item.giftCard).to.be(fixtureItem.giftCard); expect(item.itemClassId).to.be(fixtureItem.itemClassId); expect(item.subdepartmentId).to.be(fixtureItem.subdepartmentId); expect(item.itemId).to.be(fixtureItem.itemId); expect(item.itemLevelCode).to.be(fixtureItem.itemLevelCode); expect(item.itemTypeCode).to.be(fixtureItem.itemTypeCode); expect(item.minAgeRequired).to.be(fixtureItem.minAgeRequired); expect(item.promptForDescription).to.be(fixtureItem.promptForDescription); expect(item.promptForPrice).to.be(fixtureItem.promptForPrice); expect(item.promptForQty).to.be(fixtureItem.promptForQty); expect(item.promptForWeight).to.be(fixtureItem.promptForWeight); expect(item.qtyScale).to.be(fixtureItem.qtyScale); expect(item.quantityOnHand).to.be(fixtureItem.quantityOnHand); expect(item.serializeItem).to.be(fixtureItem.serializeItem); }); it('should add two of another item to the transaction', function(done) { service.addSaleLineItem({ serviceContext: config.context, transSeq: seq, itemId: '790692075812', qty: 2, price: 24.99 }, function(err, trans) { if (err) return done(err); //console.log(JSON.stringify(trans, null, 2)); var line = trans.saleLines[0]; var item = line.item; var fixture = require('./fixtures/add_sale_line_item2.json'); var fixtureLine = fixture.saleLines[0]; // WTF? var fixtureItem = fixtureLine.item; expect(trans).to.be.an('object'); expect(trans.transSeq).to.be(seq); expect(trans.saleLines).to.be.an('array'); expect(trans.saleLines).to.have.length(1); // WTF? expect(trans.amountDue).to.be(fixture.amountDue); expect(trans.cashierId).to.be(fixture.cashierId); expect(trans.changed).to.be(fixture.changed); expect(trans.totalItemSold).to.be(fixture.totalItemSold); expect(trans.totalTaxAmt).to.be(fixture.totalTaxAmt); expect(trans.totalTenderAmt).to.be(fixture.totalTenderAmt); expect(trans.transSubTotal).to.be(fixture.transSubTotal); expect(trans.transTotal).to.be(fixture.transTotal); expect(trans.giftReceiptFlag).to.be(fixture.giftReceiptFlag); expect(line.changed).to.be(fixtureLine.changed); expect(line.giftReceiptFlag).to.be(fixtureLine.giftReceiptFlag); expect(line.itemDescription).to.be(fixtureLine.itemDescription); expect(line.itemId).to.be(fixtureLine.itemId); expect(line.lineNumber).to.be(fixtureLine.lineNumber); expect(line.qty).to.be(fixtureLine.qty); expect(line.saleItemType).to.be(fixtureLine.saleItemType); expect(line.totalLineDiscountAmount).to.be(fixtureLine.totalLineDiscountAmount); expect(line.totalLinePrice).to.be(fixtureLine.totalLinePrice); expect(line.unitPrice).to.be(fixtureLine.unitPrice); expect(line.voidFlag).to.be(fixtureLine.voidFlag); expect(item.departmentId).to.be(fixtureItem.departmentId); expect(item.desc).to.be(fixtureItem.desc); expect(item.dimensionSummary).to.be(fixtureItem.dimensionSummary); expect(item.disallowSendSale).to.be(fixtureItem.disallowSendSale); expect(item.giftCard).to.be(fixtureItem.giftCard); expect(item.itemClassId).to.be(fixtureItem.itemClassId); expect(item.subdepartmentId).to.be(fixtureItem.subdepartmentId); expect(item.itemId).to.be(fixtureItem.itemId); expect(item.itemLevelCode).to.be(fixtureItem.itemLevelCode); expect(item.itemTypeCode).to.be(fixtureItem.itemTypeCode); expect(item.minAgeRequired).to.be(fixtureItem.minAgeRequired); expect(item.promptForDescription).to.be(fixtureItem.promptForDescription); expect(item.promptForPrice).to.be(fixtureItem.promptForPrice); expect(item.promptForQty).to.be(fixtureItem.promptForQty); expect(item.promptForWeight).to.be(fixtureItem.promptForWeight); expect(item.qtyScale).to.be(fixtureItem.qtyScale); expect(item.quantityOnHand).to.be(fixtureItem.quantityOnHand); expect(item.serializeItem).to.be(fixtureItem.serializeItem); done(); }); }); it('should return an error for a not on file item', function(done) { service.addSaleLineItem({ serviceContext: config.context, transSeq: seq, itemId: '314124112312311', qty: 2, price: 9.99 }, function(err, trans) { expect(err).to.be.an(Error); expect(trans).to.be(null); expect(err.message).to.be('Item Not On File'); done(); }); }); }); });