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

Commit

Permalink
feat: create subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 17, 2020
1 parent fee1cfa commit ccf7ef6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
43 changes: 43 additions & 0 deletions src/sections/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,52 @@ const SendTestNotificationToDestinationResponse = Codec.interface({
}),
})

interface Subscription {
NotificationType: NotificationType
Destination: Destination
IsEnabled: boolean
}

interface CreateSubscriptionParameters {
MarketplaceId: string
Subscription: Subscription
}

const CreateSubscriptionResponse = Codec.interface({
CreateSubscriptionResponse: Codec.interface({
CreateSubscriptionResult: exactly(''),
}),
})

export class Subscriptions {
constructor(private httpClient: HttpClient) {}

async createSubscription(parameters: CreateSubscriptionParameters): Promise<['', RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Subscriptions,
version: SUBSCRIPTIONS_API_VERSION,
action: 'SendTestNotificationToDestination',
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 CreateSubscriptionResponse.decode(response).caseOf({
Right: (x) => [x.CreateSubscriptionResponse.CreateSubscriptionResult, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async sendTestNotificationToDestination(
parameters: SendTestNotificationToDestinationParameters,
): Promise<['', RequestMeta]> {
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
@@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`sellers createSubscription returns the standard response if testing 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,
},
]
`;

exports[`sellers deregisterDestination returns the standard response if deregistration is succesful 1`] = `
Array [
"",
Expand Down
8 changes: 6 additions & 2 deletions test/unit/subscriptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { amazonMarketplaces, HttpClient, ParsingError } from '../../src'
import { MWS } from '../../src/mws'
import { AttributeKeyValueKeys, DeliveryChannel, NotificationType } from '../../src/sections/subscriptions'
import {
AttributeKeyValueKeys,
DeliveryChannel,
NotificationType,
} from '../../src/sections/subscriptions'
import { getFixture } from '../utils'

const httpConfig = {
Expand Down Expand Up @@ -60,7 +64,7 @@ const mockSubscription = {

const mockMarketplaceIdSubscriptionParameters = {
MarketplaceId: '',
Subscriptions: mockSubscription,
Subscription: mockSubscription,
}

describe('sellers', () => {
Expand Down

0 comments on commit ccf7ef6

Please sign in to comment.