-
Notifications
You must be signed in to change notification settings - Fork 38
/
accounts-guest-server-tests.js
43 lines (37 loc) · 1.71 KB
/
accounts-guest-server-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
Tinytest.add(
'guest - remove guests',
function (test) {
AccountsGuest.anonymous = false;
var before = new Date();
before.setHours(before.getHours() - 100000);
Meteor.call('createGuest');
var username = Meteor.uuid();
Accounts.createUser({password: Meteor.uuid(), username: username, profile: {guest: true, name: 'Guest'}});
Meteor.users.update({username: username},{$set: {createdAt: before}});
usr = Meteor.users.findOne({username: username});
test.isFalse((typeof usr === 'undefined'), 'guest account not defined');
before.setHours(before.getHours() + 1);
res = Accounts.removeOldGuests(before);
test.equal(res, 1, 'should exactly one deleted');
usr = Meteor.users.findOne({username: username});
test.isTrue((typeof usr === 'undefined'), 'guest account not deleted');}
);
Tinytest.add(
'guest - remove anonymous guests',
function (test) {
AccountsGuest.anonymous = true;
var before = new Date();
before.setHours(before.getHours() - 100000);
var connection = DDP.connect(Meteor.absoluteUrl());
connection.call('login', {createGuest: true});
var usr = Meteor.users.findOne({'profile.guest': true});
oldUserId = usr._id;
Meteor.users.update({_id: oldUserId},{$set: {createdAt: before}});
usr = Meteor.users.findOne({_id: oldUserId});
test.isFalse((typeof usr === 'undefined'), 'guest account not defined');
before.setHours(before.getHours() + 1);
res = Accounts.removeOldGuests(before);
test.equal(res, 1, 'should exactly one deleted');
usr = Meteor.users.findOne({_id: oldUserId});
test.isTrue((typeof usr === 'undefined'), 'guest account not deleted');}
);