diff --git a/app/models/inventory-batch.js b/app/models/inventory-batch.js index a84c3b55e8..f890633f39 100644 --- a/app/models/inventory-batch.js +++ b/app/models/inventory-batch.js @@ -7,7 +7,7 @@ import Ember from 'ember'; export default AbstractModel.extend({ haveInvoiceItems() { let invoiceItems = this.get('invoiceItems'); - return (Ember.isEmpty(invoiceItems)); + return !Ember.isEmpty(invoiceItems); }, validations: { @@ -16,7 +16,7 @@ export default AbstractModel.extend({ }, inventoryItemTypeAhead: { presence: { - if(object) { + unless(object) { return object.haveInvoiceItems(); } } @@ -27,7 +27,7 @@ export default AbstractModel.extend({ messages: { greaterThan: 'must be greater than 0' }, - if(object) { + unless(object) { return object.haveInvoiceItems(); } } @@ -38,7 +38,7 @@ export default AbstractModel.extend({ messages: { greaterThan: 'must be greater than 0' }, - if(object) { + unless(object) { return object.haveInvoiceItems(); } } diff --git a/tests/unit/models/inventory-batch-test.js b/tests/unit/models/inventory-batch-test.js new file mode 100644 index 0000000000..4d8721873c --- /dev/null +++ b/tests/unit/models/inventory-batch-test.js @@ -0,0 +1,53 @@ +import { moduleForModel, test } from 'ember-qunit'; +import { + testValidPropertyValues, + testInvalidPropertyValues +} from '../../helpers/validate-properties'; + +moduleForModel('inventory-batch', 'Unit | Model | inventory-batch', { + needs: [ + 'ember-validations@validator:local/presence', + 'ember-validations@validator:local/numericality' + ] +}); + +test('haveInvoiceItems', function(assert) { + let inventoryBatch = this.subject({ + invoiceItems: ['test have'] + }); + + assert.strictEqual(inventoryBatch.haveInvoiceItems(), true); +}); + +test('haveInvoiceItems false', function(assert) { + let inventoryBatch = this.subject(); + + assert.strictEqual(inventoryBatch.haveInvoiceItems(), false); +}); + +testValidPropertyValues('dateReceived', ['test dr']); +testInvalidPropertyValues('dateReceived', [undefined]); + +testValidPropertyValues('inventoryItemTypeAhead', ['test']); +testInvalidPropertyValues('inventoryItemTypeAhead', [undefined]); +// Test skip validation +testValidPropertyValues('inventoryItemTypeAhead', [undefined], function(subject) { + subject.set('invoiceItems', ['item']); +}); + +testValidPropertyValues('quantity', [0.001, 1, '123']); +testInvalidPropertyValues('quantity', [-1, 0, '-1']); +// Test skip validation +testValidPropertyValues('quantity', [-1], function(subject) { + subject.set('invoiceItems', ['item']); +}); + +testValidPropertyValues('purchaseCost', [0.001, 1, '123']); +testInvalidPropertyValues('purchaseCost', [-1, 0, '-1']); +// Test skip validation +testValidPropertyValues('purchaseCost', [-1], function(subject) { + subject.set('invoiceItems', ['item']); +}); + +testValidPropertyValues('vendor', ['test']); +testInvalidPropertyValues('vendor', [undefined]);