diff options
Diffstat (limited to 'test/services/user/index.test.js')
| -rw-r--r-- | test/services/user/index.test.js | 96 |
1 files changed, 92 insertions, 4 deletions
diff --git a/test/services/user/index.test.js b/test/services/user/index.test.js index a43dcae..83dc105 100644 --- a/test/services/user/index.test.js +++ b/test/services/user/index.test.js @@ -1,10 +1,98 @@ 'use strict'; +const chai = require('chai') +const chaiHttp = require('chai-http') +const should = chai.should(); const assert = require('assert'); const app = require('../../../src/app'); -describe('user service', function() { +const User = app.service('users') +const authentication = require('feathers-authentication/client'); +const bodyParser = require('body-parser'); +var token, userid + +app + .use(bodyParser.json()) + .use(bodyParser.urlencoded({ extended: true })) + .configure(authentication()); +chai.use(chaiHttp); + + +describe('user service', () => { + before((done) => { + this.server = app.listen(3030) + this.server.once('listening', () => { + done() + }) + }) + + after((done) => { + this.server.close(function(){}) + done() + }) + it('registered the users service', () => { - assert.ok(app.service('users')); - }); -}); + assert.ok(app.service('users')) + }) + + it('should create a new user', (done) => { + chai.request(app) + .post('/users') + .set('Accept', 'application/json') + .send({ + email: 'test@test.com', + password: 'password', + goal: 2000, + }) + .end((err, res) => { + res.body.should.have.property('email') + res.body.email.should.equal('test@test.com') + res.body.should.not.have.property('password') + res.body.goal.should.equal(2000) + done() + }) + }) + + it('should authenticate a new user', (done) => { + chai.request(app) + .post('/auth/local') + .set('Accept', 'application/json') + .send({ + email: 'test@test.com', + password: 'password', + }) + .end((err, res) => { + res.body.should.have.property('token') + res.body.should.have.property('data') + res.body.data.should.have.property('id') + token = res.body.token + userid = res.body.data.id + done() + }) + }) + + it('user should be able to update itself', (done) => { + chai.request(app) + .patch('/users/'.concat(userid)) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer '.concat(token)) + .send({ + goal: 2500, + }) + .end((err, res) => { + done() + }) + }) + + it('user should be able to destroy itself', (done) => { + chai.request(app) + .delete('/users/'.concat(userid)) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer '.concat(token)) + .send() + .end((err, res) => { + done() + }) + }) + +}) |
