-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from Cavdy/ft-view-accounts-by-a-user-165436828
#165436828 view accounts by a user with email
- Loading branch information
Showing
7 changed files
with
152 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,85 @@ | ||
// /* eslint-disable no-undef */ | ||
// import chaiHttp from 'chai-http'; | ||
// import chai, { expect } from 'chai'; | ||
/* eslint-disable no-undef */ | ||
import chaiHttp from 'chai-http'; | ||
import chai, { expect } from 'chai'; | ||
import dbConnection from '../config/database'; | ||
|
||
// import app from '../app'; | ||
import app from '../app'; | ||
|
||
// chai.use(chaiHttp); | ||
chai.use(chaiHttp); | ||
|
||
// describe('Testing All Users Controller', () => { | ||
// describe('Testing all accounts controller', () => { | ||
// it( | ||
// 'users should have all required details', | ||
// (done) => { | ||
// const signinUrl = '/api/auth/signin'; | ||
// chai.request(app) | ||
// .post(signinUrl) | ||
// .send({ | ||
// email: 'banka3@banka.com', | ||
// password: 'passworD3@', | ||
// }) | ||
// .end((error, response) => { | ||
// const { token } = response.body.data; | ||
// chai.request(app) | ||
// .get('/api/v1/users') | ||
// .set('Authorization', `Bearer ${token}`) | ||
// .send() | ||
// .end((err, res) => { | ||
// expect(res.body).to.be.an('object'); | ||
// expect(res.body.status).to.equal('success'); | ||
// expect(res.body.data[0]).to.have.property('id'); | ||
// expect(res.body.data[0]).to.have.property('firstName'); | ||
// expect(res.body.data[0]).to.have.property('lastName'); | ||
// expect(res.body.data[0]).to.have.property('email'); | ||
// expect(res.body.data[0]).to.have.property('password'); | ||
// expect(res.body.data[0]).to.have.property('type'); | ||
// expect(res.body.data[0]).to.have.property('isAdmin'); | ||
// }); | ||
// done(); | ||
// }); | ||
// }, | ||
// ); | ||
describe('Testing All Users Controller', () => { | ||
before(async () => { | ||
await dbConnection | ||
.dbConnect('INSERT into users(email, firstName, lastName, password, type, isAdmin) values($1, $2, $3, $4, $5, $6)', ['staff@banka.com', 'cavdy', 'ikenna', '$2a$10$CmmIst1.D3QjaWuafKbBaOuAFu0r9o7xxQY.0SMKiAN.h9z52a2y2', 'staff', false]); | ||
}); | ||
describe('Testing all accounts controller', () => { | ||
it( | ||
'users should have all required details', | ||
async () => { | ||
const signinUrl = '/api/auth/signin'; | ||
const response = await chai.request(app) | ||
.post(signinUrl) | ||
.send({ | ||
email: 'admin@banka.com', | ||
password: 'passworD4@', | ||
}); | ||
const { token } = response.body.data[0]; | ||
const res = await chai.request(app) | ||
.get('/api/v1/users') | ||
.set('Authorization', `Bearer ${token}`) | ||
.send(); | ||
expect(res.body).to.be.an('object'); | ||
expect(res.body.status).to.equal('success'); | ||
expect(res.body.data[0]).to.have.property('id'); | ||
expect(res.body.data[0]).to.have.property('firstname'); | ||
expect(res.body.data[0]).to.have.property('lastname'); | ||
expect(res.body.data[0]).to.have.property('email'); | ||
expect(res.body.data[0]).to.have.property('password'); | ||
expect(res.body.data[0]).to.have.property('type'); | ||
expect(res.body.data[0]).to.have.property('isadmin'); | ||
}, | ||
); | ||
|
||
// it( | ||
// 'only staffs and admin can view all users', | ||
// (done) => { | ||
// const signinUrl = '/api/auth/signin'; | ||
// chai.request(app) | ||
// .post(signinUrl) | ||
// .send({ | ||
// email: 'banka@banka.com', | ||
// password: 'passworD1@', | ||
// }) | ||
// .end((error, response) => { | ||
// const { token } = response.body.data; | ||
// chai.request(app) | ||
// .get('/api/v1/users') | ||
// .set('Authorization', `Bearer ${token}`) | ||
// .send() | ||
// .end((err, res) => { | ||
// expect(res.body).to.be.an('object'); | ||
// expect(res.body.status).to.equal('success'); | ||
// expect(res.body.data).to.equal('You don\'t have permission to view this page'); | ||
// }); | ||
// done(); | ||
// }); | ||
// }, | ||
// ); | ||
it( | ||
'should not see all users if not admin or staff', | ||
async () => { | ||
const signinUrl = '/api/auth/signin'; | ||
const response = await chai.request(app) | ||
.post(signinUrl) | ||
.send({ | ||
email: 'banka872@banka4.com', | ||
password: 'passworD4@', | ||
}); | ||
const { token } = response.body.data[0]; | ||
const res = await chai.request(app) | ||
.get('/api/v1/users') | ||
.set('Authorization', `Bearer ${token}`) | ||
.send(); | ||
expect(res.body).to.be.an('object'); | ||
expect(res.body.status).to.equal('success'); | ||
expect(res.body.data).to.equal('You don\'t have permission to view this page'); | ||
}, | ||
); | ||
|
||
// it( | ||
// 'only staffs and admin can delete users', | ||
// (done) => { | ||
// const signinUrl = '/api/auth/signin'; | ||
// chai.request(app) | ||
// .post(signinUrl) | ||
// .send({ | ||
// email: 'banka@banka.com', | ||
// password: 'passworD1@', | ||
// }) | ||
// .end((error, response) => { | ||
// const { token } = response.body.data; | ||
// chai.request(app) | ||
// .delete('/api/v1/users/1') | ||
// .set('Authorization', `Bearer ${token}`) | ||
// .send() | ||
// .end((err, res) => { | ||
// expect(res.body).to.be.an('object'); | ||
// expect(res.body.status).to.equal('success'); | ||
// expect(res.body.data).to.equal('You don\'t have permission to do this task'); | ||
// }); | ||
// done(); | ||
// }); | ||
// }, | ||
// ); | ||
|
||
// it( | ||
// 'only admin can delete staffs', | ||
// (done) => { | ||
// const signinUrl = '/api/auth/signin'; | ||
// chai.request(app) | ||
// .post(signinUrl) | ||
// .send({ | ||
// email: 'banka2@banka.com', | ||
// password: 'passworD2@', | ||
// }) | ||
// .end((error, response) => { | ||
// const { token } = response.body.data; | ||
// chai.request(app) | ||
// .delete('/api/v1/users/2') | ||
// .set('Authorization', `Bearer ${token}`) | ||
// .send() | ||
// .end((err, res) => { | ||
// expect(res.body).to.be.an('object'); | ||
// expect(res.body.status).to.equal('success'); | ||
// expect(res.body.data).to.equal('Sorry you can not delete a staff'); | ||
// }); | ||
// done(); | ||
// }); | ||
// }, | ||
// ); | ||
// }); | ||
// }); | ||
it( | ||
'only staffs and admin can delete users', | ||
async () => { | ||
const signinUrl = '/api/auth/signin'; | ||
const response = await chai.request(app) | ||
.post(signinUrl) | ||
.send({ | ||
email: 'banka872@banka4.com', | ||
password: 'passworD4@', | ||
}); | ||
const { id, token } = response.body.data[0]; | ||
const res = await chai.request(app) | ||
.delete(`/api/v1/users/${id}`) | ||
.set('Authorization', `Bearer ${token}`) | ||
.send(); | ||
expect(res.body).to.be.an('object'); | ||
expect(res.body.status).to.equal('success'); | ||
expect(res.body.data).to.equal('You don\'t have permission to view this page'); | ||
}, | ||
); | ||
}); | ||
}); |