diff --git a/src/operations/bidding/types.ts b/src/operations/bidding/types.ts index bb3593a96..b3af69740 100644 --- a/src/operations/bidding/types.ts +++ b/src/operations/bidding/types.ts @@ -9,19 +9,6 @@ export const KeywordBidRecommendationsMatchType = t.union([ ]) export type KeywordBidRecommendationsMatchType = t.TypeOf -/** - * The resulting status code for retrieving the bid. - */ -export const BidRecommendationsResponseCode = t.union([ - t.literal('SUCCESS'), - t.literal('INVALID_ARGUMENT'), - t.literal('NOT_FOUND'), - t.literal('INTERNAL_ERROR'), - t.literal('SERVER_IS_BUSY'), - t.literal('UNAUTHORIZED'), -]) -export type BidRecommendationsResponseCode = t.TypeOf - export const BidRecommendationsKeyword = t.strict({ /** * The keyword text. @@ -89,26 +76,33 @@ export const KeywordBidRecommendationsData = t.strict({ }) export type KeywordBidRecommendationsData = t.TypeOf +const BidRecommendationSuccesResponse = t.intersection([ + t.strict({ + /** + * The resulting status code for retrieving the bid. + */ + code: t.literal('SUCCESS'), + + suggestedBid: SuggestedBid, + }), + + BidRecommendationsKeyword, +]) + +const BidRecommendationNotFound = t.strict({ + /** + * The response code + */ + code: t.literal('NOT_FOUND'), +}) + export const BidRecommendationsResponse = t.strict({ /** * The ID of the ad group that a bid was requested for. */ adGroupId: AdGroupId, - recommendations: t.array( - t.intersection([ - t.strict({ - /** - * The resulting status code for retrieving the bid. - */ - code: BidRecommendationsResponseCode, - - suggestedBid: SuggestedBid, - }), - - BidRecommendationsKeyword, - ]), - ), + recommendations: t.array(t.union([BidRecommendationSuccesResponse, BidRecommendationNotFound])), }) export type BidRecommendationsResponse = t.TypeOf @@ -180,7 +174,7 @@ export const BidRecommendationRequest = t.strict({ }) export type BidRecommendationRequest = t.TypeOf -export const BidRecommendationList = t.strict({ +const BidRecommendationForTargetsSuccess = t.strict({ /** * The suggested bid */ @@ -194,9 +188,46 @@ export const BidRecommendationList = t.strict({ /** * The response code */ - code: BidRecommendationsResponseCode, + code: t.literal('SUCCESS'), }) +const BidRecommendationInvalidArgument = t.strict({ + /** + * The response code + */ + code: t.literal('INVALID_ARGUMENT'), +}) + +const BidRecommendationInternalError = t.strict({ + /** + * The response code + */ + code: t.literal('INTERNAL_ERROR'), +}) + +const BidRecommendationServerIsBusy = t.strict({ + /** + * The response code + */ + code: t.literal('SERVER_IS_BUSY'), +}) + +const BidRecommendationUnauthorized = t.strict({ + /** + * The response code + */ + code: t.literal('UNAUTHORIZED'), +}) + +export const BidRecommendationList = t.union([ + BidRecommendationForTargetsSuccess, + BidRecommendationInvalidArgument, + BidRecommendationNotFound, + BidRecommendationInternalError, + BidRecommendationServerIsBusy, + BidRecommendationUnauthorized, +]) + export const BidRecommendationLists = t.array(BidRecommendationList) /** diff --git a/test/index.test.ts b/test/index.test.ts index beed47d01..07d329bb3 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -34,9 +34,6 @@ describe('index', () => { it('should export all enums', () => { expect(index.CampaignBiddingAdjustmentsPredicate).toEqual(CampaignBiddingAdjustmentsPredicate) expect(index.CampaignBiddingStrategy).toEqual(CampaignBiddingStrategy) - expect(index.BidRecommendationsResponseCode).toEqual( - biddingTypes.BidRecommendationsResponseCode, - ) expect(index.BiddingAutoPredicateType).toEqual(biddingTypes.BiddingAutoPredicateType) expect(index.BiddingKeywordPredicateType).toEqual(biddingTypes.BiddingKeywordPredicateType) expect(index.BiddingProductPredicateType).toEqual(biddingTypes.BiddingProductPredicateType) diff --git a/test/operations/bidding/sponsored-products-bid-recommendation-operation.test.ts b/test/operations/bidding/sponsored-products-bid-recommendation-operation.test.ts index 63306ab9f..2eeed7ddb 100644 --- a/test/operations/bidding/sponsored-products-bid-recommendation-operation.test.ts +++ b/test/operations/bidding/sponsored-products-bid-recommendation-operation.test.ts @@ -3,7 +3,6 @@ import { httpClientFactory } from '../../http-client-factory' import { SponsoredProductsBidRecommendationOperation } from '../../../src/operations/bidding/sponsored-products-bid-recommendation-operation' import { KeywordBidRecommendationsData, - BidRecommendationsResponseCode, KeywordBidRecommendationsMatchType, BidRecommendationRequest, } from '../../../src' @@ -35,6 +34,8 @@ describe('SponsoredProductsBidRecommendationOperation', () => { describe('createKeywordBidRecommendations', () => { it(`should retrieve keyword bid recommendation data for one or more keywords`, async () => { + expect.assertions(3) + const params: KeywordBidRecommendationsData = { adGroupId: MANUAL_AD_GROUP_ID, keywords: [ @@ -56,9 +57,10 @@ describe('SponsoredProductsBidRecommendationOperation', () => { const [recommendation] = res.recommendations expect(res.adGroupId).toBe(MANUAL_AD_GROUP_ID) - expect(recommendation.code).toBe('SUCCESS') - expect(recommendation.keyword).toBe('Apple1') - expect(recommendation.matchType).toBe('broad') + if (recommendation.code == 'SUCCESS') { + expect(recommendation.keyword).toBe('Apple1') + expect(recommendation.matchType).toBe('broad') + } }) }) @@ -69,6 +71,7 @@ describe('SponsoredProductsBidRecommendationOperation', () => { */ describe.skip('getBidRecommendations', () => { it(`should retrieve a list of bid recommendations for keyword, product or auto targeting expressions by adGroupId`, async () => { + expect.assertions(3) const EXPRESSION_VALUE = 'Apple' const EXPRESSION_TYPE = 'queryBroadRelMatches' @@ -85,9 +88,10 @@ describe('SponsoredProductsBidRecommendationOperation', () => { const [recommendation] = res.recommendations expect(res.adGroupId).toBe(AUTO_AD_GROUP_ID) - expect(recommendation.code).toBe('SUCCESS') - expect(recommendation.expression.value).toBe(EXPRESSION_VALUE) - expect(recommendation.expression.type).toBe(EXPRESSION_TYPE) + if (recommendation.code == 'SUCCESS') { + expect(recommendation.expression.value).toBe(EXPRESSION_VALUE) + expect(recommendation.expression.type).toBe(EXPRESSION_TYPE) + } }) }) })