Skip to content

Commit

Permalink
Fix invoice search when invoice has no rows
Browse files Browse the repository at this point in the history
  • Loading branch information
akheron committed Nov 11, 2024
1 parent 720e575 commit 1314587
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,21 @@ class InvoiceIntegrationTest : FullApplicationTest(resetDbBeforeEach = true) {
assertEqualEnough(testInvoices.take(2).map(::toSummary), result)
}

@Test
fun `search returns invoices without rows correctly`() {
val testInvoice =
DevInvoice(
status = InvoiceStatus.DRAFT,
headOfFamilyId = testAdult_1.id,
areaId = testArea.id,
rows = emptyList(),
)
db.transaction { tx -> tx.insert(listOf(testInvoice)) }

val result = searchInvoices(SearchInvoicesRequest(page = 1))
assertEqualEnough(listOf(toSummary(testInvoice)), result)
}

@Test
fun `search gives correct total and page composition when using filters`() {
db.transaction { tx -> tx.insert(testInvoices) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ JOIN invoice ON invoice_ids.id = invoice.id
JOIN person as head ON invoice.head_of_family = head.id
JOIN LATERAL (
SELECT
jsonb_agg(DISTINCT jsonb_build_object(
coalesce(jsonb_agg(DISTINCT jsonb_build_object(
'id', row.child,
'dateOfBirth', child.date_of_birth,
'firstName', child.first_name,
'lastName', child.last_name,
'ssn', child.social_security_number
)) AS children,
SUM(row.amount * row.unit_price) AS total_price
)), '[]'::jsonb) AS children,
coalesce(sum(row.amount * row.unit_price), 0) AS total_price
FROM invoice_row AS row
JOIN person AS child ON row.child = child.id
WHERE row.invoice_id = invoice.id
Expand Down

0 comments on commit 1314587

Please sign in to comment.