|
1
|
|
|
var chai = require('chai') |
|
2
|
|
|
var server = require('../app') |
|
3
|
|
|
/* eslint-disable no-unused-vars */ |
|
4
|
|
|
var should = chai.should() |
|
5
|
|
|
var nock = require('nock') |
|
6
|
|
|
|
|
7
|
|
|
describe('Test SMS API', function () { |
|
8
|
|
|
|
|
9
|
|
|
it('it should send an sms', function (done) { |
|
10
|
|
|
nock('https://www.my-cool-sms.com') |
|
11
|
|
|
.get('/api-socket.php') |
|
12
|
|
|
.reply(200, { |
|
13
|
|
|
"success": true, |
|
14
|
|
|
"smsid": "ce184cc0a6d1714d1ac763f4fe89f521", |
|
15
|
|
|
"body": "Have a nice day!", |
|
16
|
|
|
"bodyucs2": "0048006100760065002000610020006E00690063006500200064", |
|
17
|
|
|
"bodygsm7": "486176652061206E6963652064617921", |
|
18
|
|
|
"number": "+491234567890", |
|
19
|
|
|
"senderid": "+449876543210", |
|
20
|
|
|
"senderidenabled": true, |
|
21
|
|
|
"unicode": false, |
|
22
|
|
|
"numchars": 321, |
|
23
|
|
|
"escapenumchars": 0, |
|
24
|
|
|
"smscount": 3, |
|
25
|
|
|
"charge": 0.112, |
|
26
|
|
|
"balance": 752.121, |
|
27
|
|
|
"countrycode": "IE", |
|
28
|
|
|
"prefix": "+353", |
|
29
|
|
|
"timestamp": "2017-04-02T22:27:22-07:00", |
|
30
|
|
|
"callbackurl": "https://www.groganburners.ie/api/sms/callback" |
|
31
|
|
|
}) |
|
32
|
|
|
|
|
33
|
|
|
var mail = { |
|
34
|
|
|
number: '+353873791474', |
|
35
|
|
|
message: 'Hello' |
|
36
|
|
|
} |
|
37
|
|
|
chai.request(server) |
|
38
|
|
|
.post('/api/sms') |
|
39
|
|
|
.send(mail) |
|
40
|
|
|
.end(function (err, res) { |
|
41
|
|
|
should.not.exist(err) |
|
42
|
|
|
res.should.have.status(200) |
|
43
|
|
|
res.body.should.be.a('object') |
|
44
|
|
|
res.body.should.have.property('message').eql('Message sent') |
|
45
|
|
|
nock.cleanAll() |
|
46
|
|
|
done() |
|
47
|
|
|
}) |
|
48
|
|
|
}) |
|
49
|
|
|
|
|
50
|
|
|
it('it should fail to send an sms to invalid number', function (done) { |
|
51
|
|
|
nock('https://www.my-cool-sms.com') |
|
52
|
|
|
.get('/api-socket.php') |
|
53
|
|
|
.reply(200, { |
|
54
|
|
|
success: false, |
|
55
|
|
|
errorcode: "210", |
|
56
|
|
|
description: "The number seems to be invalid" |
|
57
|
|
|
}) |
|
58
|
|
|
var mail = { |
|
59
|
|
|
number: '+35386', |
|
60
|
|
|
message: 'Hello' |
|
61
|
|
|
} |
|
62
|
|
|
chai.request(server) |
|
63
|
|
|
.post('/api/sms') |
|
64
|
|
|
.send(mail) |
|
65
|
|
|
.end(function (err, res) { |
|
66
|
|
|
should.exist(err) |
|
67
|
|
|
res.should.have.status(404) |
|
68
|
|
|
res.body.should.be.a('object') |
|
69
|
|
|
res.body.should.have.property('message').eql('Error creating message') |
|
70
|
|
|
nock.cleanAll() |
|
71
|
|
|
done() |
|
72
|
|
|
}) |
|
73
|
|
|
}) |
|
74
|
|
|
}) |
|
75
|
|
|
|