forked from mondora/mondora-connect-with
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client-tests.js
104 lines (97 loc) · 3.33 KB
/
client-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
var next = function (fn) {
var n = 0;
return function () {
var self = this;
var args = arguments;
setTimeout(function () {
fn.apply(self, args);
}, n++ * 1000);
};
};
/*
* mondora:connect-with - the `addLoginService` method should throw if the caller is not a logged in user
*/
Tinytest.addAsync("mondora:connect-with - the `addLoginService` method should throw if the caller is not a logged in user", next(function (test, done) {
Meteor.logout(function () {
Meteor.call("addLoginService", {}, function (error) {
test.instanceOf(error, Meteor.Error);
test.equal(error.error, "Login required");
done();
});
});
}));
/*
* mondora:connect-with - the `addLoginService` method should throw if the argument passed to it is not an object
*/
Tinytest.addAsync("mondora:connect-with - the `addLoginService` method should throw if the argument passed to it is not an object", next(function (test, done) {
Meteor.call("addUser", function () {
Meteor.loginWithPassword("pscanf", "pscanf", function () {
Meteor.call("addLoginService", "notAnObject", function (error) {
test.instanceOf(error, Meteor.Error);
test.equal(error.error, "Match failed");
done();
});
});
});
}));
/*
* mondora:connect-with - the `addLoginService` method should connect the existing user with the profile returned by the oauth provider
*/
Tinytest.addAsync("mondora:connect-with - the `addLoginService` method should connect the existing user with the profile returned by the oauth provider", next(function (test, done) {
Meteor.call("addUser", function () {
Meteor.call("addPendingCredentials", function () {
Meteor.loginWithPassword("pscanf", "pscanf", function () {
var credentials = {
oauth: {
credentialToken: "1234",
credentialSecret: "1234"
}
};
Meteor.call("addLoginService", credentials, function (error) {
test.equal(error, undefined);
Meteor.call("checkServiceData", function (error, result) {
test.isTrue(result);
done();
});
});
});
});
});
}));
/*
* mondora:connect-with - the `listLoginServices` method should throw if the caller is not a logged in user
*/
Tinytest.addAsync("mondora:connect-with - the `listLoginServices` method should throw if the caller is not a logged in user", next(function (test, done) {
Meteor.logout(function () {
Meteor.call("listLoginServices", {}, function (error) {
test.instanceOf(error, Meteor.Error);
test.equal(error.error, "Login required");
done();
});
});
}));
/*
* mondora:connect-with - the `listLoginServices` method should throw if the argument passed to it is not an object
*/
Tinytest.addAsync("mondora:connect-with - the `addLoginService` method should return the list of login services used by the user", next(function (test, done) {
Meteor.call("addUser", function () {
Meteor.call("addPendingCredentials", function () {
Meteor.loginWithPassword("pscanf", "pscanf", function () {
var credentials = {
oauth: {
credentialToken: "1234",
credentialSecret: "1234"
}
};
Meteor.call("addLoginService", credentials, function (error) {
test.equal(error, undefined);
Meteor.call("listLoginServices", function (error, result) {
test.equal(error, undefined);
test.equal(result.sort(), ["password", "google"].sort());
done();
});
});
});
});
});
}));