Skip to content

fix(files): filter by entity.memberOf instead of entity.id#21

Merged
johnf merged 1 commit intomainfrom
fix/files-memberof-filter
Apr 29, 2026
Merged

fix(files): filter by entity.memberOf instead of entity.id#21
johnf merged 1 commit intomainfrom
fix/files-memberof-filter

Conversation

@johnf
Copy link
Copy Markdown
Collaborator

@johnf johnf commented Apr 29, 2026

Summary

  • GET /files?memberOf=X was filtering files whose related entity id equalled the given URL, instead of files whose entity is a member of that collection. Because File and Entity share an id (1:1 relation via File.idEntity.id), this collapsed to a primary-key lookup that almost never matched a collection URL.
  • The unit test in files.test.ts reinforced the bug — it asserted prisma.file.findMany was called with the wrong where shape, which mocks happily accept. The fix updates that assertion and adds a response-body assertion.
  • Adds /files integration coverage backed by real File rows seeded against the test DB. Verified the new integration tests fail when the bug is reintroduced.

Test plan

  • pnpm test src/routes/files.test.ts — 12 passed
  • pnpm test src/test/integration.test.ts — 25 passed (4 new /files tests)
  • pnpm exec tsc --noEmit — clean
  • Reverted the route fix locally and confirmed both new integration filter tests fail

GET /files?memberOf=X was filtering files whose related entity *id*
equalled the given URL, instead of files whose entity is a *member of*
the given collection. Because File and Entity share an id (1:1), this
collapsed to a primary-key lookup that almost never matched a collection
URL.

Add an integration test (with seeded File rows in the test DB) and a
response-body assertion to the unit test, since mocked Prisma will
silently accept any where-clause shape.
@johnf johnf requested a review from alvinsw April 29, 2026 05:11
@github-actions
Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 100% (🎯 100%) 301 / 301
🔵 Statements 100% (🎯 100%) 312 / 312
🔵 Functions 100% (🎯 100%) 48 / 48
🔵 Branches 100% (🎯 100%) 148 / 148
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/routes/files.ts 100% 100% 100% 100%
Generated in workflow #74 for commit d36f7e9 by the Vitest Coverage Report Action

@johnf johnf merged commit a6f27bd into main Apr 29, 2026
1 check passed
github-actions Bot pushed a commit that referenced this pull request Apr 29, 2026
## [4.0.0](v3.0.0...v4.0.0) (2026-04-29)

### ⚠ BREAKING CHANGES

* arocapi no longer decorates fastify.prisma or
fastify.opensearch; consumers must close over their own client
references.  Arocapi no longer calls
prisma.$connect()/$disconnect() or opensearch.ping()/close() —
consumers now own connecting before registration and closing on
shutdown.

### Features

* replace decoration with options-based dependency injection ([#20](#20)) ([aa5c6b7](aa5c6b7))

### Bug Fixes

* **files:** filter by entity.memberOf instead of entity.id ([#21](#21)) ([a6f27bd](a6f27bd))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants