-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmixin-test.js
69 lines (60 loc) · 1.86 KB
/
mixin-test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict'
const path = require('path')
const request = require('supertest')
const chai = require('chai')
const { expect } = chai
chai.use(require('dirty-chai'))
chai.use(require('sinon-chai'))
require('mocha-sinon')
const SIMPLE_APP = path.join(__dirname, 'fixtures', 'simple-app')
const app = require(path.join(SIMPLE_APP, 'server/server.js'))
function json(verb, url, data) {
return request(app)[verb](url)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(data)
.expect('Content-Type', /json/)
}
/**
* Initialise the application for the test suite.
*/
before(done => {
function finishBoot() {
return done()
}
if (app.booting) {
return app.once('booted', finishBoot)
}
return finishBoot()
})
describe('Current User Mixin.', function() {
describe('Smoke test', function() {
it('should add a getCurrentUser model method', function() {
expect(app.models.user).itself.to.respondTo('getCurrentUser')
})
})
describe('Role: unauthenticated', function() {
it('should return null', function() {
return json('get', '/api/users/currentUser')
.expect(200)
.then(res => {
expect(res.body).to.be.null()
})
})
})
describe('Role: authenticated', function() {
it('should return the current user', function() {
return json('post', '/api/users/login')
.send({ username: 'generalUser', password: 'password' })
.expect(200)
.then(res => json('get', `/api/users/currentUser?access_token=${res.body.id}`)
.expect(200))
.then(res => {
expect(res.body).to.be.an('object')
expect(res.body).to.have.property('id', 'generalUser')
expect(res.body).to.have.property('username', 'generalUser')
expect(res.body).to.have.property('email', 'generalUser@fullcube.com')
})
})
})
})