Skip to content

Instantly share code, notes, and snippets.

@doug2k1
Last active March 22, 2018 23:34
Show Gist options
  • Save doug2k1/33f0bab25e4c79d4db1bbed95187105f to your computer and use it in GitHub Desktop.
Save doug2k1/33f0bab25e4c79d4db1bbed95187105f to your computer and use it in GitHub Desktop.
const expect = require('chai').expect;
const { Investment, Transaction } = require('../../src/models');
describe('Transaction', () => {
describe('attributes', () => {
it('should have amount and date', async () => {
const transaction = await Transaction.create({
amount: 1,
date: '2018-03-15'
});
expect(transaction.get('amount')).to.equal('1.00');
expect(transaction.get('date')).to.equal('2018-03-15');
});
});
describe('validations', () => {
it('should validate amount', () => {
const transaction = Transaction.build({ date: '2018-03-15' });
expect(transaction.validate()).to.be.rejected;
});
it('should validate date', () => {
const transaction = Transaction.build({ amount: 1 });
expect(transaction.validate()).to.be.rejected;
});
});
describe('relations', () => {
it('should belong to Investment', async () => {
const transaction = await Transaction.create(
{
amount: 1,
date: '2018-03-15',
Investment: { name: 'Inv' }
},
{ include: [Investment] }
);
expect(transaction.get('Investment').get('name')).to.equal('Inv');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment