diff --git a/src/graphql/ad-set.generated.tsx b/src/graphql/ad-set.generated.tsx index 4b947c7e..21e666d7 100644 --- a/src/graphql/ad-set.generated.tsx +++ b/src/graphql/ad-set.generated.tsx @@ -6,6 +6,7 @@ import * as Apollo from "@apollo/client"; const defaultOptions = {} as const; export type AdSetFragment = { id: string; + price?: string | null; createdAt: any; billingType?: string | null; name?: string | null; @@ -131,6 +132,7 @@ export type CreateAdSetMutationVariables = Types.Exact<{ export type CreateAdSetMutation = { createAdSet: { id: string; + price?: string | null; createdAt: any; billingType?: string | null; name?: string | null; @@ -212,6 +214,7 @@ export type UpdateAdSetMutationVariables = Types.Exact<{ export type UpdateAdSetMutation = { updateAdSet: { id: string; + price?: string | null; createdAt: any; billingType?: string | null; name?: string | null; @@ -301,6 +304,7 @@ export const AdFragmentDoc = gql` export const AdSetFragmentDoc = gql` fragment AdSet on AdSet { id + price createdAt billingType name diff --git a/src/graphql/ad-set.graphql b/src/graphql/ad-set.graphql index 08143953..c25d3df0 100644 --- a/src/graphql/ad-set.graphql +++ b/src/graphql/ad-set.graphql @@ -1,5 +1,6 @@ fragment AdSet on AdSet { id + price createdAt billingType name diff --git a/src/graphql/campaign.generated.tsx b/src/graphql/campaign.generated.tsx index ee73e9ab..a0091b7f 100644 --- a/src/graphql/campaign.generated.tsx +++ b/src/graphql/campaign.generated.tsx @@ -36,6 +36,7 @@ export type CampaignFragment = { geoTargets?: Array<{ code: string; name: string }> | null; adSets: Array<{ id: string; + price?: string | null; createdAt: any; billingType?: string | null; name?: string | null; @@ -147,6 +148,7 @@ export type CampaignAdsFragment = { advertiser: { id: string }; adSets: Array<{ id: string; + price?: string | null; createdAt: any; billingType?: string | null; name?: string | null; @@ -258,6 +260,7 @@ export type LoadCampaignQuery = { geoTargets?: Array<{ code: string; name: string }> | null; adSets: Array<{ id: string; + price?: string | null; createdAt: any; billingType?: string | null; name?: string | null; @@ -351,6 +354,7 @@ export type LoadCampaignAdsQuery = { advertiser: { id: string }; adSets: Array<{ id: string; + price?: string | null; createdAt: any; billingType?: string | null; name?: string | null; diff --git a/src/user/library/index.test.ts b/src/user/library/index.test.ts index fa73da46..213416e7 100644 --- a/src/user/library/index.test.ts +++ b/src/user/library/index.test.ts @@ -13,6 +13,7 @@ import { AdSetForm, CampaignForm, Creative } from "user/views/adsManager/types"; import _ from "lodash"; import { AdFragment, AdSetFragment } from "graphql/ad-set.generated"; import { CreativeFragment } from "graphql/creative.generated"; +import { DeepPartial } from "@apollo/client/utilities"; const BASE_CPM_CAMPAIGN_FRAGMENT: Readonly = { id: "3495317a-bb47-4daf-8d3e-14cdc0e87457", @@ -45,6 +46,7 @@ const BASE_CPM_CAMPAIGN_FRAGMENT: Readonly = { { id: "39644642-b56a-430a-90f8-8917651bb62f", createdAt: "2023-07-11T16:13:31.286Z", + price: "0.006", billingType: "cpm", name: "Demo ad set", totalMax: 10, @@ -123,12 +125,9 @@ describe("pricing logic (read)", () => { it("should convert per-impression values to CPM when populating CampaignForm", () => { const campaign = produce(BASE_CPM_CAMPAIGN_FRAGMENT, (c) => { - c.adSets.forEach((adset) => { + (c.adSets ?? []).forEach((adset) => { adset.billingType = "cpm"; - adset.ads?.forEach((ad) => { - ad.price = "0.007"; - ad.priceType = ConfirmationType.View; - }); + adset.price = "0.007"; }); }); const campaignForm = editCampaignValues(campaign, "abc"); @@ -140,10 +139,7 @@ describe("pricing logic (read)", () => { const campaign = produce(BASE_CPM_CAMPAIGN_FRAGMENT, (c) => { c.adSets.forEach((adset) => { adset.billingType = "cpc"; - adset.ads?.forEach((ad) => { - ad.price = "1"; - ad.priceType = ConfirmationType.View; - }); + adset.price = "1"; }); }); const campaignForm = editCampaignValues(campaign, "abc"); @@ -282,36 +278,23 @@ describe("edit form tests", () => { type: { code: "notification_v1_all" }, }; - const ad: AdFragment = { + const ad: Partial = { id: "1", creative: creative, - state: "active", - price: "6", - priceType: ConfirmationType.View, - }; - - const ad2: AdFragment = { - id: "2", - creative: creative, - state: "deleted", - price: "6", - priceType: ConfirmationType.View, }; - const ad3: AdFragment = { + const ad2: Partial = { id: "3", creative: { ...creative, id: "1235", name: "a different creative", }, - state: "active", - price: "6", - priceType: ConfirmationType.View, }; - const adSet: AdSetFragment = { + const adSet: DeepPartial = { ads: [ad, ad2], + price: "6", billingType: "cpm", conversions: [], createdAt: undefined, @@ -323,8 +306,9 @@ describe("edit form tests", () => { totalMax: 100, }; - const adSet2: AdSetFragment = { - ads: [ad, ad3], + const adSet2: DeepPartial = { + ads: [ad], + price: "6", billingType: "cpm", conversions: [], createdAt: undefined, @@ -336,7 +320,7 @@ describe("edit form tests", () => { totalMax: 100, }; - const campaignFragment: CampaignFragment = { + const campaignFragment: DeepPartial = { adSets: [adSet, adSet2], advertiser: { id: "12345" }, budget: 100, @@ -362,8 +346,8 @@ describe("edit form tests", () => { }; const editForm = editCampaignValues( - campaignFragment, - campaignFragment.advertiser.id, + campaignFragment as CampaignFragment, + campaignFragment?.advertiser?.id ?? "", ); it("should result in a valid campaign form", () => { const omitted = _.omit(editForm, ["newCreative"]); @@ -395,7 +379,7 @@ describe("edit form tests", () => { "advertiserId": "12345", "createdAt": undefined, "id": "1235", - "included": false, + "included": true, "name": "a different creative", "payloadInlineContent": undefined, "payloadNotification": { @@ -451,7 +435,7 @@ describe("edit form tests", () => { "advertiserId": "12345", "createdAt": undefined, "id": "1235", - "included": true, + "included": false, "name": "a different creative", "payloadInlineContent": undefined, "payloadNotification": { @@ -515,6 +499,10 @@ describe("edit form tests", () => { "creativeId": "1234", "creativeSetId": "11111", }, + { + "creativeId": "1235", + "creativeSetId": "11111", + }, ], "id": "11111", "oses": [ @@ -536,10 +524,6 @@ describe("edit form tests", () => { "creativeId": "1234", "creativeSetId": "22222", }, - { - "creativeId": "1235", - "creativeSetId": "22222", - }, ], "id": "22222", "oses": [ diff --git a/src/user/library/index.ts b/src/user/library/index.ts index c2911e4d..22e9002c 100644 --- a/src/user/library/index.ts +++ b/src/user/library/index.ts @@ -85,14 +85,11 @@ export function editCampaignValues( campaign: CampaignFragment, advertiserId: string, ): CampaignForm { - const ads: AdFragment[] = _.filter( - _.flatMap(campaign.adSets, "ads"), - (a) => a.state !== "deleted", - ); + const ads: AdFragment[] = _.flatMap(campaign.adSets, "ads"); const billingType = (_.head(campaign.adSets)?.billingType ?? "cpm") as Billing; - const rawPrice = BigNumber(_.head(ads)?.price ?? "0.1"); + const rawPrice = BigNumber(_.head(campaign.adSets)?.price ?? "0.1"); const price = billingType === "cpm" ? rawPrice.multipliedBy(1000) : rawPrice; return {