-
Notifications
You must be signed in to change notification settings - Fork 0
feat(phase-4a): phase 4a acceptance test fixes #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 25 commits
2e53ac9
2dda361
a8ae289
f314f82
cbc945c
9edc3f8
0660295
5d9da79
b0cbcd9
fd0707c
0e5a896
09844e6
2599412
95aa690
7e33b56
f40bc6c
21c2a98
1c24c31
b4d50a8
19e01c5
1cff813
cfc5548
7c547f0
aff8dd7
c63dbe2
7d96e39
bf60f5b
a0b3bb7
967c43e
beda824
66b8651
a7a947e
d1f1d4f
6136d06
22e5532
c745a38
e86a5fc
8cc78c7
dac5259
982989f
13215a4
6f5baf9
935f104
e591055
6683f88
e325664
3eeab0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { describe, it, expect, vi } from 'vitest' | ||
| import { submitReport, type SubmitReportDeps } from './submit-report.js' | ||
| import { normalizeMsisdn } from '@bantayog/shared-validators' | ||
|
|
||
| describe('submitReport', () => { | ||
| it('calls requestUploadUrl when a photo is provided, PUTs the photo, and writes inbox', async () => { | ||
|
|
@@ -69,4 +70,60 @@ describe('submitReport', () => { | |
| // eslint-disable-next-line @typescript-eslint/unbound-method | ||
| expect(deps.putBlob).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('normalizes phone and sets smsConsent in contact when provided', async () => { | ||
| const deps: SubmitReportDeps = { | ||
| ensureSignedIn: vi.fn().mockResolvedValue('citizen-1'), | ||
| requestUploadUrl: vi.fn(), | ||
| putBlob: vi.fn(), | ||
| writeInbox: vi.fn().mockResolvedValue('ibx-3'), | ||
| randomUUID: vi.fn().mockReturnValue('uuid-c'), | ||
| randomPublicRef: vi.fn().mockReturnValue('ref1234'), | ||
| randomSecret: vi.fn().mockReturnValue('s3'), | ||
| sha256Hex: vi.fn().mockResolvedValue('i'.repeat(64)), | ||
| now: () => 1, | ||
| } | ||
| await submitReport(deps, { | ||
| reportType: 'flood', | ||
| severity: 'low', | ||
| description: 'z', | ||
| publicLocation: { lat: 14.1, lng: 122.9 }, | ||
| contact: { phone: '09171234567', smsConsent: true }, | ||
| }) | ||
| // eslint-disable-next-line @typescript-eslint/unbound-method | ||
| expect(deps.writeInbox).toHaveBeenCalledOnce() | ||
| const inboxDoc = (deps.writeInbox as unknown as { mock: { calls: unknown[][] } }).mock | ||
| .calls[0]![0]! as { | ||
| payload: { contact?: { phone: string; smsConsent: true } } | ||
| } | ||
| expect(inboxDoc.payload.contact).toEqual({ | ||
| phone: normalizeMsisdn('09171234567'), | ||
| smsConsent: true, | ||
| }) | ||
| }) | ||
|
|
||
| it('omits contact when not provided', async () => { | ||
| const deps: SubmitReportDeps = { | ||
| ensureSignedIn: vi.fn().mockResolvedValue('citizen-1'), | ||
| requestUploadUrl: vi.fn(), | ||
| putBlob: vi.fn(), | ||
| writeInbox: vi.fn().mockResolvedValue('ibx-4'), | ||
| randomUUID: vi.fn().mockReturnValue('uuid-d'), | ||
| randomPublicRef: vi.fn().mockReturnValue('ref5678'), | ||
| randomSecret: vi.fn().mockReturnValue('s4'), | ||
| sha256Hex: vi.fn().mockResolvedValue('j'.repeat(64)), | ||
| now: () => 1, | ||
| } | ||
| await submitReport(deps, { | ||
| reportType: 'flood', | ||
| severity: 'low', | ||
| description: 'z', | ||
| publicLocation: { lat: 14.1, lng: 122.9 }, | ||
| }) | ||
| // eslint-disable-next-line @typescript-eslint/unbound-method | ||
| expect(deps.writeInbox).toHaveBeenCalledOnce() | ||
| const inboxDoc = (deps.writeInbox as unknown as { mock: { calls: unknown[][] } }).mock | ||
| .calls[0]![0]! as { payload: Record<string, unknown> } | ||
| expect(inboxDoc.payload.contact).toBeUndefined() | ||
|
Comment on lines
+125
to
+127
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert property absence, not
As per coding guidelines, "Write tests that verify the new code is actually invoked, not tests that pass trivially." 🤖 Prompt for AI Agents |
||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Avoid computing expected value with the same normalizer used in implementation.
This can mask defects in normalization. Assert against the concrete normalized literal (e.g.,
+639171234567) so the test fails if normalization regresses.As per coding guidelines, "Write tests that verify the new code is actually invoked, not tests that pass trivially."
🤖 Prompt for AI Agents