sum.test.js
1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require('../support'),
DataTypes = require('../../../lib/data-types');
describe(Support.getTestDialectTeaser('Model'), () => {
beforeEach(async function() {
this.Payment = this.sequelize.define('Payment', {
amount: DataTypes.DECIMAL,
mood: {
type: DataTypes.ENUM,
values: ['happy', 'sad', 'neutral']
}
});
await this.sequelize.sync({ force: true });
await this.Payment.bulkCreate([
{ amount: 5, mood: 'neutral' },
{ amount: -5, mood: 'neutral' },
{ amount: 10, mood: 'happy' },
{ amount: 90, mood: 'happy' }
]);
});
describe('sum', () => {
it('should sum without rows', async function() {
await expect(this.Payment.sum('amount', { where: { mood: 'sad' } })).to.eventually.be.equal(0);
});
it('should sum when is 0', async function() {
await expect(this.Payment.sum('amount', { where: { mood: 'neutral' } })).to.eventually.be.equal(0);
});
it('should sum', async function() {
await expect(this.Payment.sum('amount', { where: { mood: 'happy' } })).to.eventually.be.equal(100);
});
});
});