-
Notifications
You must be signed in to change notification settings - Fork 87
/
sms_tests.js
75 lines (66 loc) · 2.76 KB
/
sms_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
// intentionally initialize later so that we can debug tests after
// they fail without trying to recreate a user with the same phone
// address
var phone1;
var code;
Accounts._isolateLoginTokenForTest();
testAsyncMulti("accounts sms - verification flow", [
function (test, expect) {
phone1 = '+97254580'+ (Math.abs(Math.floor(Math.random() * 1000 - 1000)) + 1000);
Accounts.createUserWithPhone({phone: phone1, password: 'foobar'},
expect(function (error) {
test.equal(error, undefined);
test.isFalse(Accounts.isPhoneVerified(), 'User phone should not be verified');
}));
},
function (test, expect) {
Accounts.requestPhoneVerification(phone1, expect(function (error) {
test.equal(error, undefined);
test.isFalse(Accounts.isPhoneVerified(), 'User phone should not be verified');
}));
},
function (test, expect) {
Accounts.connection.call(
"getInterceptedSMS", phone1, expect(function (error, result) {
test.equal(error, undefined);
test.notEqual(result, undefined);
test.isFalse(Accounts.isPhoneVerified(), 'User phone should not be verified');
test.equal(result.length, 2); // the first is the phone verification
var options = result[1];
var re = new RegExp("Welcome your invitation code is: (.*)")
test.notEqual(null, options.body);
var match = options.body.match(re);
test.equal(phone1, options.to);
test.notEqual(null, options.from);
code = match[1];
}));
},
function (test, expect) {
Accounts.verifyPhone(phone1, code, "newPassword", expect(function(error) {
test.isFalse(error);
test.isTrue(Accounts.isPhoneVerified(), 'User phone should be verified');
}));
},
function (test, expect) {
Meteor.logout(expect(function (error) {
test.equal(error, undefined);
test.equal(Meteor.user(), null);
test.isFalse(Accounts.isPhoneVerified(), 'User phone should not be verified');
}));
},
function (test, expect) {
Meteor.loginWithPhoneAndPassword(
{phone: phone1}, "newPassword",
expect(function (error) {
test.isFalse(error);
test.isTrue(Accounts.isPhoneVerified(), 'User phone should be verified');
}));
},
function (test, expect) {
Meteor.logout(expect(function (error) {
test.equal(error, undefined);
test.equal(Meteor.user(), null);
test.isFalse(Accounts.isPhoneVerified(), 'User phone should not be verified');
}));
}
]);