Skip to content

Comments

Finish replacing real API calls with mocks in test suite#183

Merged
markstos merged 11 commits intomainfrom
release/3.3.0
Jan 29, 2026
Merged

Finish replacing real API calls with mocks in test suite#183
markstos merged 11 commits intomainfrom
release/3.3.0

Conversation

@wesleyschlenker
Copy link
Collaborator

@wesleyschlenker wesleyschlenker commented Jan 22, 2026

This PR completes the migration of the test suite to use mock API calls instead of the real Strava API.

Changes

  • Removed all legacy helper functions that made real API calls
  • Updated listZones() test to use mocks (previously skipped)
  • Removed listPhotos() test (previously skipped)
  • All tests now use nock for mocking API responses
  • Updates README to reflect ubiquitous mock usage
  • Bumped version to 3.3.0

Testing

  • All tests pass
  • yarn test completes entirely without an apiKey

Summary by CodeRabbit

  • Chores

    • Removed Drone and Travis CI configurations.
  • Documentation

    • README refreshed: badges, wording, endpoints, examples, environment and testing guidance reformatted and clarified.
  • API Changes

    • Added listing for routes and new segment/stream actions; removed several deprecated route methods.
  • Tests

    • Expanded activity zones tests; removed multiple test helper utilities and the listPhotos test.

Version: 3.3.0

✏️ Tip: You can customize this high-level summary in your review settings.

- Convert the existing test for listZones() from a skipped test to an active one.
- Mock the API response for heart rate and power zones.
- Add assertions to verify the structure and values of the returned zones, including distribution buckets.
- Ensure the test checks both power and heartrate zones for expected properties.
This method doesn't actually exist in the library, only the typescript definitions and a skipped test exist. There is also no corollary in the strava api documentation.

- Deleted the listPhotos method from the ActivitiesRoutes interface in index.d.ts.
- Removed the associated test case for listPhotos from activities.js, which was previously marked as skipped.
All tests are written and mocked!

- Removed several functions from testsHelper that were designed to fetch sample data from the Strava API, including getSampleAthlete, getSampleActivity, getSampleClub, getSampleRoute, getSampleGear, getSampleSegmentEffort, getSampleSegment, and getSampleRunningRace.
- This cleanup reduces code complexity and focuses on essential helper functions.
- Replaced Travis CI badge with GitHub Actions badge.
- Clarified test instructions, emphasizing that all tests now use `nock` to mock the Strava API.
- Enhanced the description of the test suite's functionality and requirements.
- Updated maintainer information to include Wesley Schlenker.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

Removed Drone and Travis CI configs, updated README (badges, endpoints, wording), bumped package version to 3.3.0, adjusted TypeScript definitions (added/removed methods), added athlete.listRoutes, removed several test helpers, removed one test block, and expanded/refactored the listZones test to use nock.

Changes

Cohort / File(s) Summary
CI configuration
\.drone\.yml, \.travis\.yml
Deleted Drone CI pipeline and Travis CI configuration (removed Node matrix and pipeline steps).
Documentation
README.md
Reflowed and rewrote sections, swapped CI badges (Travis → GitHub Actions), adjusted endpoints/examples, fixed typos, and updated maintainers/tests guidance.
Type definitions
index.d.ts
Added SegmentsRoutes.starSegment and StreamsRoutes.route; removed several methods (e.g., SegmentsRoutes.listLeaderboard, multiple ClubsRoutes.*, AthletesRoutes.get, several ActivitiesRoutes.*).
Package metadata
package.json
Bumped version from 3.2.03.3.0.
Library surface
lib/athlete.js
Added listRoutes(args) delegating to existing _listHelper('routes', ...).
Test helpers
test/_helper.js
Removed eight exported test helper methods (sample athlete/activity/club/route/gear/segment/segmentEffort/runningRace).
Test suite changes
test/activities.js
Replaced/renamed update test, expanded listZones into an active nock-backed async test with detailed assertions, and removed the listPhotos test block.

Sequence Diagram(s)

(omitted — changes do not introduce a new multi-component control flow needing sequence visualization)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • markstos

Poem

🐰 CI files hopped away at dawn,
Tests now mocked upon the lawn,
A new route method sniffs the breeze,
Types trimmed gently from the trees,
Version nudged — I munch and yawn. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the pull request: completing the migration of the test suite to use mocked API calls instead of real Strava API requests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Added `starSegment` method to `SegmentsRoutes` interface in index.d.ts.
- Introduced `route` method to `StreamsRoutes` interface in index.d.ts.
- Removed references to `running_races` from README.md.
- Updated README.md
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@README.md`:
- Line 325: Update the README description for strava.segments.explore(args,done)
to hyphenate the compound adjective: change "comma separated string" to
"comma-separated string" in the bounds argument description so it reads
`"bounds" as a comma-separated string, for two points describing a rectangular
boundary...` to improve grammar and consistency.
- Line 420: Update the README sentence "Rate limiting functionality is properly
tested" to use the hyphenated compound adjective "Rate-limiting functionality is
properly tested" so the compound adjective is grammatically correct; edit the
README.md content where that line appears.

The test is named `#updateSportType()` but calls `strava.activities.update()`. There is no `updateSportType()` method in the implementation. The test name suggests a different method.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/activities.js (1)

127-150: Duplicate describe block name creates confusing test output.

There are now two describe('#update()', ...) blocks (lines 102–125 and 127–150). This will produce duplicate test group names in the output, making it harder to identify which test failed. Consider renaming this block to distinguish it from the other update test.

Suggested fix
-  describe('#update()', function () {
+  describe('#update() - sport type', function () {
     it('should update the sport type of an activity', async function () {
🧹 Nitpick comments (1)
test/activities.js (1)

154-208: Nock mock missing consistency with other tests in this file.

All other mocks in this file include .query(true), .matchHeader('authorization', /Bearer .+/), and .once(). This mock is missing these, which could mask issues with query parameter handling or authorization headers.

Suggested fix for consistency
       // Mock the list zones API call
       nock('https://www.strava.com')
         .get('/api/v3/activities/' + testActivity.id + '/zones')
+        .query(true)
+        .matchHeader('authorization', /Bearer .+/)
+        .once()
         .reply(200, [

Copy link
Collaborator

@markstos markstos left a comment

Choose a reason for hiding this comment

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

Reviewed diff. These all look like solid changes.

Moving over to 100% mocks sets up to run tests in CI.

@markstos markstos merged commit c52b9ef into main Jan 29, 2026
3 checks passed
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.

2 participants