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

Commit

Permalink
feat: send test notification to destination
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 17, 2020
1 parent 55e5187 commit 087bf63
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
54 changes: 46 additions & 8 deletions src/sections/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ import { getServiceStatusByResource } from './shared'

const SUBSCRIPTIONS_API_VERSION = '2013-07-01'

/**
* Amazon docs list these as the only possible choices for each parameters
*/
export type DeliveryChannel = 'SQS'
export type AttributeKeyValueKeys = 'sqsQueueUrl'

interface MarketplaceIdAndDestinationOnlyParameters {
MarketplaceId: string
Destination: Destination
}

interface AttributeKeyValue {
Key: AttributeKeyValueKeys
Value: string
Expand All @@ -18,21 +27,15 @@ interface Destination {
AttributeList: AttributeKeyValue[]
}

interface RegisterDestinationParameters {
MarketplaceId: string
Destination: Destination
}
type RegisterDestinationParameters = MarketplaceIdAndDestinationOnlyParameters

const RegisterDestinationResponse = Codec.interface({
RegisterDestinationResponse: Codec.interface({
RegisterDestinationResult: exactly(''),
}),
})

interface DeregisterDestinationParameters {
MarketplaceId: string
Destination: Destination
}
type DeregisterDestinationParameters = MarketplaceIdAndDestinationOnlyParameters

const DeregisterDestinationResponse = Codec.interface({
DeregisterDestinationResponse: Codec.interface({
Expand Down Expand Up @@ -77,9 +80,44 @@ const ListRegisteredDestinationsResponse = Codec.interface({
}),
})

type SendTestNotificationToDestinationParameters = MarketplaceIdAndDestinationOnlyParameters

const SendTestNotificationToDestinationResponse = Codec.interface({
SendTestNotificationToDestinationResponse: Codec.interface({
SendTestNotificationToDestinationResult: exactly(''),
}),
})

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

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

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

async listRegisteredDestinations(
parameters: ListRegisteredDestinationsParameters,
): Promise<[ListRegisteredDestinations, 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
Expand Up @@ -66,3 +66,16 @@ Array [
},
]
`;

exports[`sellers sendTestNotificationToDestination 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,
},
]
`;

0 comments on commit 087bf63

Please sign in to comment.