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

Commit

Permalink
feat: made getScheduledPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 27, 2020
1 parent 3f2cf26 commit e97ed56
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/sections/easy-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,51 @@ const UpdateScheduledPackagesResponse = Codec.interface({
UpdateScheduledPackagesResult: UpdateScheduledPackages,
}),
})

interface GetScheduledPackageParameters {
ScheduledPackageId: ScheduledPackageId
MarketplaceId: string
}

const GetScheduledPackage = Codec.interface({
ScheduledPackage: Package,
})

type GetScheduledPackage = GetInterface<typeof GetScheduledPackage>

const GetScheduledPackageResponse = Codec.interface({
GetScheduledPackageResponse: Codec.interface({
GetScheduledPackageResult: GetScheduledPackage,
}),
})

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

async getScheduledPackage(
parameters: GetScheduledPackageParameters,
): Promise<[GetScheduledPackage, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.EasyShip,
version: EASY_SHIP_API_VERSION,
action: 'GetScheduledPackage',
parameters: {
MarketplaceId: parameters.MarketplaceId,
ScheduledPackageId: {
AmazonOrderId: parameters.ScheduledPackageId.AmazonOrderId,
PackageId: parameters.ScheduledPackageId.PackageId,
},
},
})

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

async updateScheduledPackages(
parameters: UpdateScheduledPackagesParameters,
): Promise<[UpdateScheduledPackages, RequestMeta]> {
Expand Down
36 changes: 36 additions & 0 deletions test/unit/__snapshots__/easy-ship.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ Array [
]
`;

exports[`easyShip getScheduledPackage returns info about the scheduled package if succesful 1`] = `
Array [
Object {
"ScheduledPackage": Object {
"PackageDimensions": Object {
"Height": 12,
"Length": 12,
"Unit": "cm",
"Width": 12,
},
"PackagePickupSlot": Object {
"PickupTimeEnd": 2018-02-19T10:30:00.500Z,
"PickupTimeStart": 2018-02-19T08:30:00.500Z,
"SlotId": "Xyt123bbdg=",
},
"PackageStatus": "Scheduled",
"PackageWeight": Object {
"Unit": "g",
"Value": 23,
},
"ScheduledPackageId": Object {
"AmazonOrderId": "903-1713775-3598252",
"PackageId": "1ab0f06a-9149-87e0-aba9-7098117872d6",
},
},
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`easyShip getServiceStatus returns a parsed model when the status response is valid 1`] = `
Array [
Object {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/easy-ship.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('easyShip', () => {
it('returns info about the scheduled package if succesful', async () => {
expect.assertions(1)

const mockGetScheduledPackage = createMockHttpClient('easy_ship_update_scheduled_packages')
const mockGetScheduledPackage = createMockHttpClient('easy_ship_get_scheduled_package')

expect(
await mockGetScheduledPackage.easyShip.getScheduledPackage(parameters),
Expand Down

0 comments on commit e97ed56

Please sign in to comment.