Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/default/test/targets/births.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ describe('Births this month target tests', () => {

it('birth this month should be counted', async () => {
//await harness.setNow('2000-04-30');//DOB: 2000-04-24
clock = sinon.useFakeTimers({now: moment('2000-04-30').toDate()});
clock = sinon.useFakeTimers({ now: moment('2000-04-30').toDate(), toFake: ['Date'] });
const birthsThisMonth = await harness.getTargets({ type: 'births-this-month' });
expect(birthsThisMonth).to.have.property('length', 1);
expect(birthsThisMonth[0]).to.nested.include({ 'value.pass': 1, 'value.total': 1 });
});

it('birth last month should not be counted', async () => {
//await harness.setNow('2000-04-30');//DOB: 2000-04-24
clock = sinon.useFakeTimers({now: moment('2000-05-01').toDate()});
clock = sinon.useFakeTimers({ now: moment('2000-05-01').toDate(), toFake: ['Date'] });
const birthsThisMonth = await harness.getTargets({ type: 'births-this-month' });
expect(birthsThisMonth).to.have.property('length', 1);
expect(birthsThisMonth[0]).to.nested.not.include({ 'value.pass': 1, 'value.total': 1 });
Expand Down
4 changes: 2 additions & 2 deletions config/default/test/targets/deaths.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Death related targets tests', () => {

it('death this month target test this month', async () => {
//await harness.setNow('2000-04-30');//DOD: 2000-04-25
clock = sinon.useFakeTimers({now: moment('2000-04-30').toDate()});
clock = sinon.useFakeTimers({ now: moment('2000-04-30').toDate(), toFake: ['Date'] });
harness.subject = babyDeceasedAtAge1Day;
const birthsThisMonth = await harness.getTargets({ type: 'deaths-this-month' });
expect(birthsThisMonth).to.have.property('length', 1);
Expand All @@ -34,7 +34,7 @@ describe('Death related targets tests', () => {

it('death this month target test next month', async () => {
//await harness.setNow('2000-04-30');//DOD: 2000-04-25
clock = sinon.useFakeTimers({now: moment('2000-05-30').toDate()});
clock = sinon.useFakeTimers({ now: moment('2000-05-30').toDate(), toFake: ['Date'] });
harness.subject = babyDeceasedAtAge1Day;
const birthsThisMonth = await harness.getTargets({ type: 'deaths-this-month' });
expect(birthsThisMonth).to.have.property('length', 1);
Expand Down
81 changes: 52 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"sass": "^1.83.4",
"sharp": "^0.33.5",
"shellcheck": "^3.1.0",
"sinon": "^18.0.1",
"sinon": "^21.0.0",
"tail": "^2.2.6",
"ts-node": "^10.9.2",
"typedoc": "^0.28.7",
Expand All @@ -182,6 +182,7 @@
"util": "^0.12.5",
"wdio-chromedriver-service": "^8.1.1",
"webpack-bundle-analyzer": "^4.9.1",
"xhr-mock": "^2.5.1",
"xml-js": "^1.6.11"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/rules-engine/test/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe(`Rules Engine Integration Tests`, () => {
let configHashSalt = 0;

beforeEach(() => {
clock = sinon.useFakeTimers({now: TEST_START});
clock = sinon.useFakeTimers({ now: TEST_START, toFake: ['Date'] });
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/rules-engine/test/pouchdb-provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('pouchdb provider', () => {
db = await memdownMedic('../..');
await db.bulkDocs(fixtures);

clock = sinon.useFakeTimers({now: 100000000});
clock = sinon.useFakeTimers({ now: 100000000, toFake: ['Date'] });
sinon.spy(db, 'put');
sinon.spy(db, 'query');
});
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/rules-engine/test/provider-wireup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('provider-wireup integration tests', () => {
let provider;
let db;
beforeEach(async () => {
clock = sinon.useFakeTimers({now: NOW});
clock = sinon.useFakeTimers({ now: NOW, toFake: ['setTimeout', 'Date'] });
wireup = rewire('../src/provider-wireup');
rulesStateStore = RestorableRulesStateStore();
sinon.stub(rulesStateStore, 'currentUserContact').returns(currentUserContact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const NOW = 100000;

describe('refresh-rules-emissions', () => {
beforeEach(() => {
clock = sinon.useFakeTimers(NOW);
clock = sinon.useFakeTimers({ now: NOW, toFake: ['Date'] });
refreshRulesEmissionsContact = rewire('../src/refresh-rules-emissions');
});

Expand Down
2 changes: 1 addition & 1 deletion shared-libs/rules-engine/test/rules-emitter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ for (const rulesAreDeclarative of declarativeScenarios) {

it('trigger task.anc.pregnancy_home_visit', async () => {
const time = moment('2000-01-01');
clock = sinon.useFakeTimers({now: time.valueOf()});
clock = sinon.useFakeTimers({ now: time.valueOf(), toFake: ['Date'] });

const initialized = rulesEmitter.initialize(engineSettings({ rulesAreDeclarative }));
expect(initialized).to.be.true;
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/rules-engine/test/task-states.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let clock;

describe('task-states', () => {
before(() => {
clock = sinon.useFakeTimers({now: NOW});
clock = sinon.useFakeTimers({ now: NOW, toFake: ['Date'] });
TaskStates = rewire('../src/task-states');
definedStates = Object.keys(TaskStates).filter(key => typeof TaskStates[key] === 'string');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let clock;

describe('update-temporal-states', () => {
beforeEach(() => {
clock = sinon.useFakeTimers({now: NOW});
clock = sinon.useFakeTimers({ now: NOW, toFake: ['Date'] });
});

afterEach(() => {
Expand Down
25 changes: 12 additions & 13 deletions webapp/tests/karma/ts/services/delete-docs.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TestBed } from '@angular/core/testing';
import sinon from 'sinon';
import { expect, assert } from 'chai';
import mock from 'xhr-mock';

import { DbService } from '@mm-services/db.service';
import { SessionService } from '@mm-services/session.service';
Expand All @@ -15,7 +16,6 @@ describe('DeleteDocs service', () => {
let service;
let bulkDocs;
let isOnlineOnly;
let server;
let extractLineageService;
let getDataContext;
let bind;
Expand All @@ -42,13 +42,12 @@ describe('DeleteDocs service', () => {
});
service = TestBed.inject(DeleteDocsService);

server = sinon.fakeServer.create();
server.respondImmediately = true;
mock.setup();
});

afterEach(() => {
sinon.restore();
server.restore();
mock.teardown();
});

it('returns bulkDocs errors', () => {
Expand Down Expand Up @@ -198,16 +197,13 @@ describe('DeleteDocs service', () => {
it('sends a direct request to the server when user is an admin', () => {
const record1 = { _id: 'xyz', _rev: '1' };
const record2 = { _id: 'abc', _rev: '1' };
const expected1 = { _id: 'xyz' };
const expected2 = { _id: 'abc' };
server.respondWith([200, { 'Content-Type': 'application/json' }, '{ "hello": "there" }']);
mock.post('/api/v1/bulk-delete', {
status: 200,
body: '{ "hello": "there" }'
});

isOnlineOnly.returns(true);
return service.delete([ record1, record2 ]).then(() => {
expect(server.requests).to.have.lengthOf(1);
expect(server.requests[0].url).to.equal('/api/v1/bulk-delete');
expect(server.requests[0].requestBody).to.equal(JSON.stringify({
docs: [expected1, expected2]
}));
expect(bulkDocs.callCount).to.equal(0);
expect(getDataContext.calledOnceWithExactly()).to.be.true;
expect(bind.notCalled).to.be.true;
Expand All @@ -220,7 +216,10 @@ describe('DeleteDocs service', () => {
const record2 = { _id: 'abc' };
const onProgress = sinon.spy();
const response = '[[{"ok": true}, {"ok": true}],';
server.respondWith([200, { 'Content-Type': 'application/json' }, response]);
mock.post('/api/v1/bulk-delete', {
status: 200,
body: response
});
isOnlineOnly.returns(true);
return service
.delete([ record1, record2 ], { progress: onProgress })
Expand Down