-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathsms_tests_setup.js
46 lines (40 loc) · 1.37 KB
/
sms_tests_setup.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
//
// a mechanism to intercept emails sent to addressing including
// the string "intercept", storing them in an array that can then
// be retrieved using the getInterceptedSMS method
//
var interceptedSMS = {}; // (phone) -> (array of options)
var streamBuffers = Npm.require('stream-buffers');
var stream = new streamBuffers.WritableStreamBuffer;
SMSTest.overrideOutputStream(stream);
SMSTest.hookSend(function (options) {
// console.log('in1', options, options.to);
var to = options.to;
if (!to) {
return true; // go ahead and send
} else {
if (!interceptedSMS[to])
interceptedSMS[to] = [];
interceptedSMS[to].push(options);
return false; // skip sending
}
});
Meteor.methods({
getInterceptedSMS: function (phone) {
check(phone, String);
return interceptedSMS[phone];
},
addPhoneForTestAndVerify: function (phone) {
check(phone, String);
Meteor.users.update(
{_id: this.userId},
{$push: {phone: {number: phone, verified: false}}});
Accounts.sendPhoneVerificationCode(this.userId, phone);
},
createUserOnServer: function (phone) {
check(phone, String);
var userId = Accounts.createUserWithPhone({phone: phone});
Accounts.sendPhoneVerificationCode(this.userId, phone);
return Meteor.users.findOne(userId);
}
});