Skip to content

Commit

Permalink
Fix random tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Nov 10, 2021
1 parent 5c6dc91 commit 1fd03b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/test/lib/device/device.calculateAggregate.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { expect } = require('chai');
const uuid = require('uuid');
const EventEmitter = require('events');
const { fake } = require('sinon');
const sinon = require('sinon');

const { fake } = sinon;
const db = require('../../../models');
const Device = require('../../../lib/device');
const Job = require('../../../lib/job');
Expand Down Expand Up @@ -29,6 +31,7 @@ const insertStates = async (fixedHour = true) => {

describe('Device.calculateAggregate', function Before() {
this.timeout(60000);
let clock;
beforeEach(async () => {
const queryInterface = db.sequelize.getQueryInterface();
await queryInterface.bulkDelete('t_device_feature_state');
Expand All @@ -41,6 +44,12 @@ describe('Device.calculateAggregate', function Before() {
},
{ where: {} },
);
clock = sinon.useFakeTimers({
now: 1635131280000,
});
});
afterEach(() => {
clock.restore();
});
it('should calculate hourly aggregate', async () => {
await insertStates(false);
Expand Down
10 changes: 10 additions & 0 deletions server/test/lib/device/device.getDeviceFeaturesAggregates.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const EventEmitter = require('events');
const { expect, assert } = require('chai');
const sinon = require('sinon');
const uuid = require('uuid');
const { fake } = require('sinon');
const db = require('../../../models');
Expand Down Expand Up @@ -28,6 +29,8 @@ const insertStates = async (intervalInMinutes) => {

describe('Device.getDeviceFeaturesAggregates', function Describe() {
this.timeout(15000);

let clock;
beforeEach(async () => {
const queryInterface = db.sequelize.getQueryInterface();
await queryInterface.bulkDelete('t_device_feature_state');
Expand All @@ -40,6 +43,13 @@ describe('Device.getDeviceFeaturesAggregates', function Describe() {
},
{ where: {} },
);

clock = sinon.useFakeTimers({
now: 1635131280000,
});
});
afterEach(() => {
clock.restore();
});
it('should return last hour states', async () => {
await insertStates(120);
Expand Down

0 comments on commit 1fd03b1

Please sign in to comment.