Skip to content

Conversation

@numbpill3d
Copy link
Owner

@numbpill3d numbpill3d commented Jun 8, 2025

Summary

  • update mocks in index.test.js to reference ScrapyardItem
  • mock countDocuments and other methods to satisfy route dependencies

Testing

  • npx jest --runTestsByPath tests/server/routes/index.test.js --silent
  • npm test --silent (fails: fetch failed)

https://chatgpt.com/codex/tasks/task_e_68450e581b70832f8ad5f17e9954db19

Summary by Sourcery

Fix failing index route tests by updating mocks to reference ScrapyardItem and mock required methods

Tests:

  • Switch Item model mock to ScrapyardItem in index tests
  • Add countDocuments and find method mocks for User and ScrapyardItem models

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 8, 2025

Reviewer's Guide

Refactored test mocks in index.test.js to reference ScrapyardItem and ensure all dependent database methods are mocked (countDocuments and find) for the index route tests.

File-Level Changes

Change Details Files
Enhanced User model mocks with additional methods
  • Added countDocuments mock resolving to total users
  • Added find mock returning active users
tests/server/routes/index.test.js
Refactored Item mocks to use ScrapyardItem and mock new methods
  • Updated mock import path from Item to ScrapyardItem
  • Added countDocuments mock resolving to total items
tests/server/routes/index.test.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

]),
countDocuments: jest.fn().mockResolvedValue(2),
find: jest.fn().mockResolvedValue([
{ username: 'recentuser', lastActive: new Date().toISOString() }
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of new Date().toISOString() directly in the test mock (line 15) can introduce flakiness in tests. If the test runs around midnight and the date changes, it could lead to inconsistent results.

Recommendation: Consider using a fixed timestamp or mocking the Date object to return a consistent value during tests to ensure test reliability.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @numbpill3d - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +14 to 16
find: jest.fn().mockResolvedValue([
{ username: 'recentuser', lastActive: new Date().toISOString() }
])
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Consider using a fixed date string in User.find mock for test predictability.

Using a static date string for lastActive will make test results consistent and prevent flakiness from dynamic timestamps.

Suggested change
find: jest.fn().mockResolvedValue([
{ username: 'recentuser', lastActive: new Date().toISOString() }
])
find: jest.fn().mockResolvedValue([
{ username: 'recentuser', lastActive: '2023-01-01T00:00:00.000Z' }
])

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