-
Notifications
You must be signed in to change notification settings - Fork 1
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 #56 from andela/ft-get-all-status-170267352
#170267352 Get all status types
- Loading branch information
Showing
5 changed files
with
146 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Response from '../helpers/Response'; | ||
import StatusService from '../services/StatusService'; | ||
|
||
|
||
const { getStatus } = StatusService; | ||
/** | ||
* @exports | ||
* @class StatusController | ||
*/ | ||
class StatusController { | ||
/** | ||
* Get all status types | ||
* @static | ||
* @param {object} req request object | ||
* @param {object} res response object | ||
* @memberof SearchController | ||
* @returns {object} data | ||
*/ | ||
static async getAllStatus(req, res) { | ||
const status = await getStatus(); | ||
return Response.successMessage(req, res, 'Successfully retrieved all status types', status, 200); | ||
} | ||
} | ||
export default StatusController; |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import express from 'express'; | ||
import verifyToken from '../../middlewares/verifyToken'; | ||
import isUserVerified from '../../middlewares/isUserVerified'; | ||
import StatusController from '../../controllers/StatusController'; | ||
|
||
const statusRoute = express.Router(); | ||
|
||
const { getAllStatus } = StatusController; | ||
|
||
/** | ||
* @swagger | ||
* | ||
* /status: | ||
* get: | ||
* summary: Get all status types | ||
* tags: [Status] | ||
* parameters: | ||
* - name: token | ||
* in: header | ||
* description: enter token | ||
* required: true | ||
* schema: | ||
* type: string | ||
* responses: | ||
* "200": | ||
* description: Status types retrieved successfully | ||
* "500": | ||
* description: Internal servor error | ||
*/ | ||
statusRoute | ||
.get('/', | ||
verifyToken, | ||
isUserVerified, | ||
getAllStatus); | ||
export default statusRoute; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { status } from '../database/models'; | ||
import CommonQueries from './CommonQueries'; | ||
|
||
|
||
/** | ||
* @exports | ||
* @class StatusService | ||
*/ | ||
class StatusService { | ||
/** | ||
* Get all status | ||
* @static | ||
* @description GET /api/v1/status | ||
* @param {object} req request object | ||
* @memberof SearchService | ||
* @returns {object} data | ||
*/ | ||
static async getStatus() { | ||
const queryObject = { | ||
attributes: ['id', 'status'] | ||
}; | ||
const allStatus = await CommonQueries.findAll(status, queryObject); | ||
return allStatus; | ||
} | ||
} | ||
|
||
export default StatusService; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import chai, { expect } from 'chai'; | ||
import chaiHttp from 'chai-http'; | ||
import dotenv from 'dotenv'; | ||
import app from '../index'; | ||
import mockData from './mock/mockData'; | ||
|
||
chai.use(chaiHttp); | ||
chai.should(); | ||
|
||
dotenv.config(); | ||
let userToken; | ||
|
||
describe('Get all Status types functionality tests', () => { | ||
before((done) => { | ||
chai.request(app) | ||
.post('/api/v1/auth/signin') | ||
.send(mockData.testUser) | ||
.end((err, res) => { | ||
userToken = res.body.data; | ||
|
||
done(err); | ||
}); | ||
}); | ||
|
||
before((done) => { | ||
chai.request(app) | ||
.get('/api/v1/status') | ||
.set('token', userToken) | ||
.send(mockData.usersSignin) | ||
.end(() => { | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should not provide any status if token is invalid', (done) => { | ||
chai.request(app) | ||
.get('/api/v1/status') | ||
.set('token', mockData.invalidToken) | ||
.end((err, res) => { | ||
expect(res.body.message.message).eql('jwt malformed'); | ||
res.should.have.status(401); | ||
res.body.should.be.an('object'); | ||
done(err); | ||
}); | ||
}); | ||
|
||
it('should get all status', (done) => { | ||
chai.request(app) | ||
.get('/api/v1/status') | ||
.set('token', userToken) | ||
.end((err, res) => { | ||
expect(res.body.message).eql('Successfully retrieved all status types'); | ||
res.should.have.status(200); | ||
res.body.should.be.an('object'); | ||
done(err); | ||
}); | ||
}); | ||
}); |