Skip to content

Commit

Permalink
feat: remove un-available methods and attributes of sb campaign opera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
nguyentoanit committed Apr 20, 2020
1 parent be65b05 commit fb1fa27
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 62 deletions.
46 changes: 11 additions & 35 deletions src/operations/campaigns/sponsored-brands-campaign-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,50 @@ import { Decode, DecodeArray } from '../../decorators'
import { AmazonAdTypeURIPrefix } from '../amazon-ad-type-uri-prefix'

import {
Campaign,
ListCampaignsParams,
CampaignId,
CampaignResponse,
SponsoredBrandsCampaignUpdateParams,
CampaignExtended,
SponsoredBrandsCampaignCreateParams,
SponsoredBrandsCampaign,
} from './types'

export class SponsoredBrandsCampaignOperation extends Operation {
protected resource = `${this.version}/${AmazonAdTypeURIPrefix.SponsoredBrands}/campaigns`

/**
* Gets an array of all campaigns associated with the client identifier passed in the authorization header, filtered by specified criteria.
*
* @param {ListCampaignsParams} [params]
* @returns
* @memberof SponsoredBrandsCampaignOperation
*/
@DecodeArray(Campaign)
public listCampaigns(params?: ListCampaignsParams) {
return this.client.get<Campaign[]>(this.paramsFilterTransformer('', params))
}

/**
* Gets an array of all campaigns with extended fields associated with the client identifier passed in the authorization header, filtered by specified criteria.
*
* @param {ListCampaignsParams} [params]
* @returns
* @memberof SponsoredBrandsCampaignOperation
*/
@DecodeArray(CampaignExtended)
public listCampaignsEx(params?: ListCampaignsParams) {
return this.client.get<CampaignExtended[]>(this.paramsFilterTransformer('/extended', params))
}

/**
* Gets a campaign specified by identifier
*
* @param {CampaignId} campaignId
* @returns
* @memberof SponsoredBrandsCampaignOperation
*/
@Decode(Campaign)
@Decode(SponsoredBrandsCampaign)
public getCampaign(campaignId: CampaignId) {
return this.client.get<Campaign>(`${this.resource}/${campaignId}`)
return this.client.get<SponsoredBrandsCampaign>(`${this.resource}/${campaignId}`)
}

/**
* Gets a campaign with extended fields specified by identifier
* Gets an array of all campaigns associated with the client identifier passed in the authorization header, filtered by specified criteria.
*
* @param {CampaignId} campaignId
* @param {ListCampaignsParams} [params]
* @returns
* @memberof SponsoredBrandsCampaignOperation
*/
@Decode(CampaignExtended)
public getCampaignEx(campaignId: CampaignId) {
return this.client.get<CampaignExtended>(`${this.resource}/extended/${campaignId}`)
@DecodeArray(SponsoredBrandsCampaign)
public listCampaigns(params?: ListCampaignsParams) {
return this.client.get<SponsoredBrandsCampaign[]>(this.paramsFilterTransformer('', params))
}

/**
* Creates one or more new Campaigns
*
* @param {Campaign[]} campaigns
* @param {SponsoredBrandsCampaignCreateParams[]} campaigns
* @returns
* @memberof SponsoredBrandsCampaignOperation
*/
@DecodeArray(CampaignResponse)
public createCampaigns(campaigns: Campaign[]) {
public createCampaigns(campaigns: SponsoredBrandsCampaignCreateParams[]) {
return this.client.post<CampaignResponse[]>(this.resource, campaigns)
}

Expand Down
31 changes: 31 additions & 0 deletions src/operations/campaigns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,37 @@ export type SponsoredProductsCampaignCreateParams = t.TypeOf<
typeof SponsoredProductsCampaignCreateParams
>

export const SponsoredBrandsCampaignCreateParams = t.strict({
/**
* Campaign name limit is 128 characters.
* Duplicate campaign names are not allowed. Campaigns with zero positive keywords are not allowed.
*/
name: CampaignName,

/**
* Differentiates between a keyword-targeted and automatically targeted campaign.
*/
targetingType: CampaignTargetingType,

/**
* The state of the campaign.
*/
state: CampaignState,

/**
* Daily budget for the campaign.
*/
dailyBudget: t.number,

/**
* The date the campaign will go or went live as YYYYMMDD.
*/
startDate: t.string,
})
export type SponsoredBrandsCampaignCreateParams = t.TypeOf<
typeof SponsoredBrandsCampaignCreateParams
>

export const SponsoredProductsCampaignUpdateParams = t.intersection([
t.type({
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ describe('SponsoredBrandsCampaignOperation', () => {
})
})

// Error: Unable to extract parameter from http request for javax.ws.rs.PathParam("campaignId") value is 'extended' for public abstract com.amazon.adapi.model.hsa.ExternalCampaign com.amazon.adapi.resource.HsaCampaignInterface.getCampaign(long)
describe.skip('listCampaignsEx', () => {
it(`should return an array of expanded campaigns`, async () => {
const res = await campaignOperation.listCampaignsEx()
expect(Array.isArray(res)).toBeTruthy()
})

it(`should return a filtered list of results`, async () => {
const res = await campaignOperation.listCampaignsEx({
campaignIdFilter: [CAMPAIGN_ID],
})
expect(Array.isArray(res)).toBeTruthy()
})
})

// Skip: Sponsored brand campaign list is empty
describe.skip('getCampaign', () => {
it(`should return a single campaign`, async () => {
Expand All @@ -39,26 +24,16 @@ describe('SponsoredBrandsCampaignOperation', () => {
})
})

// Skip: Sponsored brand campaign list is empty
describe.skip('getCampaignEx', () => {
it(`should return a single extended campaign`, async () => {
const res = await campaignOperation.getCampaignEx(CAMPAIGN_ID)
expect(res).toBeTruthy()
})
})

// Return an error: No resource method found for POST, return 405 with Allow header
describe.skip('createCampaigns', () => {
it(`should create a campaign`, async () => {
const res = await campaignOperation.createCampaigns([
{
name: 'test campaign 4',
campaignType: 'sponsoredProducts',
dailyBudget: 1,
state: 'enabled',
targetingType: 'manual',
state: 'enabled',
dailyBudget: 1,
startDate: '20190301',
premiumBidAdjustment: true,
},
])

Expand Down

0 comments on commit fb1fa27

Please sign in to comment.