Skip to content

Commit 1855888

Browse files
AntBushccbc-service-account
authored andcommitted
chore: update tests and claims
1 parent 7dee52c commit 1855888

File tree

4 files changed

+98
-25
lines changed

4 files changed

+98
-25
lines changed

app/backend/lib/excel_import/claims.ts

+30-25
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const getDateRequestReceived = (
4141
let dateRequestReceived = null;
4242
firstTenRowLetters.forEach((letter) => {
4343
if (
44-
claimsRequestFormSheet[index][letter] !== null &&
45-
typeof claimsRequestFormSheet[index][letter] === 'number'
44+
claimsRequestFormSheet[index][letter] &&
45+
convertExcelDateToJSDate(claimsRequestFormSheet[index][letter])
4646
) {
4747
dateRequestReceived = claimsRequestFormSheet[index][letter];
4848
}
@@ -54,13 +54,12 @@ const getBcProjectNumber = (
5454
claimsRequestFormSheet: Array<any>,
5555
index: number
5656
) => {
57-
let bcProjectNumber = null;
57+
let bcProjectNumber;
5858
firstTenRowLetters.forEach((letter) => {
5959
if (
60-
claimsRequestFormSheet[index][letter]
61-
?.toLowerCase()
62-
?.trim()
63-
?.includes('ccbc')
60+
claimsRequestFormSheet[index][letter] &&
61+
typeof claimsRequestFormSheet[index][letter] === 'string' &&
62+
/^CCBC-\d{6}$/.test(claimsRequestFormSheet[index][letter].trim())
6463
) {
6564
bcProjectNumber = claimsRequestFormSheet[index][letter];
6665
}
@@ -75,7 +74,7 @@ const getIsedProjectNumber = (
7574
let isedProjectNumber = null;
7675
firstTenRowLetters.forEach((letter) => {
7776
if (
78-
claimsRequestFormSheet[index][letter] !== null &&
77+
claimsRequestFormSheet[index][letter] &&
7978
typeof claimsRequestFormSheet[index][letter] === 'number'
8079
) {
8180
isedProjectNumber = claimsRequestFormSheet[index][letter];
@@ -85,11 +84,12 @@ const getIsedProjectNumber = (
8584
};
8685

8786
const getClaimNumber = (claimsRequestFormSheet: Array<any>, index: number) => {
88-
let claimNumber = null;
87+
let claimNumber;
8988
firstTenRowLetters.forEach((letter) => {
9089
if (
91-
claimsRequestFormSheet[index][letter] !== null &&
92-
typeof claimsRequestFormSheet[index][letter] === 'number'
90+
claimsRequestFormSheet[index][letter] &&
91+
typeof claimsRequestFormSheet[index][letter] === 'number' &&
92+
!claimNumber
9393
) {
9494
claimNumber = claimsRequestFormSheet[index][letter];
9595
}
@@ -104,9 +104,11 @@ const getEligibleCostsIncurredFromDate = (
104104
let eligibleCostsIncurredFromDate = null;
105105
firstTenRowLetters.forEach((letter) => {
106106
if (
107-
claimsRequestFormSheet[index][letter] !== null &&
107+
claimsRequestFormSheet[index][letter] &&
108108
// excel date is of type number
109-
typeof claimsRequestFormSheet[index][letter] === 'number'
109+
typeof claimsRequestFormSheet[index][letter] === 'number' &&
110+
// we only want the first value since there are others after
111+
eligibleCostsIncurredFromDate === null
110112
) {
111113
eligibleCostsIncurredFromDate = claimsRequestFormSheet[index][letter];
112114
}
@@ -121,9 +123,11 @@ const getEligibleCostsIncurredToDate = (
121123
let eligibleCostsIncurredToDate = null;
122124
firstTenRowLetters.forEach((letter) => {
123125
if (
124-
claimsRequestFormSheet[index][letter] !== null &&
126+
claimsRequestFormSheet[index][letter] &&
125127
// excel date is of type number
126-
typeof claimsRequestFormSheet[index][letter] === 'number'
128+
typeof claimsRequestFormSheet[index][letter] === 'number' &&
129+
// we only want the first value since there are others after
130+
eligibleCostsIncurredToDate === null
127131
) {
128132
eligibleCostsIncurredToDate = claimsRequestFormSheet[index][letter];
129133
}
@@ -135,11 +139,12 @@ const getEligibleCostsIncurredToDate = (
135139

136140
const isValidProgressReportInput = (input) => {
137141
const validInputs = [
138-
'Please select',
139142
'Not Started',
140143
'In Progress',
141144
'Completed',
142145
'N/A',
146+
'Yes',
147+
'No',
143148
];
144149

145150
return (
@@ -158,7 +163,7 @@ const getProgressOnPermits = (
158163
let progressOnPermits = null;
159164
firstTenRowLetters.forEach((letter) => {
160165
if (
161-
progressReportSheet[index][letter] !== null &&
166+
progressReportSheet[index][letter] &&
162167
isValidProgressReportInput(progressReportSheet[index][letter])
163168
) {
164169
progressOnPermits = progressReportSheet[index][letter];
@@ -174,7 +179,7 @@ const getHasConstructionBegun = (
174179
let hasConstructionBegun = null;
175180
firstTenRowLetters.forEach((letter) => {
176181
if (
177-
progressReportSheet[index][letter] !== null &&
182+
progressReportSheet[index][letter] &&
178183
isValidProgressReportInput(progressReportSheet[index][letter])
179184
) {
180185
hasConstructionBegun = progressReportSheet[index][letter];
@@ -190,7 +195,7 @@ const getHaveServicesBeenOffered = (
190195
let haveServicesBeenOffered = null;
191196
firstTenRowLetters.forEach((letter) => {
192197
if (
193-
progressReportSheet[index][letter] !== null &&
198+
progressReportSheet[index][letter] &&
194199
isValidProgressReportInput(progressReportSheet[index][letter])
195200
) {
196201
haveServicesBeenOffered = progressReportSheet[index][letter];
@@ -206,7 +211,7 @@ const getProjectScheduleRisks = (
206211
let projectScheduleRisks = null;
207212
firstTenRowLetters.forEach((letter) => {
208213
if (
209-
progressReportSheet[index][letter] !== null &&
214+
progressReportSheet[index][letter] &&
210215
isValidProgressReportInput(progressReportSheet[index][letter])
211216
) {
212217
projectScheduleRisks = progressReportSheet[index][letter];
@@ -222,7 +227,7 @@ const getThirdPartyPassiveInfrastructure = (
222227
let thirdPartyPassiveInfrastructure = null;
223228
firstTenRowLetters.forEach((letter) => {
224229
if (
225-
progressReportSheet[index][letter] !== null &&
230+
progressReportSheet[index][letter] &&
226231
isValidProgressReportInput(progressReportSheet[index][letter])
227232
) {
228233
thirdPartyPassiveInfrastructure = progressReportSheet[index][letter];
@@ -238,7 +243,7 @@ const getCommunicationMaterials = (
238243
let communicationMaterials = null;
239244
firstTenRowLetters.forEach((letter) => {
240245
if (
241-
progressReportSheet[index][letter] !== null &&
246+
progressReportSheet[index][letter] &&
242247
isValidProgressReportInput(progressReportSheet[index][letter])
243248
) {
244249
communicationMaterials = progressReportSheet[index][letter];
@@ -254,7 +259,7 @@ const getProjectBudgetRisks = (
254259
let projectBudgetRisks = null;
255260
firstTenRowLetters.forEach((letter) => {
256261
if (
257-
progressReportSheet[index][letter] !== null &&
262+
progressReportSheet[index][letter] &&
258263
isValidProgressReportInput(progressReportSheet[index][letter])
259264
) {
260265
projectBudgetRisks = progressReportSheet[index][letter];
@@ -270,7 +275,7 @@ const getChangesToOverallBudget = (
270275
let changesToOverallBudget = null;
271276
firstTenRowLetters.forEach((letter) => {
272277
if (
273-
progressReportSheet[index][letter] !== null &&
278+
progressReportSheet[index][letter] &&
274279
isValidProgressReportInput(progressReportSheet[index][letter])
275280
) {
276281
changesToOverallBudget = progressReportSheet[index][letter];
@@ -691,7 +696,7 @@ const ValidateData = async (data, req) => {
691696
}
692697
}
693698

694-
if (dateRequestReceived === undefined) {
699+
if (dateRequestReceived === undefined || dateRequestReceived === null) {
695700
errors.push({
696701
level: 'cell',
697702
error: 'Invalid data: Date request received',

app/tests/backend/lib/claims-upload.test.ts

+68
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,36 @@ describe('The Claims excel import api route', () => {
7676
expect(response.status).toBe(200);
7777
});
7878

79+
it('should process uploaded file for new format', async () => {
80+
mocked(getAuthRole).mockImplementation(() => {
81+
return {
82+
pgRole: 'ccbc_admin',
83+
landingRoute: '/',
84+
};
85+
});
86+
87+
mocked(performQuery).mockImplementation(async () => {
88+
return {
89+
data: {
90+
createApplicationClaimsData: {
91+
applicationClaimsData: { rowId: 1 },
92+
},
93+
},
94+
};
95+
});
96+
97+
const response = await request(app)
98+
.post('/api/analyst/claims/10/CCBC-010001/undefined/undefined')
99+
.set('Content-Type', 'application/json')
100+
.set('Connection', 'keep-alive')
101+
.field('data', JSON.stringify({ name: 'claims-data' }))
102+
// replace with claims file once we receive it
103+
.attach('claims-data', `${__dirname}/claims_new_format.xlsx`)
104+
.expect(200);
105+
106+
expect(response.status).toBe(200);
107+
});
108+
79109
it('should return error if file does not have expected worksheets', async () => {
80110
mocked(getAuthRole).mockImplementation(() => {
81111
return {
@@ -143,6 +173,44 @@ describe('The Claims excel import api route', () => {
143173
]);
144174
});
145175

176+
it('should return correct errors for excel with empty fields for new format', async () => {
177+
mocked(getAuthRole).mockImplementation(() => {
178+
return {
179+
pgRole: 'ccbc_admin',
180+
landingRoute: '/',
181+
};
182+
});
183+
184+
const response = await request(app)
185+
.post('/api/analyst/claims/10/CCBC-010001/undefined/undefined')
186+
.set('Content-Type', 'application/json')
187+
.set('Connection', 'keep-alive')
188+
.field('data', JSON.stringify({ name: 'claims-data' }))
189+
.attach('claims-data', `${__dirname}/claims_new_format_empty.xlsx`)
190+
.expect(400);
191+
192+
expect(response.status).toBe(400);
193+
expect(response.body).toEqual([
194+
{
195+
error: 'Invalid data: Claim number',
196+
level: 'cell',
197+
},
198+
{ level: 'cell', error: 'Invalid data: Date request received' },
199+
{
200+
level: 'cell',
201+
error: 'Invalid data: Eligible costs incurred from date',
202+
},
203+
{
204+
level: 'cell',
205+
error: 'Invalid data: Eligible costs incurred to date',
206+
},
207+
{
208+
error:
209+
'CCBC Number mismatch: expected CCBC-010001, received: undefined',
210+
},
211+
]);
212+
});
213+
146214
it('should return correct errors for excel with incorrect fields', async () => {
147215
mocked(getAuthRole).mockImplementation(() => {
148216
return {
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)