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

Commit

Permalink
fix: apis with optional params not required to pass in argument
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 12, 2020
1 parent 5d67d38 commit e9c24d6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 65 deletions.
14 changes: 7 additions & 7 deletions src/sections/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export class Reports {
constructor(private httpClient: HttpClient) {}

async getReportScheduleCount(
parameters: GetReportScheduleCountParameters,
parameters: GetReportScheduleCountParameters = {},
): Promise<[GetReportScheduleCount, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Reports,
Expand All @@ -337,7 +337,7 @@ export class Reports {
*/

async getReportScheduleList(
parameters: GetReportScheduleListParameters,
parameters: GetReportScheduleListParameters = {},
): Promise<[GetReportScheduleList, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Reports,
Expand Down Expand Up @@ -395,7 +395,7 @@ export class Reports {
}

async getReportCount(
parameters: GetReportCountParameters,
parameters: GetReportCountParameters = {},
): Promise<[GetReportCount, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Reports,
Expand Down Expand Up @@ -438,7 +438,7 @@ export class Reports {
}

async getReportList(
parameters: GetReportListParameters,
parameters: GetReportListParameters = {},
): Promise<[GetReportListResult, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Reports,
Expand All @@ -463,7 +463,7 @@ export class Reports {
}

async cancelReportRequests(
parameters: CancelReportRequestsParameters,
parameters: CancelReportRequestsParameters = {},
): Promise<[CancelReportRequests, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Reports,
Expand All @@ -487,7 +487,7 @@ export class Reports {
}

async getReportRequestCount(
parameters: GetReportRequestCountParameters,
parameters: GetReportRequestCountParameters = {},
): Promise<[GetReportRequestCount, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Reports,
Expand Down Expand Up @@ -533,7 +533,7 @@ export class Reports {
}

async getReportRequestList(
parameters: GetReportRequestListParameters,
parameters: GetReportRequestListParameters = {},
): Promise<[GetReportRequestListResult, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Reports,
Expand Down
12 changes: 6 additions & 6 deletions test/integration/reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,39 @@ describe('reports', () => {
itci('should succesfully get report schedule count', async () => {
expect.assertions(1)

const [response] = await reports.getReportScheduleCount({})
const [response] = await reports.getReportScheduleCount()

expect(typeof response.Count).toBe('number')
})

itci('should succesfully get report schedule list', async () => {
expect.assertions(1)

const [response] = await reports.getReportScheduleList({})
const [response] = await reports.getReportScheduleList()

expect(response).toBeDefined()
})

itci('should be able to query get report count', async () => {
expect.assertions(1)

const [response] = await reports.getReportCount({})
const [response] = await reports.getReportCount()

expect(typeof response.Count).toBe('number')
})

itci('should be able to query get report request count', async () => {
expect.assertions(1)

const [response] = await reports.getReportRequestCount({})
const [response] = await reports.getReportRequestCount()

expect(typeof response.Count).toBe('number')
})

itci('should be able to query get report request list', async () => {
expect.assertions(1)

const [response] = await reports.getReportRequestList({})
const [response] = await reports.getReportRequestList()

expect(response).toBeDefined()
})
Expand All @@ -69,7 +69,7 @@ describe('reports', () => {
itci('should be able to query get report list', async () => {
expect.assertions(1)

const [response] = await reports.getReportList({})
const [response] = await reports.getReportList()

expect(response).toBeDefined()
})
Expand Down
78 changes: 26 additions & 52 deletions test/unit/reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,46 +38,38 @@ const mockMwsFail = new MWS(

describe('reports', () => {
describe('getReportScheduleCount', () => {
const parameters = {}

it('returns a count of schedule reports if succesful', async () => {
expect.assertions(1)

const mockGetReportScheduleCount = createMockHttpClient('reports_get_report_schedule_count')

expect(
await mockGetReportScheduleCount.reports.getReportScheduleCount(parameters),
).toMatchSnapshot()
expect(await mockGetReportScheduleCount.reports.getReportScheduleCount()).toMatchSnapshot()
})

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

await expect(() =>
mockMwsFail.reports.getReportScheduleCount(parameters),
).rejects.toStrictEqual(new ParsingError(parsingError))
await expect(() => mockMwsFail.reports.getReportScheduleCount()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})

describe('getReportScheduleList', () => {
const parameters = {}

it('returns detailed information about a report schedule if succesful', async () => {
expect.assertions(1)

const mockGetReportScheduleList = createMockHttpClient('reports_get_report_schedule_list')

expect(
await mockGetReportScheduleList.reports.getReportScheduleList(parameters),
).toMatchSnapshot()
expect(await mockGetReportScheduleList.reports.getReportScheduleList()).toMatchSnapshot()
})

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

await expect(() =>
mockMwsFail.reports.getReportScheduleList(parameters),
).rejects.toStrictEqual(new ParsingError(parsingError))
await expect(() => mockMwsFail.reports.getReportScheduleList()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})

Expand Down Expand Up @@ -132,20 +124,18 @@ describe('reports', () => {
})

describe('getReportCount', () => {
const parameters = {}

it('returns report count if succesful', async () => {
expect.assertions(1)

const mockGetReportCount = createMockHttpClient('reports_get_report_count')

expect(await mockGetReportCount.reports.getReportCount(parameters)).toMatchSnapshot()
expect(await mockGetReportCount.reports.getReportCount()).toMatchSnapshot()
})

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

await expect(() => mockMwsFail.reports.getReportCount(parameters)).rejects.toStrictEqual(
await expect(() => mockMwsFail.reports.getReportCount()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
Expand Down Expand Up @@ -177,74 +167,64 @@ describe('reports', () => {
})

describe('getReportList', () => {
const parameters = {}

it('should properly return report list for multiple reports', async () => {
expect.assertions(1)

const mockGetReportList = createMockHttpClient('reports_get_report_list_multiple')

expect(await mockGetReportList.reports.getReportList(parameters)).toMatchSnapshot()
expect(await mockGetReportList.reports.getReportList()).toMatchSnapshot()
})

it('should properly return report list for a single report', async () => {
expect.assertions(1)

const mockGetReportList = createMockHttpClient('reports_get_report_list')

expect(await mockGetReportList.reports.getReportList(parameters)).toMatchSnapshot()
expect(await mockGetReportList.reports.getReportList()).toMatchSnapshot()
})

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

await expect(() => mockMwsFail.reports.getReportList(parameters)).rejects.toStrictEqual(
await expect(() => mockMwsFail.reports.getReportList()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})

describe('cancelReportRequests', () => {
const parameters = {}

it('returns count and detailed info of cancelled requests if succesful', async () => {
expect.assertions(1)

const mockCancelReportRequests = createMockHttpClient('reports_cancel_report_requests')

expect(
await mockCancelReportRequests.reports.cancelReportRequests(parameters),
).toMatchSnapshot()
expect(await mockCancelReportRequests.reports.cancelReportRequests()).toMatchSnapshot()
})

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

await expect(() =>
mockMwsFail.reports.cancelReportRequests(parameters),
).rejects.toStrictEqual(new ParsingError(parsingError))
await expect(() => mockMwsFail.reports.cancelReportRequests()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})

describe('getReportRequestCount', () => {
const parameters = {}

it('returns report request count if succesful', async () => {
expect.assertions(1)

const mockGetReportRequestCount = createMockHttpClient('reports_get_report_request_count')

expect(
await mockGetReportRequestCount.reports.getReportRequestCount(parameters),
).toMatchSnapshot()
expect(await mockGetReportRequestCount.reports.getReportRequestCount()).toMatchSnapshot()
})

it("throws a parsing error when the response isn't valid", async () => {
expect.assertions(1)

await expect(() =>
mockMwsFail.reports.getReportRequestCount(parameters),
).rejects.toStrictEqual(new ParsingError(parsingError))
await expect(() => mockMwsFail.reports.getReportRequestCount()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})

Expand Down Expand Up @@ -278,16 +258,12 @@ describe('reports', () => {
})

describe('getReportRequestList', () => {
const parameters = {}

it('returns report request info succesfully for responses with a single report', async () => {
expect.assertions(1)

const mockGetReportRequestList = createMockHttpClient('reports_get_report_request_list')

expect(
await mockGetReportRequestList.reports.getReportRequestList(parameters),
).toMatchSnapshot()
expect(await mockGetReportRequestList.reports.getReportRequestList()).toMatchSnapshot()
})

it('returns report request info succesfully for responses with multiple reports', async () => {
Expand All @@ -297,17 +273,15 @@ describe('reports', () => {
'reports_get_report_request_list_multiple',
)

expect(
await mockGetReportRequestList.reports.getReportRequestList(parameters),
).toMatchSnapshot()
expect(await mockGetReportRequestList.reports.getReportRequestList()).toMatchSnapshot()
})

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

await expect(() =>
mockMwsFail.reports.getReportRequestList(parameters),
).rejects.toStrictEqual(new ParsingError(parsingError))
await expect(() => mockMwsFail.reports.getReportRequestList()).rejects.toStrictEqual(
new ParsingError(parsingError),
)
})
})

Expand Down

0 comments on commit e9c24d6

Please sign in to comment.