This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
forked from jzgoda/managed-users
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanagedUsers_tests.js
109 lines (92 loc) · 3.57 KB
/
managedUsers_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// More testing probably needs to be done, but the most important functionality is being tested.
// I heavily borrowed from meteor/packages/accounts-password/password_tests.js to figure out how to test an account.
Tinytest.add("ManagedUsers - No Permissions Found", function(test) {
// I added this to "reset" the function to it's default, so re-runs of testing isn't broken.
// There should be a cleaner way to reset the testing state back to the default, as opposed to restarting the server
Meteor.ManagedUsers.availablePermissions = function() {
return {};
}
test.equal(_.toArray(Meteor.ManagedUsers.availablePermissions()).length, 0, "There should be no permissions at this point.");
});
Tinytest.add("ManagedUsers - 2 Permissions Found", function(test) {
// Set the permissions
Meteor.ManagedUsers.availablePermissions = function() {
var permissions = {
allowThis: "Allow the user to do this",
allowThat: "Allow the user to do that"
};
return permissions;
}
test.equal(_.toArray(Meteor.ManagedUsers.availablePermissions()).length, 2, "There should be 2 permissions, this & that.");
});
if(Meteor.isClient) {
Accounts._isolateLoginTokenForTest();
var logoutStep = function (test, expect) {
Meteor.logout(expect(function (error) {
test.equal(error, undefined);
test.equal(Meteor.user(), null);
}));
};
var loggedInAs = function (someUsername, test, expect) {
return expect(function (error) {
test.equal(error, undefined);
test.equal(Meteor.user().username, someUsername);
});
};
testAsyncMulti("ManagedUsers - Account manipulation", [
logoutStep,
function(test, expect) {
test.isFalse(Meteor.ManagedUsers.isAdmin());
Accounts.createUser({username: "someone", password: "abc123", profile: {name: "Some One"}}, function(error) {
test.equal(error.reason, "Signups forbidden");
});
Meteor.call('addUser', "someone", "Some One", "[email protected]", {}, expect(function(error, result) {
test.instanceOf(error, Meteor.Error);
test.equal(error.reason, "Only admin is allowed to do this.");
}));
},
logoutStep,
function(test, expect) {
Meteor.loginWithPassword("admin", "abc123", expect(function(error) {
test.equal(error, undefined);
test.equal(Meteor.user().username, "admin");
test.isTrue(Meteor.ManagedUsers.isAdmin());
}));
},
function(test, expect) {
Meteor.call('addUser', "someone", "Some One", "[email protected]", {}, expect(function(error, result) {
test.equal(error, undefined);
}));
},
function(test, expect) {
var someone = Meteor.users.findOne({username: "someone"});
Meteor.call('passwordReset', someone._id, expect(function(error, result) {
test.equal(error, undefined);
test.equal(result, someone._id);
}));
},
function(test, expect) {
var someone = Meteor.users.findOne({username: "someone"});
test.equal("Some One", someone.profile.name);
Meteor.call('updateUser', someone._id, someone.username, someone.profile.name, null, {}, expect(function(error, result) {
test.equal(error, undefined);
test.equal(result, someone._id);
}));
},
function(test, expect) {
var someone = Meteor.users.findOne({username: "someone"});
Meteor.call('passwordReset', someone._id, expect(function(error, result) {
test.instanceOf(error, Meteor.Error);
test.equal(error.reason, "Can't send email.");
}));
},
function(test, expect) {
var someone = Meteor.users.findOne({username: "someone"});
Meteor.call('removeUser', someone._id, expect(function(error, result) {
test.equal(error, undefined);
test.isTrue(result);
}));
},
logoutStep,
]);
}