Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
feat: update subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 17, 2020
1 parent 6774259 commit bcf8ad5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/sections/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,46 @@ const DeleteSubscriptionResponse = Codec.interface({
DeleteSubscriptionResult: exactly(''),
}),
})

interface UpdateSubscriptionParameters {
MarketplaceId: string
Subscription: Subscription
}

const UpdateSubscriptionResponse = Codec.interface({
UpdateSubscriptionResponse: Codec.interface({
UpdateSubscriptionResult: exactly(''),
}),
})
export class Subscriptions {
constructor(private httpClient: HttpClient) {}

async updateSubscription(parameters: UpdateSubscriptionParameters): Promise<['', RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Subscriptions,
version: SUBSCRIPTIONS_API_VERSION,
action: 'UpdateSubscription',
parameters: {
MarketplaceId: parameters.MarketplaceId,
Subscription: {
NotificationType: parameters.Subscription.NotificationType,
Destination: {
DeliveryChannel: parameters.Subscription.Destination.DeliveryChannel,
'AttributeList.member': parameters.Subscription.Destination.AttributeList,
},
IsEnabled: parameters.Subscription.IsEnabled,
},
}
})

return UpdateSubscriptionResponse.decode(response).caseOf({
Right: (x) => [x.UpdateSubscriptionResponse.UpdateSubscriptionResult, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async deleteSubscription(parameters: DeleteSubscriptionParameters): Promise<['', RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Subscriptions,
Expand Down
13 changes: 13 additions & 0 deletions test/unit/__snapshots__/subscriptions.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,16 @@ Array [
},
]
`;

exports[`sellers updateSubscription returns the standard response if update is succesful 1`] = `
Array [
"",
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

0 comments on commit bcf8ad5

Please sign in to comment.