mirror of
https://github.com/mmumshad/ansible-playable.git
synced 2025-03-09 23:38:54 +00:00
Initial Commit
This commit is contained in:
commit
c92f737237
273 changed files with 16964 additions and 0 deletions
67
server/api/user/user.integration.js
Normal file
67
server/api/user/user.integration.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
'use strict';
|
||||
|
||||
/* globals describe, expect, it, before, after, beforeEach, afterEach */
|
||||
|
||||
import app from '../..';
|
||||
import User from './user.model';
|
||||
import request from 'supertest';
|
||||
|
||||
describe('User API:', function() {
|
||||
var user;
|
||||
|
||||
// Clear users before testing
|
||||
before(function() {
|
||||
return User.remove().then(function() {
|
||||
user = new User({
|
||||
name: 'Fake User',
|
||||
email: 'test@example.com',
|
||||
password: 'password'
|
||||
});
|
||||
|
||||
return user.save();
|
||||
});
|
||||
});
|
||||
|
||||
// Clear users after testing
|
||||
after(function() {
|
||||
return User.remove();
|
||||
});
|
||||
|
||||
describe('GET /api/users/me', function() {
|
||||
var token;
|
||||
|
||||
before(function(done) {
|
||||
request(app)
|
||||
.post('/auth/local')
|
||||
.send({
|
||||
email: 'test@example.com',
|
||||
password: 'password'
|
||||
})
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.end((err, res) => {
|
||||
token = res.body.token;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should respond with a user profile when authenticated', function(done) {
|
||||
request(app)
|
||||
.get('/api/users/me')
|
||||
.set('authorization', `Bearer ${token}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.end((err, res) => {
|
||||
expect(res.body._id.toString()).to.equal(user._id.toString());
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should respond with a 401 when not authenticated', function(done) {
|
||||
request(app)
|
||||
.get('/api/users/me')
|
||||
.expect(401)
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue