Skip to content

Commit

Permalink
feat: change ReportResponseStatus to union string
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyentoanit committed Apr 20, 2020
1 parent 25aebe3 commit a752f6c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 33 deletions.
20 changes: 7 additions & 13 deletions src/operations/reports/report-response.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import * as t from 'io-ts'
import { createEnumType } from '../commons/types'

export enum ReportResponseStatusEnum {
IN_PROGRESS = 'IN_PROGRESS',
SUCCESS = 'SUCCESS',
FAILURE = 'FAILURE',
}

export const ReportResponseStatusType = createEnumType<ReportResponseStatusEnum>(
ReportResponseStatusEnum,
)
export type ReportResponseStatusType = t.TypeOf<typeof ReportResponseStatusType>
export const ReportResponseStatus = t.union([
t.literal('IN_PROGRESS'),
t.literal('SUCCESS'),
t.literal('FAILURE'),
])
export type ReportResponseStatus = t.TypeOf<typeof ReportResponseStatus>

export const ReportId = t.string
export type ReportId = t.TypeOf<typeof ReportId>
Expand All @@ -25,7 +20,7 @@ export const ReportResponse = t.intersection([
/**
* The status of the generation of the report, it can be IN_PROGRESS, SUCCESS or FAILURE.
*/
status: ReportResponseStatusType,
status: ReportResponseStatus,

/**
* Description of the status.
Expand All @@ -49,5 +44,4 @@ export const ReportResponse = t.intersection([
fileSize: t.number,
}),
])

export type ReportResponse = t.TypeOf<typeof ReportResponse>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { omit } from 'lodash'
import { Decode } from '../../../decorators'
import { BaseReportOperation } from '../base-report-operation'
import { ReportResponse, ReportResponseStatusEnum } from '../report-response'
import { ReportResponse } from '../report-response'
import { SponsoredProductsAdGroupReportParams } from './sponsored-products-ad-group-report-params'
import { SponsoredProductsAsinsReportParams } from './sponsored-products-asins-report-params'
import { SponsoredProductsCampaignReportParams } from './sponsored-products-campaign-report-params'
Expand All @@ -24,7 +24,7 @@ type SponsoredProductsReportParams =
* And in the case of ASIN report, it returns `otherAsin` for some reason.
*/
function fixRecordTypeResponse(res: ReportResponse): ReportResponse {
if (res.status === ReportResponseStatusEnum.SUCCESS) {
if (res.status === 'SUCCESS') {
return res
}

Expand Down
3 changes: 1 addition & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,12 @@ describe('index', () => {
expect(index.SponsoredProductsProductTargetingReportMetrics).toEqual(
reportEnum.SponsoredProductsProductTargetingReportMetrics,
)
expect(index.ReportResponseStatusEnum).toEqual(reportEnum.ReportResponseStatusEnum)
expect(index.ReportResponseStatus).toEqual(reportEnum.ReportResponseStatus)
expect(index.ReportSegmentsEnum).toEqual(reportEnum.ReportSegmentsEnum)
expect(index.SponsoredBrandsReportTypeEnum).toEqual(reportEnum.SponsoredBrandsReportTypeEnum)
expect(index.SponsoredProductsReportTypeEnum).toEqual(
reportEnum.SponsoredProductsReportTypeEnum,
)
expect(index.ReportResponseStatusType).toEqual(reportEnum.ReportResponseStatusType)
expect(index.SponsoredBrandsAdGroupReportMetrics).toEqual(
reportEnum.SponsoredBrandsAdGroupReportMetrics,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OperationProvider } from '../../../../src/operations/operation-provider
import { httpClientFactory } from '../../../http-client-factory'
import { SponsoredBrandsReportOperation } from '../../../../src/operations/reports/sponsored-brands/sponsored-brands-report-operation'
import { SponsoredBrandsReportTypeEnum } from '../../../../src/operations/reports/report-types-enum'
import { ReportResponseStatusEnum } from '../../../../src/operations/reports/report-response'
import { ReportResponseStatus } from '../../../../src'

jest.setTimeout(15000)

Expand All @@ -21,7 +21,7 @@ describe('SponsoredBrandsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand All @@ -42,7 +42,7 @@ describe('SponsoredBrandsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand All @@ -67,7 +67,7 @@ describe('SponsoredBrandsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand Down Expand Up @@ -95,7 +95,7 @@ describe('SponsoredBrandsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand Down Expand Up @@ -124,7 +124,7 @@ describe('SponsoredBrandsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand All @@ -148,7 +148,7 @@ describe('SponsoredBrandsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})
})
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('SponsoredBrandsReportOperation', () => {
expect(res.reportId).toBeDefined()
expect(res.statusDetails).toBeDefined()

if (res.status == ReportResponseStatusEnum.SUCCESS) {
if (res.status == 'SUCCESS') {
expect(res.location).toBeDefined()
expect(res.fileSize).toBeDefined()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { OperationProvider } from '../../../../src/operations/operation-provider
import { httpClientFactory } from '../../../http-client-factory'
import { SponsoredProductsReportOperation } from '../../../../src/operations/reports/sponsored-products/sponsored-products-report-operation'
import { SponsoredProductsReportTypeEnum } from '../../../../src/operations/reports/report-types-enum'
import { ReportResponseStatusEnum } from '../../../../src/operations/reports/report-response'
import { ReportResponseStatus } from '../../../../src/operations/reports/report-response'

jest.setTimeout(15000)

Expand All @@ -21,7 +21,7 @@ describe('SponsoredProductsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand All @@ -34,7 +34,7 @@ describe('SponsoredProductsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand All @@ -47,7 +47,7 @@ describe('SponsoredProductsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand All @@ -60,7 +60,7 @@ describe('SponsoredProductsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand All @@ -73,7 +73,7 @@ describe('SponsoredProductsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})

Expand All @@ -86,7 +86,7 @@ describe('SponsoredProductsReportOperation', () => {

expect(res.reportId).toBeDefined()
expect(res.recordType).toBeDefined()
expect(res.status).toBe(ReportResponseStatusEnum.IN_PROGRESS)
expect(res.status).toBe<ReportResponseStatus>('IN_PROGRESS')
expect(res.statusDetails).toBeDefined()
})
})
Expand All @@ -104,7 +104,7 @@ describe('SponsoredProductsReportOperation', () => {
expect(res.reportId).toBeDefined()
expect(res.statusDetails).toBeDefined()

if (res.status == ReportResponseStatusEnum.SUCCESS) {
if (res.status == 'SUCCESS') {
expect(res.location).toBeDefined()
expect(res.fileSize).toBeDefined()
}
Expand Down

0 comments on commit a752f6c

Please sign in to comment.