-
Notifications
You must be signed in to change notification settings - Fork 0
feat(wikibase): handle not found errors for properties and items #155
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { wikibaseEntitiesApi } from '@backend/api/wikibase/entities' | ||
| import { wikibaseService } from '@backend/services/wikibase.service' | ||
| import { treaty } from '@elysiajs/eden' | ||
| import { beforeEach, describe, expect, test } from 'bun:test' | ||
| import Elysia from 'elysia' | ||
|
|
||
| // Mock the wikibase service | ||
| const mockWikibaseService = { | ||
| getProperty: async () => { | ||
| return null // Simulate not found | ||
| }, | ||
| getItem: async () => { | ||
| return null // Simulate not found | ||
| }, | ||
| } | ||
|
|
||
| // Mock the service | ||
| Object.assign(wikibaseService, mockWikibaseService) | ||
|
|
||
|
Comment on lines
+17
to
+19
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. 🛠️ Refactor suggestion Restore wikibaseService after tests to avoid cross-suite pollution Overriding the singleton globally can leak into other tests. Save originals and restore them after the suite. Apply: @@
-import { beforeEach, describe, expect, test } from 'bun:test'
+import { beforeEach, afterAll, describe, expect, test } from 'bun:test'
@@
-// Mock the service
-Object.assign(wikibaseService, mockWikibaseService)
+// Preserve originals and mock the service
+const originalWikibaseService = {
+ getProperty: wikibaseService.getProperty.bind(wikibaseService),
+ getItem: wikibaseService.getItem.bind(wikibaseService),
+}
+Object.assign(wikibaseService, mockWikibaseService)
@@
describe('Wikibase Entities API', () => {
let api: ReturnType<typeof createTestApi>
@@
beforeEach(() => {
api = createTestApi()
})
+
+ afterAll(() => {
+ Object.assign(wikibaseService, originalWikibaseService)
+ })Also applies to: 48-50 🤖 Prompt for AI Agents |
||
| const createTestApi = () => { | ||
| return treaty(new Elysia().use(wikibaseEntitiesApi)).api | ||
| } | ||
|
|
||
| describe('Wikibase Entities API', () => { | ||
| let api: ReturnType<typeof createTestApi> | ||
|
|
||
| beforeEach(() => { | ||
| api = createTestApi() | ||
| }) | ||
|
|
||
| describe('Property endpoints', () => { | ||
| test('should return 404 for non-existent property', async () => { | ||
| const { data, status, error } = await api.wikibase.entities | ||
| .properties({ propertyId: 'P1000000' }) | ||
| .get({ | ||
| query: { instance: 'wikidata' }, | ||
| }) | ||
|
|
||
| expect(data).toBeNull() | ||
| expect(status).toBe(404) | ||
| expect(error).toHaveProperty('value', { | ||
| data: [], | ||
| errors: [ | ||
| { | ||
| details: [], | ||
| code: 'NOT_FOUND', | ||
| message: "Property with identifier 'P1000000' not found", | ||
| }, | ||
| ], | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Item endpoints', () => { | ||
| test('should return 404 for non-existent item', async () => { | ||
| const { data, status, error } = await api.wikibase.entities | ||
| .items({ itemId: 'Q1000000' }) | ||
| .get({ | ||
| query: { instance: 'wikidata' }, | ||
| }) | ||
|
|
||
| expect(data).toBeNull() | ||
| expect(status).toBe(404) | ||
| expect(error).toHaveProperty('value', { | ||
| data: [], | ||
| errors: [ | ||
| { | ||
| details: [], | ||
| code: 'NOT_FOUND', | ||
| message: "Item with identifier 'Q1000000' not found", | ||
| }, | ||
| ], | ||
| }) | ||
| }) | ||
|
|
||
| test('should return 404 when wikibase.getItem throws an error for not found', async () => { | ||
| const { data, status, error } = await api.wikibase.entities | ||
| .items({ itemId: 'Q9999999' }) | ||
| .get({ | ||
| query: { instance: 'wikidata' }, | ||
| }) | ||
|
|
||
| expect(data).toBeNull() | ||
| expect(status).toBe(404) | ||
| expect(error).toHaveProperty('value', { | ||
| data: [], | ||
| errors: [ | ||
| { | ||
| details: [], | ||
| code: 'NOT_FOUND', | ||
| message: "Item with identifier 'Q9999999' not found", | ||
| }, | ||
| ], | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Item endpoints', () => { | ||
| test('should return 404 for non-existent item', async () => { | ||
| const { data, status, error } = await api.wikibase.entities | ||
| .items({ itemId: 'Q1000000' }) | ||
| .get({ | ||
| query: { instance: 'wikidata' }, | ||
| }) | ||
|
|
||
| expect(data).toBeNull() | ||
| expect(status).toBe(404) | ||
| expect(error).toHaveProperty('value', { | ||
| data: [], | ||
| errors: [ | ||
| { | ||
| details: [], | ||
| code: 'NOT_FOUND', | ||
| message: "Item with identifier 'Q1000000' not found", | ||
| }, | ||
| ], | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💡 Verification agent
🧩 Analysis chain
Verify Elysia import style
Confirm that a default import from 'elysia' is valid in your setup. If not, switch to a named import to match the rest of the codebase.
Run to check consistency:
🏁 Script executed:
Length of output: 27
🏁 Script executed:
Length of output: 6361
Use named Elysia import for consistency
backend/tests/api/wikibase/entities.test.ts(line 5), replacebackend/tests/api/wikibase/constraints.test.ts(line 5), replace🤖 Prompt for AI Agents