Skip to content

Commit

Permalink
Merge pull request #607 from digital-land/rosado/NOTICKET-query-fix
Browse files Browse the repository at this point in the history
A condition would always fail for entityCount = 0.

The clauses inserted into the query were used with an outer join, so this bug did not narrow down the result set. In fact the results would still contain the correct value of zero in the entity_count column.
  • Loading branch information
rosado authored Nov 6, 2024
2 parents e927f0d + 1acc733 commit 0c028f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/services/performanceDbApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function lpaOverviewQuery (lpa, params) {

const entityCountsSelects = []
for (const { resource, dataset, entityCount } of params.entityCounts) {
if (entityCount && entityCount >= 0) {
if (Number.isInteger(entityCount) && entityCount >= 0) {
entityCountsSelects.push(entityCountSelectFragment(dataset, resource, entityCount))
}
}
Expand Down
6 changes: 5 additions & 1 deletion test/unit/performanceDbApi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ describe('performanceDbApi', () => {
it('uses params in the query', () => {
const query = lpaOverviewQuery('local-authority:FOO', {
datasetsFilter: ['dataset-one', 'dataset-two'],
entityCounts: [{ dataset: 'dataset-three', resource: 'r1', entityCount: 10 }]
entityCounts: [
{ dataset: 'dataset-three', resource: 'r1', entityCount: 10 },
{ dataset: 'dataset-four', resource: 'r2', entityCount: 0 }]
})
expect(query).toContain('local-authority:FOO')
expect(query).toContain('dataset-one')
expect(query).toContain('dataset-two')
expect(query).toContain('dataset-three')
expect(query).toContain('dataset-four')
})
})

Expand Down

0 comments on commit 0c028f3

Please sign in to comment.