You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rap2-delos/test/test.account.js

108 lines
3.0 KiB
JavaScript

7 years ago
/* global describe, it */
7 years ago
const app = require('../dist/scripts/app').default
7 years ago
const request = require('supertest').agent(app.listen())
const should = require('chai').should()
const Random = require('mockjs').Random
describe('Account', () => {
let user = { fullname: Random.cname(), email: Random.email(), password: Random.word(6) }
let validUser = (user) => {
user.should.be.a('object').have.all.keys(['id', 'fullname', 'email'])
}
let validUserForSearch = (user) => {
7 years ago
user.should.be.a('object').have.all.keys(['id', 'fullname', 'email'])
}
7 years ago
let validPagination = (pagination) => {
pagination.should.be.a('object').contain.all.keys(['cursor', 'limit', 'total'])
}
it('/account/register', (done) => {
request.post('/account/register')
.send(user)
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
console.log(err)
should.not.exist(err)
validUser(res.body.data)
user.id = res.body.data.id
done()
})
})
it('/account/count', (done) => {
request.get('/account/count')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
should.not.exist(err)
res.body.data.should.to.be.a('number').above(0)
done()
})
})
it('/account/list', (done) => {
request.get('/account/list')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
should.not.exist(err)
let { data, pagination } = res.body
data.should.be.a('array').have.length.above(0)
data.forEach(item => {
validUserForSearch(item)
7 years ago
})
validPagination(pagination)
done()
})
})
it('/account/login', done => {
request.post('/account/login')
.send({ email: user.email, password: user.password })
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
should.not.exist(err)
validUser(res.body.data)
done()
})
})
it('/account/info', done => {
request.get('/account/info')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
should.not.exist(err)
validUser(res.body.data)
done()
})
})
it('/account/logout', done => {
request.get('/account/logout')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
should.not.exist(err)
res.body.data.should.be.a('object').have.all.keys({ id: user.id })
done()
})
})
it('/account/info', done => {
request.get('/account/info')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
should.not.exist(err)
should.not.exist(res.body.data)
done()
})
})
it('/account/remove', (done) => {
request.get('/account/remove')
.query({ id: user.id })
.expect(200)
.end((err, res) => {
should.not.exist(err)
res.body.data.should.eq(1)
done()
})
})
})