Skip to content

refactor: drop axios from tests and webhooks#1046

Merged
ferhatelmas merged 1 commit intomasterfrom
ferhat/axios-tests
Apr 23, 2026
Merged

refactor: drop axios from tests and webhooks#1046
ferhatelmas merged 1 commit intomasterfrom
ferhat/axios-tests

Conversation

@ferhatelmas
Copy link
Copy Markdown
Member

@ferhatelmas ferhatelmas commented Apr 23, 2026

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

Copilot AI review requested due to automatic review settings April 23, 2026 15:25
@ferhatelmas ferhatelmas requested a review from a team as a code owner April 23, 2026 15:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.post usage with native fetch in 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.purge instead 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.

Comment thread src/test/queue-mocks.test.ts Outdated
Comment thread src/test/render-routes.test.ts
Comment thread src/test/render-routes.test.ts Outdated
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 23, 2026

Coverage Report for CI Build 24851859970

Coverage increased (+0.1%) to 71.373%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (20 of 21 lines covered, 95.24%).
  • 5 coverage regressions across 2 files.

Uncovered Changes

File Changed Covered %
src/storage/events/lifecycle/webhook.ts 21 20 95.24%

Coverage Regressions

5 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
src/storage/cdn/cdn-cache-manager.ts 4 25.0%
src/storage/object.ts 1 87.8%

Coverage Stats

Coverage Status
Relevant Lines: 9750
Covered Lines: 7357
Line Coverage: 75.46%
Relevant Branches: 5449
Covered Branches: 3491
Branch Coverage: 64.07%
Branches in Coverage %: Yes
Coverage Strength: 377.43 hits per line

💛 - Coveralls

@ferhatelmas ferhatelmas force-pushed the ferhat/axios-tests branch 3 times, most recently from 742c8bc to 4fe4585 Compare April 23, 2026 17:16
@ferhatelmas ferhatelmas changed the title refactor: drop axios from tests refactor: drop axios from tests and webhooks Apr 23, 2026
@ferhatelmas ferhatelmas force-pushed the ferhat/axios-tests branch 3 times, most recently from 017c785 to f63f44e Compare April 23, 2026 17:29
@ferhatelmas ferhatelmas requested a review from Copilot April 23, 2026 17:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/test/render-routes.test.ts
Comment thread src/test/render-routes.test.ts
Comment thread src/test/render-routes.test.ts
Comment thread src/test/render-routes.test.ts
Comment thread src/test/render-routes.test.ts Outdated
@ferhatelmas ferhatelmas force-pushed the ferhat/axios-tests branch 2 times, most recently from bbd764d to a19e2e1 Compare April 23, 2026 17:41
@ferhatelmas ferhatelmas requested a review from Copilot April 23, 2026 17:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getTenantConfig function rejects; it doesn't exercise Webhook.shouldSend or Webhook.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 when getTenantConfig throws (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.

Comment thread src/storage/events/lifecycle/webhook.ts
@ferhatelmas ferhatelmas force-pushed the ferhat/axios-tests branch 2 times, most recently from a8a992d to cc593fa Compare April 23, 2026 17:52
@ferhatelmas ferhatelmas requested a review from Copilot April 23, 2026 17:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/test/queue-mocks.test.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / runMigrationsOnTenant functions 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 against Webhook.shouldSend / Webhook.handle behavior 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

  • resources is logged with a leading slash in the success logSchema.event call but without it in the error logger.error call. 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.

Comment thread src/storage/events/lifecycle/webhook.ts
Comment thread src/test/cdn.test.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in Webhook or 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.

Comment thread src/test/render-routes.test.ts
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getTenantConfig rejects; it doesn’t exercise any behavior in Webhook.shouldSend/Webhook.handle, so it provides little signal and can give a false sense of coverage. Consider removing it or rewriting it to assert how Webhook.shouldSend behaves when getTenantConfig throws.
  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.

Comment thread src/storage/events/lifecycle/webhook.ts
@ferhatelmas ferhatelmas merged commit 648a811 into master Apr 23, 2026
13 checks passed
@ferhatelmas ferhatelmas deleted the ferhat/axios-tests branch April 23, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants