@c15t/nextjs
Version:
Developer-first CMP for Next.js: cookie banner, consent manager, preferences centre. GDPR ready with minimal setup and rich customization.
1 lines • 4.57 kB
JavaScript
;let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_exports__={};let external_vitest_namespaceObject=require("vitest"),external_headers_cjs_namespaceObject=require("./headers.cjs"),external_initial_data_cjs_namespaceObject=require("./initial-data.cjs"),external_normalize_url_cjs_namespaceObject=require("./normalize-url.cjs");for(var __webpack_i__ in external_vitest_namespaceObject.vi.mock("next/headers",()=>({headers:()=>new Headers({"x-forwarded-proto":"https","x-forwarded-host":"example.com",cookie:"test=123"})})),external_vitest_namespaceObject.vi.mock("./headers",()=>({extractRelevantHeaders:external_vitest_namespaceObject.vi.fn()})),external_vitest_namespaceObject.vi.mock("./normalize-url",()=>({normalizeBackendURL:external_vitest_namespaceObject.vi.fn()})),(0,external_vitest_namespaceObject.describe)("getC15TInitialData",()=>{let e={"x-forwarded-proto":"https","x-forwarded-host":"example.com",cookie:"test=123"},t=new Headers({"x-forwarded-proto":"https","x-forwarded-host":"example.com",cookie:"test=123"}),a=external_vitest_namespaceObject.vi.fn();(0,external_vitest_namespaceObject.beforeEach)(()=>{external_vitest_namespaceObject.vi.clearAllMocks(),external_vitest_namespaceObject.vi.stubGlobal("fetch",a),external_headers_cjs_namespaceObject.extractRelevantHeaders.mockReturnValue(e),external_normalize_url_cjs_namespaceObject.normalizeBackendURL.mockReturnValue("https://api.example.com")}),(0,external_vitest_namespaceObject.afterEach)(()=>{external_vitest_namespaceObject.vi.unstubAllGlobals()}),(0,external_vitest_namespaceObject.it)("should return undefined when normalized URL is not available",async()=>{external_normalize_url_cjs_namespaceObject.normalizeBackendURL.mockReturnValue(null);let e=await (0,external_initial_data_cjs_namespaceObject.getC15TInitialData)("https://example.com",t);(0,external_vitest_namespaceObject.expect)(e).toBeUndefined()}),(0,external_vitest_namespaceObject.it)("should return undefined when no relevant headers are present",async()=>{external_headers_cjs_namespaceObject.extractRelevantHeaders.mockReturnValue({});let e=await (0,external_initial_data_cjs_namespaceObject.getC15TInitialData)("https://example.com",t);(0,external_vitest_namespaceObject.expect)(e).toBeUndefined()}),(0,external_vitest_namespaceObject.it)("should successfully fetch and return consent banner data",async()=>{let n={showConsentBanner:!0,branding:"c15t",jurisdiction:{message:"Please accept cookies",code:"GDPR"},location:{countryCode:"US",regionCode:"CA"},translations:{language:"en",translations:{common:{acceptAll:"Accept All",rejectAll:"Reject All",customize:"Customize",save:"Save"},cookieBanner:{title:"Cookie Preferences",description:"We use cookies to improve your experience"},consentManagerDialog:{title:"Manage Cookie Preferences",description:"Customize your cookie preferences"},consentTypes:{necessary:{title:"Necessary",description:"Required for the website to function"},experience:{title:"Experience",description:"Enhance your browsing experience"},functionality:{title:"Functionality",description:"Enable specific functionality"},marketing:{title:"Marketing",description:"Help us improve our marketing"},measurement:{title:"Measurement",description:"Help us measure performance"}}}}};a.mockResolvedValueOnce({ok:!0,json:()=>Promise.resolve(n)});let c=await (0,external_initial_data_cjs_namespaceObject.getC15TInitialData)("https://example.com",t);(0,external_vitest_namespaceObject.expect)(a).toHaveBeenCalledWith("https://api.example.com/show-consent-banner",{method:"GET",headers:e}),(0,external_vitest_namespaceObject.expect)(c).toEqual(n)}),(0,external_vitest_namespaceObject.it)("should handle fetch failure gracefully",async()=>{a.mockRejectedValueOnce(Error("Network error"));let e=await (0,external_initial_data_cjs_namespaceObject.getC15TInitialData)("https://example.com",t);(0,external_vitest_namespaceObject.expect)(e).toBeUndefined()}),(0,external_vitest_namespaceObject.it)("should handle non-ok response gracefully",async()=>{a.mockResolvedValueOnce({ok:!1,status:500,statusText:"Internal Server Error"});let e=await (0,external_initial_data_cjs_namespaceObject.getC15TInitialData)("https://example.com",t);(0,external_vitest_namespaceObject.expect)(e).toBeUndefined()})}),__webpack_exports__)exports[__webpack_i__]=__webpack_exports__[__webpack_i__];Object.defineProperty(exports,"__esModule",{value:!0});