Skip to content

Commit 2e36ae6

Browse files
committed
tests added
1 parent cd8e5aa commit 2e36ae6

File tree

11 files changed

+145
-57
lines changed

11 files changed

+145
-57
lines changed
Lines changed: 19 additions & 19 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ declare function buildPlacementsRequest(placements: MozAdsPlacements): AdPlaceme
226226
/**
227227
* Maps the ad content from the UAPI response to corresponding placement IDs of given configs.
228228
*
229-
* Note: This function makes no guarantee that all given placement IDs will have defined `adContent`.
229+
* Note: This function will attempt to use fallback ads where possible if not all content is mapped.
230230
*/
231231
declare function mapResponseToPlacementsWithContent(response: AdResponse, placements: MozAdsPlacements): MozAdsPlacements;
232232

dist/core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/core.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u,w as v,x as w,y,z}from"./chunk-KYLX7KWQ.mjs";import"./chunk-57T3EAOB.mjs";export{d as AdUnitFormatImpressionThreshold,b as AdUnitFormatTypeLookup,u as CLOSE_ICON_SVG,e as DEFAULT_SERVICE_ENDPOINT,g as DefaultImpressionThreshold,i as DefaultLogReporter,l as DefaultLogger,n as DefaultMozAdsImpressionObserver,z as FALLBACK_BILLBOARD_SVG,w as FALLBACK_DINO_SVG_FRAGMENT,y as FALLBACK_DONATE_SVG_FRAGMENT,B as FALLBACK_MRECTANGLE_SVG,A as FALLBACK_SKYSCRAPER_SVG,c as FallbackAdURL,K as FetchAdsError,a as FixedSize,t as IABFixedSize,f as INSTRUMENT_ENDPOINT,o as IS_BROWSER,r as IS_PRODUCTION,p as LOG_EMIT_FLAG_DEFAULT,m as LOG_TO_CONSOLE_FLAG_DEFAULT,k as LoggerLevel,x as NonIABFixedSize,v as REPORT_ICON_SVG,h as SeverityLevel,F as StoreType,M as buildPlacementsRequest,q as defaultImpressionObserver,j as defaultLogReporter,L as fetchAds,G as getItemFromStore,J as getOrGenerateContextId,C as l,N as mapResponseToPlacementsWithContent,D as preloadImage,s as recordClick,I as removeItemFromStore,E as renderPlacement,H as setItemInStore};
1+
import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u,w as v,x as w,y,z}from"./chunk-FMM6R42G.mjs";import"./chunk-57T3EAOB.mjs";export{d as AdUnitFormatImpressionThreshold,b as AdUnitFormatTypeLookup,u as CLOSE_ICON_SVG,e as DEFAULT_SERVICE_ENDPOINT,g as DefaultImpressionThreshold,i as DefaultLogReporter,l as DefaultLogger,n as DefaultMozAdsImpressionObserver,z as FALLBACK_BILLBOARD_SVG,w as FALLBACK_DINO_SVG_FRAGMENT,y as FALLBACK_DONATE_SVG_FRAGMENT,B as FALLBACK_MRECTANGLE_SVG,A as FALLBACK_SKYSCRAPER_SVG,c as FallbackAdURL,K as FetchAdsError,a as FixedSize,t as IABFixedSize,f as INSTRUMENT_ENDPOINT,o as IS_BROWSER,r as IS_PRODUCTION,p as LOG_EMIT_FLAG_DEFAULT,m as LOG_TO_CONSOLE_FLAG_DEFAULT,k as LoggerLevel,x as NonIABFixedSize,v as REPORT_ICON_SVG,h as SeverityLevel,F as StoreType,M as buildPlacementsRequest,q as defaultImpressionObserver,j as defaultLogReporter,L as fetchAds,G as getItemFromStore,J as getOrGenerateContextId,C as l,N as mapResponseToPlacementsWithContent,D as preloadImage,s as recordClick,I as removeItemFromStore,E as renderPlacement,H as setItemInStore};

dist/iife.global.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"use client";import{E as h,L as A,r as m,t as P,u as g}from"./chunk-KYLX7KWQ.mjs";import"./chunk-57T3EAOB.mjs";import{useLayoutEffect as x,useRef as b}from"react";import{createContext as v,useContext as y,useEffect as w,useState as L}from"react";var M;try{M=new m({name:"react.hooks.useMozAdsPlacement"})}catch(e){console.debug(`DefaultLogger for react.hooks.useMozAdsPlacement could not be instantiated: ${e}`)}var f=class{placements={};async getPlacementWithContent(t){let o=this.placements[t.placementId];if(o)return o;try{let r=await A({placements:{[t.placementId]:t}});this.placements={...this.placements,...r}}catch(r){return M?.error(`Unable to fetch ads; ${r.message}`,{type:"placementComponent.adLoad.failure",eventLabel:"ad_load_error",errorId:r?.name}),t.onError?.({error:r}),t}return this.placements[t.placementId]}},R=v(new f),z=({placementId:e,iabContent:t,fixedSize:o,onError:r})=>{let[l,s]=L({placementId:e,iabContent:t,fixedSize:o}),d=y(R),c=async()=>{s(await d.getPlacementWithContent({placementId:e,iabContent:t,fixedSize:o,onError:r}))};return w(()=>{c()},[e]),l};import{jsx as C}from"react/jsx-runtime";var E;try{E=new m({name:"react.components.MozAdsPlacement"})}catch(e){console.debug(`DefaultLogger for react.components.MozAdsPlacement could not be instantiated: ${e}`)}function q({placementId:e,iabContent:t,fixedSize:o,onClick:r,onReport:l,onError:s,onLoad:d}){let{width:c,height:u}=o||{},p={width:c&&`${c}px`,height:u&&`${u}px`};try{let n=z({placementId:e,iabContent:t,fixedSize:o,onError:s}),i=b(null);return x(()=>{i.current&&h(i.current,{placement:n,onClick:a=>{g(n),r?.(a)},onReport:a=>{l?.(a)},onError:a=>{s?.(a)},onLoad:a=>{P.observe(n),d?.(a)}})},[n]),C("div",{ref:i,style:p})}catch(n){try{E?.error(`An unexpected error has occured when rendering ${e}: ${n?.message}`,{type:"placementComponent.render.error",eventLabel:"render_error",placementId:e,errorId:n?.name}),s?.({error:n})}catch{}return C("div",{style:p})}}export{q as MozAdsPlacement,f as MozAdsPlacementContextState,R as mozAdsPlacementContext,z as useMozAdsPlacement};
1+
"use client";import{E as h,L as A,r as m,t as P,u as g}from"./chunk-FMM6R42G.mjs";import"./chunk-57T3EAOB.mjs";import{useLayoutEffect as x,useRef as b}from"react";import{createContext as v,useContext as y,useEffect as w,useState as L}from"react";var M;try{M=new m({name:"react.hooks.useMozAdsPlacement"})}catch(e){console.debug(`DefaultLogger for react.hooks.useMozAdsPlacement could not be instantiated: ${e}`)}var f=class{placements={};async getPlacementWithContent(t){let o=this.placements[t.placementId];if(o)return o;try{let r=await A({placements:{[t.placementId]:t}});this.placements={...this.placements,...r}}catch(r){return M?.error(`Unable to fetch ads; ${r.message}`,{type:"placementComponent.adLoad.failure",eventLabel:"ad_load_error",errorId:r?.name}),t.onError?.({error:r}),t}return this.placements[t.placementId]}},R=v(new f),z=({placementId:e,iabContent:t,fixedSize:o,onError:r})=>{let[l,s]=L({placementId:e,iabContent:t,fixedSize:o}),d=y(R),c=async()=>{s(await d.getPlacementWithContent({placementId:e,iabContent:t,fixedSize:o,onError:r}))};return w(()=>{c()},[e]),l};import{jsx as C}from"react/jsx-runtime";var E;try{E=new m({name:"react.components.MozAdsPlacement"})}catch(e){console.debug(`DefaultLogger for react.components.MozAdsPlacement could not be instantiated: ${e}`)}function q({placementId:e,iabContent:t,fixedSize:o,onClick:r,onReport:l,onError:s,onLoad:d}){let{width:c,height:u}=o||{},p={width:c&&`${c}px`,height:u&&`${u}px`};try{let n=z({placementId:e,iabContent:t,fixedSize:o,onError:s}),i=b(null);return x(()=>{i.current&&h(i.current,{placement:n,onClick:a=>{g(n),r?.(a)},onReport:a=>{l?.(a)},onError:a=>{s?.(a)},onLoad:a=>{P.observe(n),d?.(a)}})},[n]),C("div",{ref:i,style:p})}catch(n){try{E?.error(`An unexpected error has occured when rendering ${e}: ${n?.message}`,{type:"placementComponent.render.error",eventLabel:"render_error",placementId:e,errorId:n?.name}),s?.({error:n})}catch{}return C("div",{style:p})}}export{q as MozAdsPlacement,f as MozAdsPlacementContextState,R as mozAdsPlacementContext,z as useMozAdsPlacement};

packages/core/src/fetch.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ export const fetchAds = async ({
7272
throw fetchAdsError
7373
}
7474

75-
logger.info(`Succesfully fetched ads with request: ${JSON.stringify(request)}`, {
75+
logger.info(`Successfully fetched ads with request: ${JSON.stringify(request)}`, {
7676
type: 'fetchAds.request.success',
7777
method: 'POST',
7878
})
79-
console.log('here', mapResponseToPlacementsWithContent(response, pendingPlacements))
8079

8180
resolve(mapResponseToPlacementsWithContent(response, pendingPlacements))
8281
}
@@ -132,7 +131,7 @@ export function buildPlacementsRequest(placements: MozAdsPlacements): AdPlacemen
132131
/**
133132
* Maps the ad content from the UAPI response to corresponding placement IDs of given configs.
134133
*
135-
* Note: This function makes no guarantee that all given placement IDs will have defined `adContent`.
134+
* Note: This function will attempt to use fallback ads where possible if not all content is mapped.
136135
*/
137136
export function mapResponseToPlacementsWithContent(response: AdResponse, placements: MozAdsPlacements): MozAdsPlacements {
138137
for (const placementWithContent of Object.values<MozAdsPlacementWithContent>(placements)) {
@@ -142,7 +141,7 @@ export function mapResponseToPlacementsWithContent(response: AdResponse, placeme
142141
// If a single ad placement is missing from the response, we fill that slot if a single fallback if able
143142

144143
if (!placementWithContent.fixedSize) {
145-
// Without a fixedSize, we cannot fallback to anything
144+
// Without a fixedSize, we cannot fallback to anything, so we give it an empty object
146145
placementWithContent.content = {}
147146
continue
148147
}

0 commit comments

Comments
 (0)