|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const assert = require('assert') |
| 5 | +const _compact = require('lodash/compact') |
| 6 | +const _includes = require('lodash/includes') |
| 7 | +const { Invoice } = require('../../../lib') |
| 8 | +const testModel = require('../../helpers/test_model') |
| 9 | +// const testModelValidation = require('../../helpers/test_model_validation') |
| 10 | + |
| 11 | +describe('Invoice model', () => { |
| 12 | + testModel({ |
| 13 | + model: Invoice, |
| 14 | + orderedFields: [ |
| 15 | + 'invoiceHash', |
| 16 | + 'invoice', |
| 17 | + null, |
| 18 | + null, |
| 19 | + 'amount' |
| 20 | + ] |
| 21 | + }) |
| 22 | + |
| 23 | + // testModelValidation({ |
| 24 | + // model: Invoice, |
| 25 | + // validData: { |
| 26 | + // invoiceHash: ['foo', 'bar', 'baz', 'qux'], |
| 27 | + // invoice: ['foo1', 'bar2', 'baz3', 'qux4'], |
| 28 | + // amount: ['0.001', '0.002', '0.003', '0.004'] |
| 29 | + // } |
| 30 | + // }) |
| 31 | + |
| 32 | + it('initializes correctly', () => { |
| 33 | + const invc = new Invoice([ |
| 34 | + 'invoiceHash', |
| 35 | + 'invoice', |
| 36 | + null, |
| 37 | + null, |
| 38 | + 'amount' |
| 39 | + ]) |
| 40 | + |
| 41 | + assert.strictEqual(invc.invoiceHash, 'invoiceHash') |
| 42 | + assert.strictEqual(invc.invoice, 'invoice') |
| 43 | + assert.strictEqual(invc.amount, 'amount') |
| 44 | + }) |
| 45 | + |
| 46 | + it('serializes correctly', () => { |
| 47 | + const invc = new Invoice([ |
| 48 | + 'invoiceHash', |
| 49 | + 'invoice', |
| 50 | + null, |
| 51 | + null, |
| 52 | + 'amount' |
| 53 | + ]) |
| 54 | + |
| 55 | + const arr = _compact(invc.serialize()) |
| 56 | + assert.deepStrictEqual(arr, [ |
| 57 | + 'invoiceHash', |
| 58 | + 'invoice', |
| 59 | + 'amount' |
| 60 | + ]) |
| 61 | + }) |
| 62 | + |
| 63 | + it('unserializes correctly', () => { |
| 64 | + const obj = Invoice.unserialize([ |
| 65 | + 'invoiceHash', |
| 66 | + 'invoice', |
| 67 | + null, |
| 68 | + null, |
| 69 | + 'amount' |
| 70 | + ]) |
| 71 | + |
| 72 | + assert.strictEqual(obj.invoiceHash, 'invoiceHash') |
| 73 | + assert.strictEqual(obj.invoice, 'invoice') |
| 74 | + assert.strictEqual(obj.amount, 'amount') |
| 75 | + }) |
| 76 | + |
| 77 | + describe('toString', () => { |
| 78 | + it('includes pertinent information', () => { |
| 79 | + const invc = new Invoice({ |
| 80 | + invoiceHash: 'invoiceHash', |
| 81 | + invoice: 'invoice', |
| 82 | + amount: '0.0001' |
| 83 | + }) |
| 84 | + |
| 85 | + const str = invc.toString() |
| 86 | + assert.ok(_includes(str, 'invoiceHash: invoiceHash'), 'invoiceHash missing') |
| 87 | + assert.ok(_includes(str, 'invoice: invoice'), 'invoice missing') |
| 88 | + assert.ok(_includes(str, 'amount: 0.0001'), 'amount missing') |
| 89 | + }) |
| 90 | + }) |
| 91 | +}) |
0 commit comments