From e9940633964b4d044b04e48e2cab8d624b9144ca Mon Sep 17 00:00:00 2001 From: Mike Lay Date: Thu, 15 Dec 2016 09:54:03 -0500 Subject: [PATCH] Add model unit test invoice (#872) - Add model unit test for invoice --- tests/unit/models/invoice-test.js | 95 +++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 tests/unit/models/invoice-test.js diff --git a/tests/unit/models/invoice-test.js b/tests/unit/models/invoice-test.js new file mode 100644 index 0000000000..dedf9921eb --- /dev/null +++ b/tests/unit/models/invoice-test.js @@ -0,0 +1,95 @@ +import { moduleForModel, test } from 'ember-qunit'; +import Ember from 'ember'; + +moduleForModel('invoice', 'Unit | Model | invoice', { + needs: [ + 'model:patient', + 'model:visit', + 'model:price-profile', + 'model:payment', + 'model:billing-line-item', + 'model:line-item-detail' + ] +}); + +const lineItemsData = [ + { + category: 'test', + privateInsurance: 10, + nationalInsurance: 3, + discount: 5 + }, + { + privateInsurance: 4, + nationalInsurance: 5, + discount: 2 + } +]; + +test('addPayment', function(assert) { + let payments; + Ember.run(() => { + payments = [12.5, 10].map((amount) => { + let model = this.store().createRecord('payment', { amount }); + model.set('currentState.parentState.isNew', false); + return model; + }); + }); + let invoice = this.subject(); + + Ember.run(() => invoice.addPayment(payments[0])); + assert.strictEqual(invoice.get('paidTotal'), 12.5, 'Should add first payment'); + + Ember.run(() => invoice.addPayment(payments[1])); + assert.strictEqual(invoice.get('paidTotal'), 22.5, 'Should add second payment'); +}); + +test('billAsDate', function(assert) { + let invoice = this.subject({ + billDate: new Date(1481745786401) + }); + + assert.strictEqual(invoice.get('billDateAsTime'), 1481745786401); +}); + +test('paidFlag', function(assert) { + let invoice = this.subject({ status: 'Paid' }); + + assert.strictEqual(invoice.get('paidFlag'), true); +}); + +test('paidFlag false', function(assert) { + let invoice = this.subject(); + + assert.strictEqual(invoice.get('paidFlag'), false); +}); + +test('discount', function(assert) { + let lineItems, invoice; + Ember.run(() => { + lineItems = lineItemsData.map((item) => this.store().createRecord('billing-line-item', item)); + invoice = this.subject({ lineItems }); + }); + + assert.strictEqual(invoice.get('discount'), 7); +}); + +test('nationalInsurance', function(assert) { + let lineItems, invoice; + Ember.run(() => { + lineItems = lineItemsData.map((item) => this.store().createRecord('billing-line-item', item)); + invoice = this.subject({ lineItems }); + }); + + assert.strictEqual(invoice.get('nationalInsurance'), 8); +}); + +test('privateInsurance', function(assert) { + let lineItems, invoice; + Ember.run(() => { + lineItems = lineItemsData.map((item) => this.store().createRecord('billing-line-item', item)); + invoice = this.subject({ lineItems }); + }); + + assert.strictEqual(invoice.get('privateInsurance'), 14); +});