test/integration/auth.js   A
last analyzed

Complexity

Total Complexity 16
Complexity/F 1.07

Size

Lines of Code 96
Function Count 15

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 96
rs 10
wmc 16
mnd 1
bc 17
fnc 15
bpm 1.1333
cpm 1.0666
noi 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
B auth.js ➔ ??? 0 43 1
B auth.js ➔ describe(ꞌAuth logged outꞌ) 0 45 1
1
var chai = require('chai')
2
var server = require('../../app')
3
var expect = chai.expect
4
var nock = require('nock')
5
/* eslint-disable no-unused-vars */
6
var should = chai.should()
7
8
describe('Auth logged out', function () {
9
  it('login page loads correctly', function (done) {
10
    chai.request(server)
11
      .get('/auth/login')
12
      .end(function (err, res) {
13
        should.not.exist(err)
14
        res.should.have.status(200)
15
        done()
16
      })
17
  })
18
19
  it('Account page logged out redirects', (done) => {
20
    chai.request(server)
21
      .get('/auth/account').end(function (err, res) {
22
        should.not.exist(err)
23
        expect(res.redirects[0]).to.match(/\/auth\/login/)
24
        expect(res).to.redirect
0 ignored issues
show
introduced by
The result of the property access to expect(res).to.redirect is not used.
Loading history...
25
        done()
26
      })
27
  })
28
29
  it('google endpoint redirects', function (done) {
30
    chai.request(server)
31
      .get('/auth/google')
32
      .end(function (err, res) {
33
        should.exist(err)
34
        expect(res.redirects[0]).to.contain('https://accounts.google.com/o/oauth2/auth')
35
        expect(res).to.redirect
0 ignored issues
show
introduced by
The result of the property access to expect(res).to.redirect is not used.
Loading history...
36
        done()
37
      })
38
  })
39
40
  it('it should end the session and show login', function (done) {
41
    chai.request(server)
42
      .get('/auth/logout')
43
      .end(function (err, res) {
44
        should.not.exist(err)
45
        expect(res.redirects[0]).to.match(/\/$/)
46
        expect(res).to.redirect
0 ignored issues
show
introduced by
The result of the property access to expect(res).to.redirect is not used.
Loading history...
47
        // If successful layout displays Login links
48
        // TODO expect(res.text).to.match(/Contact/)
49
        done()
50
      })
51
  })
52
})
53
54
describe('GET /auth/google/callback', () => {
55
  beforeEach(function () {
56
    nock('https://accounts.google.com')
57
      .post('/o/oauth2/token')
58
      .reply(200, {
59
        access_token: 'test123828',
60
        token_type: 'Bearer',
61
        expires_in: 3600,
62
        refresh_token: 'test22912'
63
      })
64
    nock('https://www.googleapis.com')
65
      .get('/plus/v1/people/me')
66
      .query(true)
67
      .reply(200, {
68
        id: '1234567890',
69
        displayName: 'Test User',
70
        emails: ['[email protected]'],
71
        username: 'dueyfinster'
72
      })
73
  })
74
75
  afterEach(function () {
76
    nock.cleanAll()
77
  })
78
79
  it('Login works and shows account', (done) => {
80
    var agent = chai.request.agent(server)
81
    try {
82
      agent
83
        .get('/auth/google/callback?code=xxxxxxxx&authuser=0&session_state=xxxxxxxx&prompt=consent')
84
        .then(function (res) {
0 ignored issues
show
Unused Code introduced by
The parameter res is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
85
          return agent.get('/auth/account')
86
            .then(function (res) {
87
              res.should.have.status(200)
88
              res.text.should.include('Test User')
89
              done()
90
            })
91
        })
92
    } catch (error) {
93
      done(error)
94
    }
95
  })
96
})
97