Skip to content

Commit 65c971d

Browse files
committed
Additional tweaks for payment report
1 parent 444f204 commit 65c971d

6 files changed

Lines changed: 23 additions & 9 deletions

File tree

sql/reports/sfdc/payments.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ WITH resolved_payment_references AS (
2020
ELSE c.name
2121
END AS challenge_name,
2222
c.status AS challenge_status,
23+
CASE
24+
WHEN w.category = 'ENGAGEMENT_PAYMENT' THEN 'COMPLETED'
25+
ELSE c.status
26+
END AS reported_challenge_status,
2327
m.handle,
2428
m."userId",
2529
m."firstName",
@@ -49,7 +53,7 @@ SELECT
4953
category,
5054
(category = 'TASK_PAYMENT') AS "isTask",
5155
challenge_name AS "challengeName",
52-
challenge_status AS "challengeStatus",
56+
reported_challenge_status AS "challengeStatus",
5357
handle AS "winnerHandle",
5458
"userId" as "winnerId",
5559
"firstName" as "winnerFirstName",
@@ -73,6 +77,6 @@ WHERE
7377
AND ($8::timestamptz IS NULL OR created_at <= $8::timestamptz)
7478
AND ($9::numeric IS NULL OR total_amount >= $9::numeric)
7579
AND ($10::numeric IS NULL OR total_amount <= $10::numeric)
76-
AND ($11::text[] IS NULL OR challenge_status::text = ANY($11::text[]))
80+
AND ($11::text[] IS NULL OR reported_challenge_status::text = ANY($11::text[]))
7781
AND ($12::text[] IS NULL OR payment_status::text = ANY($12::text[]))
7882
ORDER BY created_at DESC

src/reports/member/member-search.service.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ describe("MemberSearchService", () => {
106106
expect(dataSql).toContain(
107107
'ORDER BY m.handle ASC, "matchIndex" DESC NULLS LAST',
108108
);
109-
expect(dataSql).toContain(
110-
'LOWER(m."homeCountryCode") = ANY($1::text[])',
111-
);
109+
expect(dataSql).toContain('LOWER(m."homeCountryCode") = ANY($1::text[])');
112110
expect(dataParams).toEqual([["us"], 5, 5]);
113111
expect(countParams).toEqual([["us"]]);
114112
});

src/reports/sfdc/sfdc-reports.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export class PaymentsReportResponse {
343343
paymentAmount: number;
344344
@ApiProperty({
345345
description:
346-
'Challenge status from challenges."Challenge".status. Null for ENGAGEMENT_PAYMENT rows and challenge-backed rows whose external reference cannot be resolved.',
346+
"Normalized challenge status label for challenge-backed payments. ENGAGEMENT_PAYMENT rows are always reported as Completed; challenge-backed rows whose external reference cannot be resolved remain null.",
347347
nullable: true,
348348
type: String,
349349
})

src/reports/sfdc/sfdc-reports.service.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ describe("SfdcReportsService - getPaymentsReport", () => {
314314
expect(paymentsSql).toContain(
315315
"WHEN w.category = 'ENGAGEMENT_PAYMENT' THEN ea.\"engagementId\"",
316316
);
317+
expect(paymentsSql).toContain(
318+
"WHEN w.category = 'ENGAGEMENT_PAYMENT' THEN 'COMPLETED'",
319+
);
320+
expect(paymentsSql).toContain(
321+
"reported_challenge_status::text = ANY($11::text[])",
322+
);
317323
expect(paymentsSql).toContain(
318324
"($3::text[] IS NULL AND $4::text[] IS NULL)",
319325
);
@@ -354,7 +360,7 @@ describe("SfdcReportsService - getPaymentsReport", () => {
354360
expect.objectContaining({
355361
category: "ENGAGEMENT_PAYMENT",
356362
challengeName: "Customer Support Engagement",
357-
challengeStatus: null,
363+
challengeStatus: "Completed",
358364
}),
359365
expect.objectContaining({
360366
category: "CHALLENGE_PAYMENT",

src/reports/sfdc/sfdc-reports.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export class SfdcReportsService {
130130

131131
return payments.map((payment) => ({
132132
...payment,
133-
challengeStatus: normalizeChallengeStatus(payment.challengeStatus),
133+
challengeStatus:
134+
payment.category === "ENGAGEMENT_PAYMENT"
135+
? "Completed"
136+
: normalizeChallengeStatus(payment.challengeStatus),
134137
}));
135138
}
136139

src/reports/sfdc/test-helpers/mock-data.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ export const normalizedChallengeData = mockChallengeData.map((challenge) => ({
172172

173173
export const normalizedPaymentData = mockPaymentData.map((payment) => ({
174174
...payment,
175-
challengeStatus: normalizeChallengeStatus(payment.challengeStatus),
175+
challengeStatus:
176+
payment.category === "ENGAGEMENT_PAYMENT"
177+
? "Completed"
178+
: normalizeChallengeStatus(payment.challengeStatus),
176179
}));
177180

178181
export const mockBaFeesData: BaFeesReportResponse[] = [

0 commit comments

Comments
 (0)