From 2972be12a92ef3ddbe0d2cd04763f235a27a6cb2 Mon Sep 17 00:00:00 2001 From: Tolulope Odueke Date: Sat, 20 Apr 2019 21:46:56 +0100 Subject: [PATCH] feature(endpoint):fetch all dormant accounts Create endpoint for admins to get all dormant accounts [Finishes #165448156] --- server/validation/accountValidation.js | 4 +++- test/account.test.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/server/validation/accountValidation.js b/server/validation/accountValidation.js index e769567..3fffa16 100644 --- a/server/validation/accountValidation.js +++ b/server/validation/accountValidation.js @@ -135,7 +135,9 @@ export default class AccountValidation { }); } - if (req.query.status !== 'active') { + const { status } = req.query; + + if (status !== 'active' && status !== 'dormant') { return res.status(400).json({ status: 400, error: 'Account status must be either active or dormant' diff --git a/test/account.test.js b/test/account.test.js index fb473d4..dae6f54 100644 --- a/test/account.test.js +++ b/test/account.test.js @@ -195,6 +195,21 @@ describe('Account Route', () => { }); }); + it('Should fetch all dormant accounts under the bank for an authorized staff', done => { + chai + .request(app) + .get(`${API_PREFIX}/accounts?status=dormant`) + .set('Authorization', staffAuthToken) + .end((err, res) => { + expect(res.body) + .to.have.property('status') + .eql(200); + expect(res.body).to.have.property('data'); + expect(res.status).to.equal(200); + done(); + }); + }); + it('Should not fetch accounts by their status if a user requests it', done => { chai .request(app)