Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/playwright-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
NPDI_API_PORT=5001
GRAPH_PASSWORD=test_password
GRAPH_USER=neo4j
GRAPH_NM_URI="db:7687"
FLASK_ENV=development
MIXPANEL_TOKEN=notset
EOF
Expand Down Expand Up @@ -99,12 +100,14 @@ jobs:

- name: Install Playwright Browsers
working-directory: frontend
run: npx playwright install --with-deps
run: npx playwright install --with-deps chromium

- name: Run Playwright tests
working-directory: frontend
env:
NPDI_WEB_PORT: 3000
NPDI_API_PORT: 5001
NEXT_PUBLIC_API_BASE_URL: http://0.0.0.0:5001/api/v1
run: npm run test:e2e

- name: Upload test results
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:
- /app/node_modules
environment:
NEXT_PUBLIC_API_MODE: real
NEXT_PUBLIC_API_BASE_URL: http://localhost:${NPDI_API_PORT:-5000}/api/v1
NEXT_PUBLIC_API_BASE_URL: http://localhost:${NPDI_API_PORT:-5001}/api/v1
ports:
- ${NPDI_WEB_PORT:-3000}:${NPDI_WEB_PORT:-3000}
api:
Expand Down
120 changes: 120 additions & 0 deletions frontend/tests/officers.post.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { test, expect } from "@playwright/test"

// This test posts multiple officers to the backend API and verifies they were created.
// It uses Playwright's APIRequestContext via the `request` fixture. The project's
// Playwright config sets `baseURL` to the web container, so we have to specify
// an `apiURL` here instead.

// Sample officers payload - adjust fields to match backend model expectations.
const sampleOfficers = [
{
uid: `test-officer-${Date.now()}-1`,
first_name: "TestFirst1",
middle_name: "M",
last_name: "TestLast1",
suffix: "Jr.",
ethnicity: "White",
gender: "Male",
state_ids: [
{
id_name: "Tax ID Number",
state: "NY",
value: `TAX-${Date.now()}`
}
]
},
{
uid: `test-officer-${Date.now()}-2`,
first_name: "TestFirst2",
middle_name: "A",
last_name: "TestLast2",
ethnicity: "Hispanic/Latino",
gender: "Female",
state_ids: [
{
id_name: "Driver's License",
state: "NY",
value: `DL-${Date.now()}`
}
]
}
]

test.describe("Officers API", () => {
test("POST multiple officers and verify they exist", async ({ request }) => {
// Register a temporary user and create a source so the user is promoted
// to CONTRIBUTOR (the backend requires that role to create officers).
const testEmail = `pw-${Date.now()}@example.com`
const testPassword = "TestPass123!"
const apiBase =
process.env.NEXT_PUBLIC_API_BASE_URL ??
`http://localhost:${process.env.NPDI_API_PORT ?? "5001"}/api/v1`

const regRes = await request.post(`${apiBase}/auth/register`, {
data: {
email: testEmail,
password: testPassword,
firstname: "PW",
lastname: "Test",
phone_number: "000-000-0000"
},
headers: { "Content-Type": "application/json" }
})

if (!regRes.ok()) {
const bad = await regRes.text()
console.error("Register failed:", regRes.status(), bad)
}
expect(regRes.ok()).toBeTruthy()
const regJson = await regRes.json()
const accessToken = regJson?.access_token
expect(accessToken).toBeTruthy()

// Create a source to promote the user to CONTRIBUTOR
const sourceRes = await request.post(`${apiBase}/sources`, {
data: {
name: `PW Source ${Date.now()}`,
url: "https://example.org",
contact_email: testEmail
},
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`
}
})

expect(sourceRes.ok()).toBeTruthy()

// POST each officer individually (API expects single-object create)
const createdUids: string[] = []
for (const officer of sampleOfficers) {
const postRes = await request.post(`${apiBase}/officers`, {
data: officer,
headers: { "Content-Type": "application/json", Authorization: `Bearer ${accessToken}` }
})

if (!postRes.ok()) {
const body = await postRes.text()
console.error("Create officer failed:", postRes.status(), body)
}
expect(postRes.ok()).toBeTruthy()

const postJson = await postRes.json()
const createdUid = postJson?.uid || postJson?.id || officer.uid
expect(createdUid).toBeTruthy()
createdUids.push(createdUid)
}

// For each created UID, query the GET endpoint to confirm existence.
for (const uid of createdUids) {
const getRes = await request.get(`${apiBase}/officers/${encodeURIComponent(uid)}`, {
headers: { Authorization: `Bearer ${accessToken}` }
})
expect(getRes.ok()).toBeTruthy()
const getJson = await getRes.json()
// Basic checks: returned object has matching uid and name
expect(getJson).toBeDefined()
expect(getJson.uid || getJson.id).toBeTruthy()
}
})
})
Loading