diff --git a/index.d.ts b/index.d.ts index e593023..8e525db 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 { @@ -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; + } } export interface TimedZoneRange { diff --git a/lib/activities.js b/lib/activities.js index a6388d4..8303b86 100644 --- a/lib/activities.js +++ b/lib/activities.js @@ -41,8 +41,8 @@ var _updateAllowedProps = [ 'name', 'type', 'sport_type', - 'private', 'commute', + 'hide_from_home', 'trainer', 'description', 'gear_id' @@ -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); - var form = this.client.getRequestBodyObj(_updateAllowedProps, args) + var form = this.client.getRequestBodyObj(_updateAllowedProps, args.body) var endpoint = 'activities/' + args.id args.form = form @@ -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, diff --git a/test/activities.js b/test/activities.js index c9b0c5e..843b7fe 100644 --- a/test/activities.js +++ b/test/activities.js @@ -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 @@ -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 + } } // Mock the update activity API call @@ -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) }) })