Skip to content

Commit

Permalink
feat: change KeywordState, KeywordMatchType, KeywordServingStatus and…
Browse files Browse the repository at this point in the history
… KeywordResponseStatus to use union string
  • Loading branch information
nguyentoanit committed Apr 20, 2020
1 parent 8356e9c commit dbde3fe
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 71 deletions.
77 changes: 38 additions & 39 deletions src/operations/keywords/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,47 @@ export type KeywordIds = t.TypeOf<typeof KeywordIds>
/**
* Advertiser-specified state of the keyword
*/
export enum KeywordStateEnum {
ENABLED = 'enabled',
PAUSED = 'paused',
ARCHIVED = 'archived',
}
export const KeywordStateType = createEnumType<KeywordStateEnum>(KeywordStateEnum)
export const KeywordState = t.union([
t.literal('enabled'),
t.literal('paused'),
t.literal('archived'),
])
export type KeywordState = t.TypeOf<typeof KeywordState>

/**
* The match type used to match the keyword to search query
*/
export enum KeywordMatchTypeEnum {
EXACT = 'exact',
PHRASE = 'phrase',
BROAD = 'broad',
}
export const KeywordMatchType = createEnumType<KeywordMatchTypeEnum>(KeywordMatchTypeEnum)
export const KeywordMatchType = t.union([
t.literal('exact'),
t.literal('phrase'),
t.literal('broad'),
])
export type KeywordMatchType = t.TypeOf<typeof KeywordMatchType>

/**
* The computed status, accounting for out of budget, policy violations, etc.
* See developer notes for more information.
*/
export enum KeywordServingStatusEnum {
TARGETING_CLAUSE_ARCHIVED = 'TARGETING_CLAUSE_ARCHIVED',
TARGETING_CLAUSE_PAUSED = 'TARGETING_CLAUSE_PAUSED',
TARGETING_CLAUSE_STATUS_LIVE = 'TARGETING_CLAUSE_STATUS_LIVE',
TARGETING_CLAUSE_POLICING_SUSPENDED = 'TARGETING_CLAUSE_POLICING_SUSPENDED',
CAMPAIGN_OUT_OF_BUDGET = 'CAMPAIGN_OUT_OF_BUDGET',
AD_GROUP_PAUSED = 'AD_GROUP_PAUSED',
AD_GROUP_ARCHIVED = 'AD_GROUP_ARCHIVED',
CAMPAIGN_PAUSED = 'CAMPAIGN_PAUSED',
CAMPAIGN_ARCHIVED = 'CAMPAIGN_ARCHIVED',
ACCOUNT_OUT_OF_BUDGET = 'ACCOUNT_OUT_OF_BUDGET',
}
export const KeywordServingStatusType = createEnumType<KeywordServingStatusEnum>(
KeywordServingStatusEnum,
)
export const KeywordServingStatus = t.union([
t.literal('TARGETING_CLAUSE_ARCHIVED'),
t.literal('TARGETING_CLAUSE_PAUSED'),
t.literal('TARGETING_CLAUSE_STATUS_LIVE'),
t.literal('TARGETING_CLAUSE_POLICING_SUSPENDED'),
t.literal('CAMPAIGN_OUT_OF_BUDGET'),
t.literal('AD_GROUP_PAUSED'),
t.literal('AD_GROUP_ARCHIVED'),
t.literal('CAMPAIGN_PAUSED'),
t.literal('CAMPAIGN_ARCHIVED'),
t.literal('ACCOUNT_OUT_OF_BUDGET'),
])
export type KeywordServingStatus = t.TypeOf<typeof KeywordServingStatus>

export enum KeywordResponseStatusEnum {
SUCCESS = 'SUCCESS',
INVALID_ARGUMENT = 'INVALID_ARGUMENT',
NOT_FOUND = 'NOT_FOUND',
}
export const KeywordResponseStatus = t.union([
t.literal('SUCCESS'),
t.literal('INVALID_ARGUMENT'),
t.literal('NOT_FOUND'),
])
export type KeywordResponseStatus = t.TypeOf<typeof KeywordResponseStatus>

export const Keyword = t.intersection([
t.strict({
Expand All @@ -76,7 +75,7 @@ export const Keyword = t.intersection([
/**
* Advertiser-specified state of the keyword
*/
state: KeywordStateType,
state: KeywordState,

/**
* The expression to match against search queries
Expand Down Expand Up @@ -114,7 +113,7 @@ export const KeywordExtended = t.intersection([
/**
* The computed status, accounting for campaign out of budget, policy violations, etc. See developer notes for more information.
*/
servingStatus: KeywordServingStatusType,
servingStatus: KeywordServingStatus,
}),
])
export type KeywordExtended = t.TypeOf<typeof KeywordExtended>
Expand All @@ -129,7 +128,7 @@ export const KeywordResponse = t.intersection([
/**
* An enumerated success or error code for machine use.
*/
code: t.string,
code: KeywordResponseStatus,
}),
t.partial({
/**
Expand All @@ -149,14 +148,14 @@ export const CreateKeywordsParam = t.strict({

matchType: KeywordMatchType,

state: KeywordStateType,
state: KeywordState,
})
export type CreateKeywordsParam = t.TypeOf<typeof CreateKeywordsParam>

export const UpdateKeywordsParam = t.strict({
keywordId: KeywordId,

state: KeywordStateType,
state: KeywordState,

bid: t.number,
})
Expand All @@ -180,7 +179,7 @@ export const ListBiddableKeywordsParam = t.intersection([
* Optional. Restricts results to keywords with state within the specified comma-separated list.
* Must be one of: enabled, paused, or archived. Default behavior is to include all.
*/
stateFilter: KeywordStateType,
stateFilter: KeywordState,

/**
* Optional. Restricts results to keywords within campaigns specified in comma-separated list.
Expand Down Expand Up @@ -741,7 +740,7 @@ export const ListSponsoredBrandsKeywordParams = t.intersection([
/**
* The returned array includes only keywords with state set to the specified value.
*/
stateFilter: KeywordStateType,
stateFilter: KeywordState,

/**
* The returned array includes only keywords associated with campaigns matching those specified by identifier in the comma-delimited string.
Expand Down
8 changes: 4 additions & 4 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ describe('index', () => {
expect(index.CampaignNegativeKeywordStateEnum).toEqual(
keywordEnum.CampaignNegativeKeywordStateEnum,
)
expect(index.KeywordMatchTypeEnum).toEqual(keywordEnum.KeywordMatchTypeEnum)
expect(index.KeywordResponseStatusEnum).toEqual(keywordEnum.KeywordResponseStatusEnum)
expect(index.KeywordServingStatusEnum).toEqual(keywordEnum.KeywordServingStatusEnum)
expect(index.KeywordStateEnum).toEqual(keywordEnum.KeywordStateEnum)
expect(index.KeywordMatchType).toEqual(keywordEnum.KeywordMatchType)
expect(index.KeywordResponseStatus).toEqual(keywordEnum.KeywordResponseStatus)
expect(index.KeywordServingStatus).toEqual(keywordEnum.KeywordServingStatus)
expect(index.KeywordState).toEqual(keywordEnum.KeywordState)
expect(index.NegativeKeywordMatchTypeEnum).toEqual(keywordEnum.NegativeKeywordMatchTypeEnum)
expect(index.NegativeKeywordResponseStatusEnum).toEqual(
keywordEnum.NegativeKeywordResponseStatusEnum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {
SponsoredBrandsListDraftCampaignRequest,
SponsoredBrandsDraftCampaignId,
} from '../../../src/operations/drafts/types'
import {
KeywordMatchTypeEnum,
NegativeKeywordMatchTypeEnum,
} from '../../../src/operations/keywords/types'
import { NegativeKeywordMatchTypeEnum } from '../../../src/operations/keywords/types'

/**
* TODO: Need check on Production API again. Sandbox API return error:
Expand Down Expand Up @@ -64,7 +61,7 @@ describe.skip('SponsoredBrandsDraftsOperation', () => {
keywords: [
{
keywordText: 'string1',
matchType: KeywordMatchTypeEnum.BROAD,
matchType: 'broad',
bid: 1,
},
],
Expand Down Expand Up @@ -110,7 +107,7 @@ describe.skip('SponsoredBrandsDraftsOperation', () => {
keywords: [
{
keywordText: 'string1',
matchType: KeywordMatchTypeEnum.BROAD,
matchType: 'broad',
bid: 1,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { httpClientFactory } from '../../http-client-factory'
import { OperationProvider } from '../../../src'
import {
CreateSponsoredBrandsKeywordParams,
KeywordMatchTypeEnum,
KeywordResponseStatusEnum,
SponsoredBrandsKeyword,
ListSponsoredBrandsKeywordParams,
KeywordStateEnum,
UpdateSponsoredBrandsKeywordParams,
SponsoredBrandsKeywordStateEnum,
SponsoredBrandsKeywordResponse,
KeywordResponseStatus,
KeywordMatchType,
} from '../../../src/operations/keywords/types'

// TODO: Need check operations again because creating sb keyword is not available for test api
Expand All @@ -35,9 +34,9 @@ describe('SponsoredBrandsKeywordsOperation', () => {
const params: ListSponsoredBrandsKeywordParams = {
startIndex: 0,
count: 1,
matchTypeFilter: [KeywordMatchTypeEnum.PHRASE],
matchTypeFilter: ['phrase'],
keywordText: KEYWORD_TEXT,
stateFilter: KeywordStateEnum.PAUSED,
stateFilter: 'paused',
campaignIdFilter: [CAMPAIGN_ID],
adGroupIdFilter: [AD_GROUP_ID],
}
Expand Down Expand Up @@ -71,13 +70,13 @@ describe('SponsoredBrandsKeywordsOperation', () => {
adGroupId: AD_GROUP_ID,
campaignId: CAMPAIGN_ID,
keywordText: KEYWORD_TEXT,
matchType: KeywordMatchTypeEnum.BROAD,
matchType: 'broad',
bid: BID,
},
]
const [res] = await operation.createKeywords(params)

expect(res.code).toEqual(KeywordResponseStatusEnum.SUCCESS)
expect(res.code).toEqual<KeywordResponseStatus>('SUCCESS')
})
})

Expand All @@ -89,7 +88,7 @@ describe('SponsoredBrandsKeywordsOperation', () => {
expect(res.adGroupId).toBe(AD_GROUP_ID)
expect(res.keywordId).toBe(KEYWORD_ID)
expect(res.keywordText).toBe(KEYWORD_TEXT)
expect(res.matchType).toBe(KeywordMatchTypeEnum.BROAD)
expect(res.matchType).toBe<KeywordMatchType>('broad')
expect(res.bid).toEqual(BID)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { OperationProvider } from '../../../src'
import {
Keyword,
CreateKeywordsParam,
KeywordMatchTypeEnum,
KeywordStateEnum,
KeywordResponseStatusEnum,
KeywordExtended,
UpdateKeywordsParam,
KeywordResponseStatus,
} from '../../../src/operations/keywords/types'

describe('SponsoredProductsAdGroupKeywordsOperation', () => {
Expand Down Expand Up @@ -56,13 +54,13 @@ describe('SponsoredProductsAdGroupKeywordsOperation', () => {
campaignId: MANUAL_CAMPAIGN_ID,
adGroupId: MANUAL_AD_GROUP_ID,
keywordText: 'Apple',
matchType: KeywordMatchTypeEnum.BROAD,
state: KeywordStateEnum.PAUSED,
matchType: 'broad',
state: 'paused',
},
]
const [res] = await operation.createKeywords(params)

expect(res.code).toEqual(KeywordResponseStatusEnum.SUCCESS)
expect(res.code).toEqual<KeywordResponseStatus>('SUCCESS')
})
})

Expand All @@ -71,21 +69,21 @@ describe('SponsoredProductsAdGroupKeywordsOperation', () => {
const params: UpdateKeywordsParam[] = [
{
keywordId: PAUSED_KEYWORD_ID,
state: KeywordStateEnum.PAUSED,
state: 'paused',
bid: 1,
},
]
const [res] = await operation.updateKeywords(params)

expect(res.code).toEqual(KeywordResponseStatusEnum.SUCCESS)
expect(res.code).toEqual<KeywordResponseStatus>('SUCCESS')
})
})

describe('archiveBiddableKeyword', () => {
it(`should archive a keyword`, async () => {
const res = await operation.archiveBiddableKeyword(ARCHIVED_KEYWORD_ID)

expect(res.code).toEqual(KeywordResponseStatusEnum.SUCCESS)
expect(res.code).toEqual<KeywordResponseStatus>('SUCCESS')
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { SponsoredBrandsBidRecommendationsOperation } from '../../../src/operati
import { httpClientFactory } from '../../http-client-factory'
import { SponsoredBrandsBidsRecommendationRequest } from '../../../src/operations/recommendations/types'
import { ProductPredicateTypeEnum } from '../../../src/operations/product-targeting/types'
import { KeywordMatchTypeEnum } from '../../../src/operations/keywords/types'

/**
* TODO: Need check again on Production API. Sandbox API returns an error:
Expand All @@ -26,7 +25,7 @@ describe.skip('SponsoredBrandsBidRecommendationsOperation', () => {
],
keywords: [
{
matchType: KeywordMatchTypeEnum.BROAD,
matchType: 'broad',
keywordText: 'string',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SnapshotStatusEnum,
SuccessSnapshotResponse,
} from '../../../src/operations/snapshots/types'
import { Keyword, KeywordMatchTypeEnum, KeywordStateEnum } from '../../../src'
import { Keyword, KeywordMatchType, KeywordState } from '../../../src'

describe('SponsoredProductsSnapshotOperation', () => {
const client = httpClientFactory()
Expand All @@ -32,8 +32,8 @@ describe('SponsoredProductsSnapshotOperation', () => {
expect(res.campaignId).toEqual(164069484151709)
expect(res.keywordId).toEqual(239748696088896)
expect(res.keywordText).toEqual('Apple')
expect(res.matchType).toEqual(KeywordMatchTypeEnum.BROAD)
expect(res.state).toEqual(KeywordStateEnum.PAUSED)
expect(res.matchType).toEqual<KeywordMatchType>('broad')
expect(res.state).toEqual<KeywordState>('paused')
})
})

Expand Down

0 comments on commit dbde3fe

Please sign in to comment.