Skip to content

Commit 6f02a27

Browse files
authored
Merge pull request #136 from adhocteam/js-collaborators-feedback
Address PR feedback
2 parents abc9932 + da1521c commit 6f02a27

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

docs/openapi/index.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ components:
109109
type: string
110110
selectableUser:
111111
type: object
112-
description: Users with permission to approve reports
112+
description: >
113+
Users with only their id and name, ready to be placed in a select box on the frontend without
114+
further modification
113115
properties:
114116
id:
115117
type: number

frontend/src/fetchers/activityReports.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { get, put, post } from './index';
33

44
const activityReportUrl = join('/', 'api', 'activity-reports');
55

6-
export const fetchApprovers = async (region) => {
6+
export const getApprovers = async (region) => {
77
const res = await get(join(activityReportUrl, 'approvers', `?region=${region}`));
88
return res.json();
99
};

frontend/src/pages/ActivityReport/constants.js

-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ export const targetPopulations = [
5454
'Pregnant Women',
5555
];
5656

57-
export const otherUsers = [
58-
'User 1',
59-
'User 2',
60-
'User 3',
61-
];
62-
6357
export const programTypes = [
6458
'program type 1',
6559
'program type 2',

frontend/src/pages/ActivityReport/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
getRecipients,
2222
createReport,
2323
getCollaborators,
24-
fetchApprovers,
24+
getApprovers,
2525
} from '../../fetchers/activityReports';
2626

2727
const defaultValues = {
@@ -34,7 +34,6 @@ const defaultValues = {
3434
endDate: null,
3535
grantees: [],
3636
numberOfParticipants: '',
37-
otherUsers: [],
3837
participantCategory: '',
3938
participants: [],
4039
programTypes: [],
@@ -71,7 +70,7 @@ function ActivityReport({ match }) {
7170
const apiCalls = [
7271
getRecipients(),
7372
getCollaborators(region),
74-
fetchApprovers(region),
73+
getApprovers(region),
7574
];
7675

7776
if (activityReportId !== 'new') {

src/routes/activityReports/handlers.test.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jest.mock('../../services/users', () => ({
1616
usersWithPermissions: jest.fn(),
1717
}));
1818

19+
jest.mock('../../policies/activityReport');
20+
1921
const mockResponse = {
2022
json: jest.fn(),
2123
sendStatus: jest.fn(),
@@ -49,7 +51,9 @@ describe('Activity Report handlers', () => {
4951
};
5052

5153
it('returns the report', async () => {
52-
ActivityReport.prototype.canUpdate = jest.fn().mockReturnValue(true);
54+
ActivityReport.mockImplementationOnce(() => ({
55+
canUpdate: () => true,
56+
}));
5357
createOrUpdate.mockResolvedValue(report);
5458
userById.mockResolvedValue({
5559
id: 1,
@@ -59,7 +63,9 @@ describe('Activity Report handlers', () => {
5963
});
6064

6165
it('handles unauthorizedRequests', async () => {
62-
ActivityReport.prototype.canUpdate = jest.fn().mockReturnValue(false);
66+
ActivityReport.mockImplementationOnce(() => ({
67+
canUpdate: () => false,
68+
}));
6369
activityReportById.mockResolvedValue(report);
6470
userById.mockResolvedValue({
6571
id: 1,
@@ -77,7 +83,9 @@ describe('Activity Report handlers', () => {
7783
};
7884

7985
it('returns the created report', async () => {
80-
ActivityReport.prototype.canCreate = jest.fn().mockReturnValue(true);
86+
ActivityReport.mockImplementationOnce(() => ({
87+
canCreate: () => true,
88+
}));
8189
createOrUpdate.mockResolvedValue(report);
8290
userById.mockResolvedValue({
8391
id: 1,
@@ -93,7 +101,9 @@ describe('Activity Report handlers', () => {
93101
});
94102

95103
it('handles unauthorized requests', async () => {
96-
ActivityReport.prototype.canCreate = jest.fn().mockReturnValue(false);
104+
ActivityReport.mockImplementationOnce(() => ({
105+
canCreate: () => false,
106+
}));
97107
userById.mockResolvedValue({
98108
id: 1,
99109
});
@@ -110,7 +120,9 @@ describe('Activity Report handlers', () => {
110120
};
111121

112122
it('returns the updated report', async () => {
113-
ActivityReport.prototype.canUpdate = jest.fn().mockReturnValue(true);
123+
ActivityReport.mockImplementationOnce(() => ({
124+
canUpdate: () => true,
125+
}));
114126
activityReportById.mockResolvedValue(report);
115127
createOrUpdate.mockResolvedValue(report);
116128
userById.mockResolvedValue({
@@ -122,7 +134,9 @@ describe('Activity Report handlers', () => {
122134

123135
it('handles unauthorized requests', async () => {
124136
activityReportById.mockResolvedValue(report);
125-
ActivityReport.prototype.canUpdate = jest.fn().mockReturnValue(false);
137+
ActivityReport.mockImplementationOnce(() => ({
138+
canUpdate: () => false,
139+
}));
126140
userById.mockResolvedValue({
127141
id: 1,
128142
});
@@ -150,6 +164,9 @@ describe('Activity Report handlers', () => {
150164
};
151165

152166
it('returns the report', async () => {
167+
ActivityReport.mockImplementationOnce(() => ({
168+
canGet: () => true,
169+
}));
153170
activityReportById.mockResolvedValue(report);
154171
userById.mockResolvedValue({
155172
id: 1,
@@ -167,7 +184,9 @@ describe('Activity Report handlers', () => {
167184

168185
it('handles unauthorized requests', async () => {
169186
activityReportById.mockResolvedValue(report);
170-
ActivityReport.prototype.canGet = jest.fn().mockReturnValue(false);
187+
ActivityReport.mockImplementationOnce(() => ({
188+
canGet: () => false,
189+
}));
171190
await getReport(request, mockResponse);
172191
expect(mockResponse.sendStatus).toHaveBeenCalledWith(403);
173192
});

0 commit comments

Comments
 (0)