Skip to content

Commit

Permalink
Merge pull request #4402 from NMDSdevopsServiceAdm/feat/parentRequest…
Browse files Browse the repository at this point in the history
…sMainPage

Feat: Parent requests - main page
  • Loading branch information
joannafawl authored Dec 17, 2021
2 parents a647faf + 728d473 commit bb513a8
Show file tree
Hide file tree
Showing 14 changed files with 417 additions and 150 deletions.
7 changes: 3 additions & 4 deletions server/routes/admin/parent-approval/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const express = require('express');
const router = express.Router();
const models = require('../../../models');
const moment = require('moment-timezone');
const config = require('../../../config/config');
const notifications = require('../../../data/notifications');
const uuid = require('uuid');

Expand All @@ -11,7 +9,7 @@ const parentRejectionConfirmation = 'Parent request rejected';

const getParentRequests = async (req, res) => {
try {
let approvalResults = await models.Approvals.findAllPending('BecomeAParent');
let approvalResults = await models.Approvals.findAllPendingAndInProgress('BecomeAParent');
let parentRequests = await _mapResults(approvalResults);
return res.status(200).json(parentRequests);
} catch (error) {
Expand Down Expand Up @@ -44,7 +42,8 @@ const _mapResults = async (approvalResults) => {
workplaceId: approval.Establishment.nmdsId,
userName: approval.User.FullNameValue,
orgName: approval.Establishment.NameValue,
requested: moment.utc(approval.createdAt).tz(config.get('timezone')).format('D/M/YYYY h:mma'),
requested: approval.createdAt,
status: approval.Status,
};
});
};
Expand Down
71 changes: 23 additions & 48 deletions server/test/unit/routes/admin/cqc-status-change/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,25 @@ const sinon = require('sinon');
const sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);
const moment = require('moment-timezone');
const config = require('../../../../../config/config');
const httpsMocks = require('node-mocks-http');
const Sequelize = require('sequelize');

const models = require('../../../../../models/index');
const mainServiceRouter = require('../../../../../routes/establishments/mainService');

const cqcStatusChange = require('../../../../../routes/admin/cqc-status-change');
const sb = sinon.createSandbox();
var testWorkplace = {};

var workplaceObjectWasSaved = false;
const _initialiseTestWorkplace = () => {
testWorkplace.id = 4321;
testWorkplace.isRegulated = false;
testWorkplace.MainServiceFKValue = 1;
testWorkplace.nmdsId = 'I1234567';
testWorkplace.NameValue = faker.lorem.words(4);
testWorkplace.save = () => {
workplaceObjectWasSaved = true;
};
var testWorkplace = {
id: 4321,
isRegulated: false,
MainServiceFKValue: 1,
nmdsId: 'I1234567',
NameValue: faker.lorem.words(4),
save: () => {
return (workplaceObjectWasSaved = true);
},
};

var testUser = {};
const _initialiseTestUser = () => {
testUser.id = 1234;
var testUser = {
id: 1234,
};

var approvalObjectWasSaved = false;
Expand Down Expand Up @@ -65,12 +58,11 @@ var fakeApproval = {
},
};

var approvalRequestBody = {};
const _initialiseTestRequestBody = () => {
approvalRequestBody.approvalId = fakeApproval.ID;
approvalRequestBody.establishmentId = testWorkplace.id;
approvalRequestBody.userId = testUser.id;
approvalRequestBody.rejectionReason = 'Because I felt like it.';
var approvalRequestBody = {
approvalId: fakeApproval.ID,
establishmentId: testWorkplace.id,
userId: testUser.id,
rejectionReason: 'Because I felt like it.',
};

var returnedJson = null;
Expand All @@ -85,59 +77,41 @@ const approvalStatus = (status) => {
send: () => {},
};
};
var changeMainService;
var throwErrorWhenFetchingAllRequests = false;
var throwErrorWhenFetchingSingleRequest = false;

describe.skip('admin/cqc-status-change route', () => {
afterEach(() => {
sb.restore();
sinon.restore();
});

beforeEach(async () => {
sb.stub(models.Approvals, 'findAllPending').callsFake(async (approvalType) => {
sinon.stub(models.Approvals, 'findAllPending').callsFake(async () => {
if (throwErrorWhenFetchingAllRequests) {
throw 'Oopsy! findAllPending throwing error.';
} else {
return [fakeApproval];
}
});
changeMainService = sb.stub(mainServiceRouter, 'changeMainService').callsFake(async (approvalType) => {
if (throwErrorWhenFetchingSingleRequest) {
return { success: false, errorCode: '400', errorMsg: 'error' };
} else {
return { success: true, fakeApproval };
}
});

sb.stub(models.Approvals, 'findbyId').callsFake(async (id) => {
sinon.stub(models.Approvals, 'findbyId').callsFake(async (id) => {
if (throwErrorWhenFetchingSingleRequest) {
throw 'Oopsy! findbyId throwing error.';
} else if (id === fakeApproval.ID) {
return fakeApproval;
}
});

sb.stub(models.establishment, 'findbyId').callsFake(async (id) => {
if (id === testWorkplace.id) {
return testWorkplace;
}
});

sb.stub(models.establishment, 'findbyId').callsFake(async (id) => {
sinon.stub(models.establishment, 'findbyId').callsFake(async (id) => {
if (id === testWorkplace.id) {
return testWorkplace;
}
});

_initialiseTestWorkplace();
_initialiseTestUser();
_initialiseTestRequestBody();
returnedJson = null;
returnedStatus = null;
throwErrorWhenFetchingAllRequests = false;
throwErrorWhenFetchingSingleRequest = false;
noMatchingRequestByEstablishmentId = false;
});

describe('fetching CQC Status Approval', () => {
Expand All @@ -159,7 +133,8 @@ describe.skip('admin/cqc-status-change route', () => {
workplaceId: fakeApproval.Establishment.nmdsId,
username: fakeApproval.User.FullNameValue,
orgName: fakeApproval.Establishment.NameValue,
requested: moment.utc(fakeApproval.createdAt).tz(config.get('timezone')).format('D/M/YYYY h:mma'),
requested: fakeApproval.createdAt,
status: 'Pending',
data: {
currentService: {
ID: fakeApproval.Data.currentService.id,
Expand Down
Loading

0 comments on commit bb513a8

Please sign in to comment.