Completed
Push — master ( 7c2271...f13ae1 )
by Neil
01:30
created

sms.js ➔ describe(ꞌTest SMS APIꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 68

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
nc 1
dl 0
loc 68
rs 9.2447
nop 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B sms.js ➔ ... ➔ it(ꞌit should fail to send an sms to invalid numberꞌ) 0 24 1
B sms.js ➔ ... ➔ it(ꞌit should send an smsꞌ) 0 40 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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