refactor: drop axios from tests and webhooks#1046
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the test suite to remove Axios usage/mocking in favor of native fetch and more direct/more focused mocks.
Changes:
- Replaced
axios.postusage with nativefetchin S3 multipart/form-data upload tests. - Removed Axios-based renderer client setup in render-route tests and replaced it with a local mocked client.
- Simplified/migrated CDN purge route test to spy on
CdnCacheManager.purgeinstead of mocking Axios internals.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/test/s3-protocol.test.ts | Drops Axios usage in multipart form upload tests by switching to fetch. |
| src/test/render-routes.test.ts | Replaces Axios client creation/spies with a local mocked renderer client. |
| src/test/queue-mocks.test.ts | Removes Axios mocking and replaces the network-error test with a local mocked function. |
| src/test/cdn.test.ts | Removes Axios mocking and asserts the route calls CdnCacheManager.purge with expected inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage Report for CI Build 24851859970Coverage increased (+0.1%) to 71.373%Details
Uncovered Changes
Coverage Regressions5 previously-covered lines in 2 files lost coverage.
Coverage Stats💛 - Coveralls |
742c8bc to
4fe4585
Compare
017c785 to
f63f44e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bbd764d to
a19e2e1
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/test/queue-mocks.test.ts:203
- This test only asserts that the mocked
getTenantConfigfunction rejects; it doesn't exerciseWebhook.shouldSendorWebhook.handle, so it doesn't validate any webhook queue handler behavior and adds noise to the suite. Consider rewriting it to assert the webhook handler behavior whengetTenantConfigthrows (or remove the test if that scenario isn't meant to be handled here).
it('should handle database errors gracefully', async () => {
const dbError = new Error('Database connection failed')
mockGetTenantConfig.mockRejectedValue(dbError)
await expect(mockGetTenantConfig('test-tenant')).rejects.toThrow('Database connection failed')
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a8a992d to
cc593fa
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/test/queue-mocks.test.ts:207
- The test "should handle database errors gracefully" doesn't exercise any production logic; it only asserts that the mocked getTenantConfig rejects when configured to reject (tautological). Consider removing this test or changing it to assert the behavior of Webhook.shouldSend / Webhook.handle when getTenantConfig throws (e.g., whether it propagates or is handled/logged).
it('should handle database errors gracefully', async () => {
const dbError = new Error('Database connection failed')
mockGetTenantConfig.mockRejectedValue(dbError)
await expect(mockGetTenantConfig('test-tenant')).rejects.toThrow('Database connection failed')
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cc593fa to
8e55324
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
src/test/queue-mocks.test.ts:219
- These last two tests only assert that the mocked
getTenantConfig/runMigrationsOnTenantfunctions reject when configured to reject, without exercising any queue handler logic. They don't add meaningful coverage and can be removed or replaced with assertions againstWebhook.shouldSend/Webhook.handlebehavior when those dependencies fail.
it('should handle database errors gracefully', async () => {
const dbError = new Error('Database connection failed')
mockGetTenantConfig.mockRejectedValue(dbError)
await expect(mockGetTenantConfig('test-tenant')).rejects.toThrow('Database connection failed')
})
it('should handle migration errors gracefully', async () => {
const migrationError = new Error('Migration failed')
mockRunMigrationsOnTenant.mockRejectedValue(migrationError)
await expect(
mockRunMigrationsOnTenant({
databaseUrl: 'postgres://test:test@localhost:5432/test',
tenantId: 'test-tenant',
})
).rejects.toThrow('Migration failed')
})
src/storage/events/lifecycle/webhook.ts:181
resourcesis logged with a leading slash in the successlogSchema.eventcall but without it in the errorlogger.errorcall. This inconsistency can break downstream log/resource parsing; use the same resource format in both places (either always include the leading/or never include it).
error: error.message,
jodId: job.id,
type: 'event',
event: job.data.event.type,
payload: JSON.stringify(job.data.event.payload),
objectPath: path,
resources: [path],
tenantId: job.data.tenant.ref,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8e55324 to
c78a14f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/test/queue-mocks.test.ts:218
- The last two tests only assert that the
vi.fn()mocks (mockGetTenantConfig/mockRunMigrationsOnTenant) reject when configured to reject. They don't exercise any production handler logic and will always pass regardless of behavior inWebhookor the queue handlers. Consider removing these assertions or rewriting them to call the relevant handler code paths that should surface DB/migration errors.
it('should handle database errors gracefully', async () => {
const dbError = new Error('Database connection failed')
mockGetTenantConfig.mockRejectedValue(dbError)
await expect(mockGetTenantConfig('test-tenant')).rejects.toThrow('Database connection failed')
})
it('should handle migration errors gracefully', async () => {
const migrationError = new Error('Migration failed')
mockRunMigrationsOnTenant.mockRejectedValue(migrationError)
await expect(
mockRunMigrationsOnTenant({
databaseUrl: 'postgres://test:test@localhost:5432/test',
tenantId: 'test-tenant',
})
).rejects.toThrow('Migration failed')
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
c78a14f to
afb13ee
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/test/queue-mocks.test.ts:207
- This test only asserts that the mocked
getTenantConfigrejects; it doesn’t exercise any behavior inWebhook.shouldSend/Webhook.handle, so it provides little signal and can give a false sense of coverage. Consider removing it or rewriting it to assert howWebhook.shouldSendbehaves whengetTenantConfigthrows.
it('should handle database errors gracefully', async () => {
const dbError = new Error('Database connection failed')
mockGetTenantConfig.mockRejectedValue(dbError)
await expect(mockGetTenantConfig('test-tenant')).rejects.toThrow('Database connection failed')
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What kind of change does this PR introduce?
Refactor
What is the current behavior?
Axios is used/mocked in tests and webhooks.
What is the new behavior?
Use native fetch/undici agent or improve mock to test the contract.
Additional context
Next one in dropping axios, related to #1038, #1042