-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeteor-accounts-anonymous-auto-tests.js
48 lines (45 loc) · 1.29 KB
/
meteor-accounts-anonymous-auto-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"use strict";
/* globals AccountsAnonymousAuto */
Tinytest.addAsync('AccountsAnonymousAuto - auto-login', function (test, done) {
AccountsAnonymousAuto._enabled.set(true);
var loginFailureStopper = Accounts.onLoginFailure(function () {
loginFailureStopper.stop();
test.fail('Login failed');
});
if (Meteor.loggingIn()) {
var checkLoginStopper = Accounts.onLogin(function () {
checkLoginStopper.stop();
checkLogin();
});
} else {
Meteor.logout(function (err) {
test.isUndefined(err);
Tracker.flush();
Meteor.setTimeout(function () {
checkLogin();
}, 100);
});
}
function checkLogin() {
var initialId = Meteor.userId();
test.isNotNull(initialId);
Meteor.logout(function (err) {
test.isUndefined(err);
if (Meteor.loggingIn()) {
var checkLoginAfterLogoutStopper = Accounts.onLogin(function () {
checkLoginAfterLogoutStopper.stop();
checkLoginAfterLogout();
});
} else {
checkLoginAfterLogout();
}
function checkLoginAfterLogout() {
var newId = Meteor.userId();
test.notEqual(newId, initialId);
AccountsAnonymousAuto._enabled.set(false);
loginFailureStopper.stop();
done();
}
});
}
});