Completed
Push — master ( 2d8abe...e6d75a )
by Neil
03:16
created

email.js ➔ describe(ꞌTest Email APIꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 50
rs 9.3333

1 Function

Rating   Name   Duplication   Size   Complexity  
A email.js ➔ ... ➔ it(ꞌit should send an emailꞌ) 0 23 1
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
var nodemailer = require('nodemailer')
7
var sinon = require('sinon')
8
var expect = require('chai').expect
9
10
describe('Test Email API', function () {
11
  it('it should send an email', function (done) {
12
    var transportStub = { sendMail: function (options, callback) { callback(false, true) } }
13
    var sendMailSpy = sinon.spy(transportStub, 'sendMail')
0 ignored issues
show
Unused Code introduced by
The variable sendMailSpy seems to be never used. Consider removing it.
Loading history...
14
    var mailerStub = sinon.stub(nodemailer, 'createTransport').returns(transportStub)
15
16
    var mail = {
17
      to: '[email protected]',
18
      subject: 'Hello ✔',
19
      text: 'Hello world 🐴',
20
      html: '<b>Hello world 🐴</b>'
21
    }
22
    chai.request(server)
23
      .post('/api/email')
24
      .send(mail)
25
      .end(function (err, res) {
26
        should.not.exist(err)
27
        res.should.have.status(200)
28
        res.body.should.be.a('object')
29
        res.body.should.have.property('message').eql('Message sent')
30
        mailerStub.restore()
31
        done()
32
      })
33
  })
34
35
36
  it('it should send an email', function (done) {
37
    var transportStub = { sendMail: function (options, callback) { callback(true, false) } }
38
    var sendMailSpy = sinon.spy(transportStub, 'sendMail')
0 ignored issues
show
Unused Code introduced by
The variable sendMailSpy seems to be never used. Consider removing it.
Loading history...
39
    var mailerStub = sinon.stub(nodemailer, 'createTransport').returns(transportStub)
40
41
    var mail = {
42
      to: '[email protected]',
43
      subject: 'Hello ✔',
44
      text: 'Hello world 🐴',
45
      html: '<b>Hello world 🐴</b>'
46
    }
47
    chai.request(server)
48
      .post('/api/email')
49
      .send(mail)
50
      .end(function (err, res) {
51
        should.exist(err)
52
        res.should.have.status(404)
53
        res.body.should.be.a('object')
54
        res.body.should.have.property('message').eql('Error creating message')
55
        mailerStub.restore()
56
        done()
57
      })
58
  })
59
})
60