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

Commit

Permalink
test: list financial event groups
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 18, 2020
1 parent 857c23a commit 0ab2f7f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 11 deletions.
38 changes: 38 additions & 0 deletions test/unit/__fixtures__/finances_list_financial_event_groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<ListFinancialEventGroupsResponse xmlns="https://mws.amazonservices.com/Finances/2015-05-01">
<ListFinancialEventGroupsResult>
<NextToken>2YgYW55IGNhcm5hbCBwbGVhcEXAMPLE</NextToken>
<FinancialEventGroupList>
<FinancialEventGroup>
<FinancialEventGroupId>
22YgYW55IGNhcm5hbCBwbGVhEXAMPLE
</FinancialEventGroupId>
<ProcessingStatus>Closed</ProcessingStatus>
<FundTransferStatus>Successful</FundTransferStatus>
<OriginalTotal>
<CurrencyCode>USD</CurrencyCode>
<Amount>19.00</Amount>
</OriginalTotal>
<ConvertedTotal>
<CurrencyCode>USD</CurrencyCode>
<Amount>19.00</Amount>
</ConvertedTotal>
<FundTransferDate>2014-09-09T01:30:00.000-06:00</FundTransferDate>
<TraceId>128311029381HSADJEXAMPLE</TraceId>
<AccountTail>1212</AccountTail>
<BeginningBalance>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</BeginningBalance>
<FinancialEventGroupStart>
2014-09-01T01:30:00.000-06:00
</FinancialEventGroupStart>
<FinancialEventGroupEnd>
2014-09-09T01:30:00.000-06:00
</FinancialEventGroupEnd>
</FinancialEventGroup>
</FinancialEventGroupList>
</ListFinancialEventGroupsResult>
<ResponseMetadata>
<RequestId>1105b931-6f1c-4480-8e97-f3b46EXAMPLE</RequestId>
</ResponseMetadata>
</ListFinancialEventGroupsResponse>
49 changes: 38 additions & 11 deletions test/unit/finances.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,60 @@ const headers = {
'x-mws-quota-resetson': '2020-04-06T10:22:23.582Z',
}

const createMockHttpClient = (fixture: string) =>
new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture(fixture),
headers,
}),
),
)

const mockMwsFail = new MWS(
new HttpClient(httpConfig, () => Promise.resolve({ data: '', headers: {} })),
)

const parsingError = 'Expected an object, but received a string with value ""'

describe('sellers', () => {
describe('finances', () => {
describe('listFinancialEventGroups', () => {
const parameters = {
FinancialEventGroupStartedAfter: new Date(),
}

it('returns a next token and financial event groups list if succesful', async () => {
expect.assertions(1)

const mockListFinancialEventGroups = createMockHttpClient('finances_list_financial_event_groups')

expect(
await mockListFinancialEventGroups.finances.listFinancialEventGroups(parameters),
).toMatchSnapshot()
})

it('throws a parsing error when the status response is not valid', async () => {
expect.assertions(1)

await expect(() => mockMwsFail.finances.listFinancialEventGroups()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})

describe('getServiceStatus', () => {
it('returns a parsed model when the status response is valid', async () => {
expect.assertions(1)

const mockMwsServiceStatus = new MWS(
new HttpClient(httpConfig, () =>
Promise.resolve({
data: getFixture('get_service_status'),
headers,
}),
),
)
const mockMwsServiceStatus = createMockHttpClient('get_service_status')

expect(await mockMwsServiceStatus.sellers.getServiceStatus()).toMatchSnapshot()
expect(await mockMwsServiceStatus.finances.getServiceStatus()).toMatchSnapshot()
})

it('throws a parsing error when the status response is not valid', async () => {
expect.assertions(1)

await expect(() => mockMwsFail.sellers.getServiceStatus()).rejects.toStrictEqual(
await expect(() => mockMwsFail.finances.getServiceStatus()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
Expand Down

0 comments on commit 0ab2f7f

Please sign in to comment.