mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
948934da2d
closes https://github.com/TryGhost/Team/issues/950 - fixes the mrr value/chart on dashboard when a site has no new mrr events in more than 30 days shown as 0 - adds tests to cover more mrr event scenarios
86 lines
3.1 KiB
JavaScript
86 lines
3.1 KiB
JavaScript
import moment from 'moment';
|
|
import {describe, it} from 'mocha';
|
|
import {expect} from 'chai';
|
|
import {setupTest} from 'ember-mocha';
|
|
|
|
describe('Unit: Service: membersStats', function () {
|
|
setupTest();
|
|
|
|
let memberStatsService;
|
|
|
|
beforeEach(function () {
|
|
memberStatsService = this.owner.lookup('service:membersStats');
|
|
});
|
|
|
|
it('fills correct date and value for mrr data when no data points', function () {
|
|
const data = [];
|
|
const output = memberStatsService.fillDates(data);
|
|
const values = Object.values(output);
|
|
const keys = Object.keys(output);
|
|
|
|
expect(values[0]).to.equal(0);
|
|
expect(keys[0]).to.equal(moment().subtract(30, 'days').format('YYYY-MM-DD'));
|
|
expect(keys[keys.length - 1]).to.equal(moment().format('YYYY-MM-DD'));
|
|
expect(values[values.length - 1]).to.equal(0);
|
|
});
|
|
|
|
it('fills correct date and value for mrr data when no data point in range', function () {
|
|
const data = [
|
|
{
|
|
date: moment().subtract(40, 'days').format('YYYY-MM-DD'),
|
|
value: 10459
|
|
},
|
|
{
|
|
date: moment().subtract(31, 'days').format('YYYY-MM-DD'),
|
|
value: 14459
|
|
}
|
|
];
|
|
const output = memberStatsService.fillDates(data);
|
|
const values = Object.values(output);
|
|
const keys = Object.keys(output);
|
|
|
|
expect(values[0]).to.equal(14459);
|
|
expect(keys[0]).to.equal(moment().subtract(30, 'days').format('YYYY-MM-DD'));
|
|
expect(keys[keys.length - 1]).to.equal(moment().format('YYYY-MM-DD'));
|
|
expect(values[values.length - 1]).to.equal(14459);
|
|
});
|
|
|
|
it('fills correct date and value for mrr data when first data point outside range', function () {
|
|
const data = [
|
|
{
|
|
date: moment().subtract(31, 'days').format('YYYY-MM-DD'),
|
|
value: 14459
|
|
},
|
|
{
|
|
date: moment().subtract(10, 'days').format('YYYY-MM-DD'),
|
|
value: 98176
|
|
}
|
|
];
|
|
const output = memberStatsService.fillDates(data);
|
|
const values = Object.values(output);
|
|
const keys = Object.keys(output);
|
|
|
|
expect(values[0]).to.equal(14459);
|
|
expect(keys[0]).to.equal(moment().subtract(30, 'days').format('YYYY-MM-DD'));
|
|
expect(keys[keys.length - 1]).to.equal(moment().format('YYYY-MM-DD'));
|
|
expect(values[values.length - 1]).to.equal(98176);
|
|
});
|
|
|
|
it('fills correct date and value for mrr data when only 1 data point in range', function () {
|
|
const data = [
|
|
{
|
|
date: moment().subtract(29, 'days').format('YYYY-MM-DD'),
|
|
value: 14459
|
|
}
|
|
];
|
|
const output = memberStatsService.fillDates(data);
|
|
const values = Object.values(output);
|
|
const keys = Object.keys(output);
|
|
|
|
expect(values[0]).to.equal(14459);
|
|
expect(keys[0]).to.equal(moment().subtract(30, 'days').format('YYYY-MM-DD'));
|
|
expect(keys[keys.length - 1]).to.equal(moment().format('YYYY-MM-DD'));
|
|
expect(values[values.length - 1]).to.equal(14459);
|
|
});
|
|
});
|