Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample of offline user failing to log in #7236

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions tests/e2e/login/login-logout.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const loginPage = require('../../page-objects/login/login.wdio.page');
const commonPage = require('../../page-objects/common/common.wdio.page');
const place = require('../../factories/cht/contacts/place');
const userFactory = require('../../factories/cht/users/users');
const utils = require('../../utils');
const auth = require('../../auth')();


Expand All @@ -14,13 +17,13 @@ describe('Login and logout tests', () => {
{ code: 'ne', name: 'नेपाली (Nepali)' },
{ code: 'sw', name: 'Kiswahili (Swahili)' }
];

const frTranslations = {
user: `Nom d'utilisateur`,
pass: 'Mot de passe',
error: `Nom d'utilisateur ou mot de passe incorrect. Veuillez réessayer`
};

const esTranslations = {
user: 'Nombre de usuario',
pass: 'Contraseña',
Expand Down Expand Up @@ -55,7 +58,20 @@ describe('Login and logout tests', () => {

it('should log in using username and password fields', async () => {
await loginPage.login(auth.username, auth.password);
expect(await commonPage.analyticsTab()).toBeDisplayed();
expect(await commonPage.messagesTab()).toBeDisplayed();
await expect(await commonPage.analyticsTab()).toBeDisplayed();
await expect(await commonPage.messagesTab()).toBeDisplayed();
});

it('can log in as an offline user', async () => {
const places = place.generateHierarchy();
const healthCenter = places.find((place) => place.type === 'health_center');
const offlineUser = userFactory.build({
place: healthCenter._id
});
await utils.saveDocs(places);
await utils.createUsers([offlineUser]);
await loginPage.login(offlineUser.username, offlineUser.password);
await expect(await commonPage.analyticsTab()).toBeDisplayed();
await expect(await commonPage.messagesTab()).toBeDisplayed();
});
});
33 changes: 16 additions & 17 deletions webapp/src/js/bootstrapper/swRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@ function register(onInstalling) {
return resolve();
}

onInstalling();
registration.onupdatefound = function() {
const installingWorker = registration.installing;
installingWorker.onstatechange = function() {
switch (installingWorker.state) {
case 'activated':
resolve(installingWorker);
installingWorker.onstatechange = undefined;
break;
case 'redundant':
reject(new Error('Service worker labeled redundant'));
installingWorker.onstatechange = undefined;
break;
default:
console.debug(`Service worker state changed to ${installingWorker.state}`);
}
};
const installingWorker = registration.installing;
installingWorker.onstatechange = function() {
switch (installingWorker.state) {
case 'activated':
resolve(installingWorker);
installingWorker.onstatechange = undefined;
break;
case 'redundant':
reject(new Error('Service worker labeled redundant'));
installingWorker.onstatechange = undefined;
break;
default:
console.debug(`Service worker state changed to ${installingWorker.state}`);
}
};

onInstalling();
})
.catch(reject);
});
Expand Down
10 changes: 3 additions & 7 deletions webapp/tests/mocha/unit/bootstrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,10 @@ describe('bootstrapper', () => {
localGet.withArgs('_design/medic-client').rejects();
sinon.stub(purger, 'setOptions');

const localReplicateResult = Promise.reject({ status: 401 });
localReplicateResult.on = () => {};
localReplicate.returns(localReplicateResult);

localAllDocs.resolves({ total_rows: 0 });
fetch.resolves({ json: sinon.stub().resolves({ total_docs: 2500, warn: false }) });

bootstrapper(pouchDbOptions, err => {
assert.equal(localReplicate.callCount, 0);
assert.equal(localAllDocs.callCount, 0);
assert.equal(fetch.callCount, 0);
assert.equal(err.status, 401);
assert.equal(
err.redirect,
Expand Down
2 changes: 1 addition & 1 deletion webapp/tests/mocha/unit/swRegister.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { expect } = require('chai');
let fakeRegisterFunc;

function executeSwLifecycle(registration) {
setTimeout(() => registration.onupdatefound(), 1);
//setTimeout(() => registration.onupdatefound(), 1);
setTimeout(() => registration.installing.onstatechange(), 2);
}

Expand Down