From c8666cdbaf2757cd16a895e01158d3357c492a45 Mon Sep 17 00:00:00 2001 From: DanielCliftonGuardian <110032454+DanielCliftonGuardian@users.noreply.github.com> Date: Fri, 20 Dec 2024 07:02:38 +0000 Subject: [PATCH] Simplify --- dotcom-rendering/src/lib/assets.test.ts | 10 +++++----- dotcom-rendering/src/lib/assets.ts | 13 +++---------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/dotcom-rendering/src/lib/assets.test.ts b/dotcom-rendering/src/lib/assets.test.ts index 53f7afde8c..b3429b53f2 100644 --- a/dotcom-rendering/src/lib/assets.test.ts +++ b/dotcom-rendering/src/lib/assets.test.ts @@ -28,9 +28,9 @@ describe('decideAssetOrigin for stage', () => { ); }); it('DEV', () => { - expect(decideAssetOrigin('DEV', true)).toEqual(BASE_URL_DEV); - expect(decideAssetOrigin('dev', true)).toEqual(BASE_URL_DEV); - expect(decideAssetOrigin(undefined, false)).toEqual('/'); + expect(decideAssetOrigin('DEV')).toEqual(BASE_URL_DEV); + expect(decideAssetOrigin('dev')).toEqual(BASE_URL_DEV); + expect(decideAssetOrigin(undefined)).toEqual(BASE_URL_DEV); }); }); @@ -82,13 +82,13 @@ describe('getPathFromManifest', () => { it('returns correct hashed asset (1)', () => { expect(getPathFromManifest('client.web', '7305.client.web.js')).toBe( - '/assets/7305.client.web.8cdc05567d98ebd9f67e.js', + 'http://localhost:3030/assets/7305.client.web.8cdc05567d98ebd9f67e.js', ); }); it('returns correct hashed asset (2)', () => { expect(getPathFromManifest('client.web', '356.client.web.js')).toBe( - '/assets/356.client.web.0a1bbdf8c7a5e5826b7c.js', + 'http://localhost:3030/assets/356.client.web.0a1bbdf8c7a5e5826b7c.js', ); }); diff --git a/dotcom-rendering/src/lib/assets.ts b/dotcom-rendering/src/lib/assets.ts index 3f585f0916..307cf19374 100644 --- a/dotcom-rendering/src/lib/assets.ts +++ b/dotcom-rendering/src/lib/assets.ts @@ -21,29 +21,22 @@ export type AssetOrigin = * Decides the url to use for fetching assets * * @param {'PROD' | 'CODE' | undefined} stage the environment code is executing in - * @param {boolean} isDev whether the environment is development * @returns {AssetOrigin} */ -export const decideAssetOrigin = ( - stage: string | undefined, - isDev?: boolean, -): AssetOrigin => { - if (isDev) { - return BASE_URL_DEV; - } +export const decideAssetOrigin = (stage: string | undefined): AssetOrigin => { switch (stage?.toUpperCase()) { case 'PROD': return 'https://assets.guim.co.uk/'; case 'CODE': return 'https://assets-code.guim.co.uk/'; default: - return '/'; + return BASE_URL_DEV; } }; const isDev = process.env.NODE_ENV === 'development'; -export const ASSET_ORIGIN = decideAssetOrigin(process.env.GU_STAGE, isDev); +export const ASSET_ORIGIN = decideAssetOrigin(process.env.GU_STAGE); const isAssetHash = (manifest: unknown): manifest is AssetHash => isObject(manifest) &&