Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 47 additions & 45 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,43 +611,43 @@ export interface Lap {
total_elevation_gain: number;
}

export type ActivityType =
| "AlpineSki"
| "BackcountrySki"
| "Canoeing"
| "Crossfit"
| "EBikeRide"
| "Elliptical"
| "Golf"
| "Handcycle"
| "Hike"
| "IceSkate"
| "InlineSkate"
| "Kayaking"
| "Kitesurf"
| "NordicSki"
| "Ride"
| "RockClimbing"
| "RollerSki"
| "Rowing"
| "Run"
| "Sail"
| "Skateboard"
| "Snowboard"
| "Snowshoe"
| "Soccer"
| "StairStepper"
| "StandUpPaddling"
| "Surfing"
| "Swim"
| "Velomobile"
| "VirtualRide"
| "VirtualRun"
| "Walk"
| "WeightTraining"
| "Wheelchair"
| "Windsurf"
| "Workout"
export type ActivityType =
| "AlpineSki"
| "BackcountrySki"
| "Canoeing"
| "Crossfit"
| "EBikeRide"
| "Elliptical"
| "Golf"
| "Handcycle"
| "Hike"
| "IceSkate"
| "InlineSkate"
| "Kayaking"
| "Kitesurf"
| "NordicSki"
| "Ride"
| "RockClimbing"
| "RollerSki"
| "Rowing"
| "Run"
| "Sail"
| "Skateboard"
| "Snowboard"
| "Snowshoe"
| "Soccer"
| "StairStepper"
| "StandUpPaddling"
| "Surfing"
| "Swim"
| "Velomobile"
| "VirtualRide"
| "VirtualRun"
| "Walk"
| "WeightTraining"
| "Wheelchair"
| "Windsurf"
| "Workout"
| "Yoga";

export interface DetailedActivity extends SummaryActivity {
Expand Down Expand Up @@ -678,14 +678,16 @@ export interface ActivityCreateArgs extends BaseArgs {

export interface ActivityUpdateArgs extends BaseArgs {
id: string;
commute?: boolean;
trainer?: boolean;
hide_from_home?: boolean;
description?: string;
name?: string;
type?: ActivityType;
sport_type?: SportType;
gear_id?: string;
body: {
commute?: boolean;
trainer?: boolean;
hide_from_home?: boolean;
description?: string;
name?: string;
type?: ActivityType;
sport_type?: SportType;
gear_id?: string;
}
Comment thread
bigandy marked this conversation as resolved.
}

export interface TimedZoneRange {
Expand Down
17 changes: 14 additions & 3 deletions lib/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var _updateAllowedProps = [
'name',
'type',
'sport_type',
'private',
'commute',
'hide_from_home',
'trainer',
'description',
'gear_id'
Expand Down Expand Up @@ -79,9 +79,10 @@ activities.prototype.create = function (args) {
* @throws {Error} When args.id is missing
*/
activities.prototype.update = async function (args) {
_requireActivityId(args)
_requireActivityId(args);
_requireActivityUpdateBody(args);
Comment thread
coderabbitai[bot] marked this conversation as resolved.

var form = this.client.getRequestBodyObj(_updateAllowedProps, args)
var form = this.client.getRequestBodyObj(_updateAllowedProps, args.body)
var endpoint = 'activities/' + args.id

args.form = form
Expand Down Expand Up @@ -151,6 +152,16 @@ var _requireActivityId = function (args) {
throw new Error('args must include an activity id')
}
}
/**
* Internal: Throws if args does not include a body which is now required for activty update.
* @param {{ id?: string; body?: any }} args
* @throws {Error} When args.body is missing
*/
var _requireActivityUpdateBody = function (args) {
if (typeof args.body === 'undefined') {
throw new Error('args must include a body')
}
}
/**
* Internal: GETs a paginated activity sub-resource (zones, laps, comments, kudos).
* Kudoers use page/per_page (getPaginationQS). Others use page/per_page when present,
Expand Down
14 changes: 9 additions & 5 deletions test/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ describe('activities_test', function () {
const name = 'Run like the wind!!'
const args = {
id: testActivity.id,
name: name
body: {
name: name,
}
}

// Mock the update activity API call
Expand All @@ -110,10 +112,12 @@ describe('activities_test', function () {

describe('#update()', function () {
it('should update the sport type of an activity', async function () {
const sportType = 'MountainBikeRide'
const sport_type = 'MountainBikeRide'
const args = {
id: testActivity.id,
sportType: sportType
body: {
sport_type: sport_type
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

// Mock the update activity API call
Expand All @@ -124,12 +128,12 @@ describe('activities_test', function () {
.reply(200, {
id: testActivity.id,
resource_state: 3,
sport_type: sportType
sport_type: sport_type
})

const payload = await strava.activities.update(args)
assert.strictEqual(payload.resource_state, 3)
assert.strictEqual(payload.sport_type, sportType)
assert.strictEqual(payload.sport_type, sport_type)
})
})

Expand Down