diff --git a/src/graphql/types.ts b/src/graphql/types.ts index 3e41ef7c..0c03884f 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -112,10 +112,8 @@ export type CreateAdInput = { creativeId?: InputMaybe; creativeSetId?: InputMaybe; id?: InputMaybe; - /** The price in the owning campaign's currency for each single confirmation of the priceType specified. Note therefore that the caller is responsible for dividing cost-per-mille by 1000. */ - price: Scalars["Numeric"]; - priceType: ConfirmationType; - state?: InputMaybe; + price?: InputMaybe; + priceType?: InputMaybe; webhooks?: InputMaybe>; }; @@ -133,6 +131,8 @@ export type CreateAdSetInput = { negativeKeywords?: InputMaybe>; oses?: InputMaybe>; perDay: Scalars["Float"]; + /** The price in the owning campaign's currency for each single confirmation of the priceType specified. Note therefore that the caller is responsible for dividing cost-per-mille by 1000. */ + price?: InputMaybe; segments: Array; splitTestGroup?: InputMaybe; state?: InputMaybe; @@ -413,6 +413,8 @@ export type UpdateAdSetInput = { optimized?: InputMaybe; oses?: InputMaybe>; perDay?: InputMaybe; + /** The price in the owning campaign's currency for each single confirmation of the priceType specified. Note therefore that the caller is responsible for dividing cost-per-mille by 1000. */ + price?: InputMaybe; segments?: InputMaybe>; splitTestGroup?: InputMaybe; state?: InputMaybe; diff --git a/src/user/library/index.test.ts b/src/user/library/index.test.ts index 4c468ba4..fa73da46 100644 --- a/src/user/library/index.test.ts +++ b/src/user/library/index.test.ts @@ -1,11 +1,6 @@ import { CampaignFragment } from "graphql/campaign.generated"; import { describe, expect, it } from "vitest"; -import { - editCampaignValues, - transformCreative, - transformEditForm, - transformNewForm, -} from "."; +import { editCampaignValues, transformEditForm, transformNewForm } from "."; import { CampaignFormat, CampaignPacingStrategies, @@ -137,7 +132,7 @@ describe("pricing logic (read)", () => { }); }); const campaignForm = editCampaignValues(campaign, "abc"); - expect(campaignForm.price).toEqual(7); + expect(campaignForm.price).toEqual("7"); expect(campaignForm.billingType).toEqual("cpm"); }); @@ -152,7 +147,7 @@ describe("pricing logic (read)", () => { }); }); const campaignForm = editCampaignValues(campaign, "abc"); - expect(campaignForm.price).toEqual(1); + expect(campaignForm.price).toEqual("1"); expect(campaignForm.billingType).toEqual("cpc"); }); @@ -161,56 +156,11 @@ describe("pricing logic (read)", () => { c.adSets = []; }); const formObject = editCampaignValues(campaign, "abc"); - expect(formObject.price).toEqual(100); + expect(formObject.price).toEqual("100"); expect(formObject.billingType).toEqual("cpm"); }); }); -describe("pricing logic (write)", () => { - const creative: Creative = { - payloadNotification: { - title: "some title", - body: "body", - targetUrl: "some url", - }, - advertiserId: "some id", - state: "draft", - type: { code: "notification_all_v1" }, - name: "some name", - included: true, - }; - - it("should convert from CPM to per-impression values when populating a CPM creative", () => { - const inputObject = transformCreative(creative, { - billingType: "cpm", - price: 9, - }); - - expect(inputObject.price).toEqual("0.009"); - expect(inputObject.priceType).toEqual(ConfirmationType.View); - }); - - it("should not convert CPC to per-impression values when populating a CPC creative", () => { - const inputObject = transformCreative(creative, { - billingType: "cpc", - price: 9, - }); - - expect(inputObject.price).toEqual("9"); - expect(inputObject.priceType).toEqual(ConfirmationType.Click); - }); - - it("should not convert CPV to per-impression values when populating a CPV creative", () => { - const inputObject = transformCreative(creative, { - billingType: "cpv", - price: 9, - }); - - expect(inputObject.price).toEqual("9"); - expect(inputObject.priceType).toEqual(ConfirmationType.Landed); - }); -}); - describe("new form tests", () => { const dateString = new Date().toLocaleString(); @@ -254,7 +204,7 @@ describe("new form tests", () => { isCreating: false, name: "Test", paymentType: PaymentType.Radom, - price: 6, + price: "6", startAt: dateString, state: "draft", type: "paid", @@ -270,8 +220,6 @@ describe("new form tests", () => { "ads": [ { "creativeId": "11111", - "price": "0.006", - "priceType": "VIEW", }, ], "billingType": "cpm", @@ -284,6 +232,7 @@ describe("new form tests", () => { }, ], "perDay": 4, + "price": "0.006", "segments": [ { "code": "5678", @@ -316,29 +265,6 @@ describe("new form tests", () => { } `); }); - - it("should transform a creative", () => { - creative.payloadNotification = { - title: "valid", - targetUrl: "valid", - body: "valid", - }; - - creative.payloadSearch = { - title: "invalid", - targetUrl: "invalid", - body: "invalid", - }; - - const res = transformCreative(creative, form); - expect(res).toMatchInlineSnapshot(` - { - "creativeId": "11111", - "price": "0.006", - "priceType": "VIEW", - } - `); - }); }); describe("edit form tests", () => { @@ -569,7 +495,7 @@ describe("edit form tests", () => { "isCreating": false, "name": "My first campaign", "paymentType": "RADOM", - "price": 6000, + "price": "6000", "startAt": undefined, "state": "active", "type": "paid", @@ -588,8 +514,6 @@ describe("edit form tests", () => { { "creativeId": "1234", "creativeSetId": "11111", - "price": "6", - "priceType": "VIEW", }, ], "id": "11111", @@ -611,14 +535,10 @@ describe("edit form tests", () => { { "creativeId": "1234", "creativeSetId": "22222", - "price": "6", - "priceType": "VIEW", }, { "creativeId": "1235", "creativeSetId": "22222", - "price": "6", - "priceType": "VIEW", }, ], "id": "22222", diff --git a/src/user/library/index.ts b/src/user/library/index.ts index 4543e1de..c2911e4d 100644 --- a/src/user/library/index.ts +++ b/src/user/library/index.ts @@ -1,8 +1,6 @@ import { CampaignFormat, CampaignPacingStrategies, - ConfirmationType, - CreateAdInput, CreateCampaignInput, UpdateCampaignInput, } from "graphql/types"; @@ -33,6 +31,7 @@ export function transformNewForm( form: CampaignForm, userId?: string, ): CreateCampaignInput { + const price = BigNumber(form.price); return { currency: form.currency, externalId: "", @@ -52,6 +51,10 @@ export function transformNewForm( budget: form.budget, adSets: form.adSets.map((adSet) => ({ name: adSet.name, + price: + form.billingType === "cpm" + ? price.dividedBy(1000).toString() + : price.toString(), billingType: form.billingType, perDay: form.format === CampaignFormat.PushNotification ? 4 : 6, segments: adSet.segments.map((s) => ({ code: s.code, name: s.name })), @@ -60,7 +63,7 @@ export function transformNewForm( conversions: transformConversion(adSet.conversions), ads: adSet.creatives .filter((c) => c.included) - .map((ad) => transformCreative(ad, form)), + .map((ad) => ({ creativeId: ad.id })), })), paymentType: form.paymentType, }; @@ -78,34 +81,6 @@ function transformConversion(conv: Conversion[]) { })); } -export function transformCreative( - creative: Creative, - campaign: Pick, -): CreateAdInput { - let price: BigNumber; - let priceType: ConfirmationType; - - if (campaign.billingType === "cpm") { - price = BigNumber(campaign.price).dividedBy(1000); - priceType = ConfirmationType.View; - } else if (campaign.billingType === "cpv") { - price = BigNumber(campaign.price); - priceType = ConfirmationType.Landed; - } else { - price = BigNumber(campaign.price); - priceType = ConfirmationType.Click; - } - - const createInput: CreateAdInput = { - price: price.toString(), - priceType: priceType, - }; - - createInput.creativeId = creative.id; - - return createInput; -} - export function editCampaignValues( campaign: CampaignFragment, advertiserId: string, @@ -147,7 +122,7 @@ export function editCampaignValues( advertiserId, newCreative: initialCreative, currency: campaign.currency, - price: price.toNumber(), + price: price.toString(), billingType: billingType, validateStart: false, budget: campaign.budget, @@ -243,7 +218,7 @@ export function transformEditForm( ads: adSet.creatives .filter((c) => c.included) .map((ad) => ({ - ...transformCreative(ad, form), + creativeId: ad.id, creativeSetId: adSet.id, })), })), diff --git a/src/user/views/adsManager/types/index.ts b/src/user/views/adsManager/types/index.ts index f2817326..a04d8626 100644 --- a/src/user/views/adsManager/types/index.ts +++ b/src/user/views/adsManager/types/index.ts @@ -24,7 +24,7 @@ export type CampaignForm = { state: string; type: "paid"; // this is per click for CPC campaigns, but per thousand views for CPM campaigns - price: number; + price: string; billingType: Billing; paymentType: PaymentType; }; @@ -118,7 +118,7 @@ export const initialCampaign = (advertiser: IAdvertiser): CampaignForm => { newCreative: initialCreative, billingType: "cpm", currency: "USD", - price: 6, + price: "6", adSets: [ { ...initialAdSet,