const buildDates = () => { const currDate = new Date() const today = `${currDate.getUTCFullYear()}-${currDate.getUTCMonth() + 1}-${currDate.getUTCDate()}` currDate.setDate(currDate.getDate() - 1) const yesterday = `${currDate.getUTCFullYear()}-${currDate.getUTCMonth() + 1}-${currDate.getUTCDate()}` return [yesterday, today] }
describe('areAllDataFetched', () => { it('should return false if data is undefined', () => { const props = generateProps() const graph = mount(<MetricsGraph {...props} />) const inst = graph.instance() assert(inst.areAllDataFetched(undefined, props.timeframe) === false) }) it('should return false if some data are not fetched yet', () => { const props = generateProps() const graph = mount(<MetricsGraph {...props} />) const inst = graph.instance() const currDate = new Date() const key = `${currDate.getUTCFullYear()}-${currDate.getUTCMonth() + 1}-${currDate.getUTCDate()}` assert(inst.areAllDataFetched({[key]: []}, props.timeframe) === false) }) it('should return true if all data are fetched', () => { const props = generateProps() const graph = mount(<MetricsGraph {...props} />) const inst = graph.instance() const dates = buildDates() assert(inst.areAllDataFetched({[dates[0]]: [], [dates[1]]: []}, props.timeframe)) }) })
it('group by date object transform', done => { const obj1 = new TestObject(); const obj2 = new TestObject(); const obj3 = new TestObject(); const pipeline = [ { group: { objectId: { day: { $dayOfMonth: '$updatedAt' }, month: { $month: '$createdAt' }, year: { $year: '$createdAt' }, }, count: { $sum: 1 }, }, }, ]; Parse.Object.saveAll([obj1, obj2, obj3]) .then(() => { const query = new Parse.Query(TestObject); return query.aggregate(pipeline); }) .then(results => { const createdAt = new Date(obj1.createdAt); expect(results[0].objectId.day).toEqual(createdAt.getUTCDate()); expect(results[0].objectId.month).toEqual(createdAt.getUTCMonth() + 1); expect(results[0].objectId.year).toEqual(createdAt.getUTCFullYear()); done(); }); });
function currentDateArray(config) { // hooks is actually the exported moment object var nowValue = new Date(utils_hooks__hooks.now()); if (config._useUTC) { return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()]; } return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()]; }
function setWeekAll(weekYear, week, weekday, dow, doy) { var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy), date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear); this.year(date.getUTCFullYear()); this.month(date.getUTCMonth()); this.date(date.getUTCDate()); return this; }
function currentDateArray(config) { var now = new Date(); if (config._useUTC) { return [ now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() ]; } else { return [now.getFullYear(), now.getMonth(), now.getDate()]; } }
function startOfWeek(year, month, day, weekStartsOn) { const date = utc(year, month, day); const weekDay = date.getUTCDay(); const diff = (weekDay < weekStartsOn ? 7 : 0) + weekDay - weekStartsOn; date.setUTCDate(date.getUTCDate() - diff); return [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()]; }
function addDay(year, month, day) { const date = utc(year, month, day); date.setUTCDate(date.getUTCDate() + 1); return [date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()]; }
const buildDates = () => { const currDate = new Date() const today = `${currDate.getUTCFullYear()}-${currDate.getUTCMonth() + 1}-${currDate.getUTCDate()}` currDate.setDate(currDate.getDate() - 1) const yesterday = `${currDate.getUTCFullYear()}-${currDate.getUTCMonth() + 1}-${currDate.getUTCDate()}` return [yesterday, today] }
describe('areAllDataFetched', () => { it('should return false if data is undefined', () => { const props = generateProps() const graph = mount(<MetricsGraph {...props} />) const inst = graph.instance() assert(inst.areAllDataFetched(undefined, props.timeframe) === false) }) it('should return false if some data are not fetched yet', () => { const props = generateProps() const graph = mount(<MetricsGraph {...props} />) const inst = graph.instance() const currDate = new Date() const key = `${currDate.getUTCFullYear()}-${currDate.getUTCMonth() + 1}-${currDate.getUTCDate()}` assert(inst.areAllDataFetched({[key]: []}, props.timeframe) === false) }) it('should return true if all data are fetched', () => { const props = generateProps() const graph = mount(<MetricsGraph {...props} />) const inst = graph.instance() const dates = buildDates() assert(inst.areAllDataFetched({[dates[0]]: [], [dates[1]]: []}, props.timeframe)) }) })
it('group by date object', done => { const obj1 = new TestObject(); const obj2 = new TestObject(); const obj3 = new TestObject(); const pipeline = [ { group: { objectId: { day: { $dayOfMonth: '$_updated_at' }, month: { $month: '$_created_at' }, year: { $year: '$_created_at' }, }, count: { $sum: 1 }, }, }, ]; Parse.Object.saveAll([obj1, obj2, obj3]) .then(() => { const query = new Parse.Query(TestObject); return query.aggregate(pipeline); }) .then(results => { const createdAt = new Date(obj1.createdAt); expect(results[0].objectId.day).toEqual(createdAt.getUTCDate()); expect(results[0].objectId.month).toEqual(createdAt.getUTCMonth() + 1); expect(results[0].objectId.year).toEqual(createdAt.getUTCFullYear()); done(); }); });
function setWeekAll(weekYear, week, weekday, dow, doy) { var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy), date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear); this.year(date.getUTCFullYear()); this.month(date.getUTCMonth()); this.date(date.getUTCDate()); return this; }
function currentDateArray(config) { // hooks is actually the exported moment object var nowValue = new Date(hooks.now()); if (config._useUTC) { return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()]; } return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()]; }
function currentDateArray(config) { // hooks is actually the exported moment object var nowValue = new Date(hooks.now()); if (config._useUTC) { return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()]; } return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()]; }
function currentDateArray(config) { // hooks is actually the exported moment object var nowValue = new Date(hooks.now()); if (config._useUTC) { return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()]; } return [nowValue.getFullYear(), nowValue.getMonth(), nowValue.getDate()]; }