| Total Complexity | 7 |
| Complexity/F | 1 |
| Lines of Code | 44 |
| Function Count | 7 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | 'use strict' |
||
| 2 | var mongoose = require('mongoose') |
||
| 3 | var Company = mongoose.model('Company') |
||
| 4 | var Expense = mongoose.model('Expense') |
||
| 5 | var chai = require('chai') |
||
| 6 | var expect = chai.expect |
||
| 7 | |||
| 8 | describe('Unit Test Expense Model', function () { |
||
| 9 | it('should fail with invalid company', function (done) { |
||
| 10 | var expense = new Expense({ |
||
| 11 | company: 'test', |
||
| 12 | items: [{ desc: 'Boiler Service and Repair', total: 80.00 }] |
||
| 13 | }) |
||
| 14 | |||
| 15 | expense.validate(function (err) { |
||
| 16 | expect(err.errors.company).to.exist |
||
|
|
|||
| 17 | done() |
||
| 18 | }) |
||
| 19 | }) |
||
| 20 | |||
| 21 | it('should fail with invalid line items', function (done) { |
||
| 22 | var expense = new Expense({ |
||
| 23 | company: new Company({name: 'ABC Oil Gas Company'}), |
||
| 24 | items: [{test: 'test'}] |
||
| 25 | }) |
||
| 26 | |||
| 27 | expense.validate(function (err) { |
||
| 28 | expect(err.errors).to.exist |
||
| 29 | done() |
||
| 30 | }) |
||
| 31 | }) |
||
| 32 | |||
| 33 | it('should be valid with minimal data', function (done) { |
||
| 34 | var expense = new Expense({ |
||
| 35 | company: new Company({name: 'ABC Oil Gas Company'}), |
||
| 36 | items: [{ desc: 'Boiler Service and Repair', total: 80.00 }] |
||
| 37 | }) |
||
| 38 | |||
| 39 | expense.validate(function (err) { |
||
| 40 | expect(err).to.not.exist |
||
| 41 | done() |
||
| 42 | }) |
||
| 43 | }) |
||
| 44 | }) |
||
| 45 |