From 412607e1275d62e8b7f8e85b51a27cb4ee252e61 Mon Sep 17 00:00:00 2001 From: Viktor Andersson <30777521+VIKTORVAV99@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:42:25 +0100 Subject: [PATCH] chore(app-backend): Use v9 (#7435) * switch paths to v9 + adjust mockserver * switch tokens * update env variables * add auth to state * prettier and merge v9 changes --------- Co-authored-by: Tony Co-authored-by: tonypls --- .github/workflows/deploy_preview_branch.yml | 4 +- .github/workflows/deploy_staging.yml | 2 +- mobileapp/README.md | 2 +- mobileapp/fastlane/Fastfile | 2 +- .../public/{v8 => v9}/details/daily/DE.json | 0 .../{v8 => v9}/details/daily/DK-DK2.json | 0 .../public/{v8 => v9}/details/hourly/CN.json | 0 .../public/{v8 => v9}/details/hourly/DE.json | 0 .../{v8 => v9}/details/hourly/DK-DK2.json | 0 .../public/{v8 => v9}/details/monthly/DE.json | 0 .../{v8 => v9}/details/monthly/DK-DK2.json | 0 .../public/{v8 => v9}/details/yearly/DE.json | 0 .../{v8 => v9}/details/yearly/DK-DK2.json | 0 mockserver/public/{v8 => v9}/gfs/solar.json | 0 mockserver/public/{v8 => v9}/gfs/wind.json | 0 mockserver/public/{v8 => v9}/meta.json | 0 mockserver/public/{v8 => v9}/state/daily.json | 0 .../public/{v8 => v9}/state/hourly.json | 0 .../public/{v8 => v9}/state/last_hour.json | 0 .../public/{v8 => v9}/state/monthly.json | 0 .../public/{v8 => v9}/state/yearly.json | 0 web/Earthfile | 2 +- web/README.md | 4 +- web/cypress/e2e/countrypanel.spec.ts | 44 +++++++++---------- web/cypress/e2e/map.spec.ts | 4 +- web/cypress/e2e/ranking.spec.ts | 10 ++--- web/cypress/e2e/timeslider.spec.ts | 40 ++++++++--------- web/src/api/getMeta.ts | 2 +- web/src/api/getState.ts | 11 +++-- web/src/api/getWeatherData.ts | 2 +- web/src/api/getZone.ts | 2 +- web/src/api/helpers.ts | 6 +-- 32 files changed, 71 insertions(+), 66 deletions(-) rename mockserver/public/{v8 => v9}/details/daily/DE.json (100%) rename mockserver/public/{v8 => v9}/details/daily/DK-DK2.json (100%) rename mockserver/public/{v8 => v9}/details/hourly/CN.json (100%) rename mockserver/public/{v8 => v9}/details/hourly/DE.json (100%) rename mockserver/public/{v8 => v9}/details/hourly/DK-DK2.json (100%) rename mockserver/public/{v8 => v9}/details/monthly/DE.json (100%) rename mockserver/public/{v8 => v9}/details/monthly/DK-DK2.json (100%) rename mockserver/public/{v8 => v9}/details/yearly/DE.json (100%) rename mockserver/public/{v8 => v9}/details/yearly/DK-DK2.json (100%) rename mockserver/public/{v8 => v9}/gfs/solar.json (100%) rename mockserver/public/{v8 => v9}/gfs/wind.json (100%) rename mockserver/public/{v8 => v9}/meta.json (100%) rename mockserver/public/{v8 => v9}/state/daily.json (100%) rename mockserver/public/{v8 => v9}/state/hourly.json (100%) rename mockserver/public/{v8 => v9}/state/last_hour.json (100%) rename mockserver/public/{v8 => v9}/state/monthly.json (100%) rename mockserver/public/{v8 => v9}/state/yearly.json (100%) diff --git a/.github/workflows/deploy_preview_branch.yml b/.github/workflows/deploy_preview_branch.yml index 0c1633a832..7a294a3365 100644 --- a/.github/workflows/deploy_preview_branch.yml +++ b/.github/workflows/deploy_preview_branch.yml @@ -5,7 +5,7 @@ on: required: true CLOUDFLARE_ACCOUNT_ID: required: true - VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN: + VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9: required: true jobs: deploy: @@ -39,7 +39,7 @@ jobs: working-directory: ./web run: pnpm run build env: - VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN: '${{ secrets.VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN }}' + VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9: '${{ secrets.VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9 }}' - name: Publish uses: cloudflare/pages-action@1 with: diff --git a/.github/workflows/deploy_staging.yml b/.github/workflows/deploy_staging.yml index 5f5f1569e1..8150ee5dc5 100644 --- a/.github/workflows/deploy_staging.yml +++ b/.github/workflows/deploy_staging.yml @@ -35,7 +35,7 @@ jobs: working-directory: ./web run: pnpm run build env: - VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN: '${{ secrets.VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN }}' + VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9: '${{ secrets.VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9 }}' - name: Publish uses: cloudflare/pages-action@1 with: diff --git a/mobileapp/README.md b/mobileapp/README.md index 8144e2de52..36d5705797 100644 --- a/mobileapp/README.md +++ b/mobileapp/README.md @@ -50,7 +50,7 @@ pnpm dev-ios ```bash -SENTRY_AUTH_TOKEN="" VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN="" pnpm run build-web +SENTRY_AUTH_TOKEN="" VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9="" pnpm run build-web ``` 2. Then run one of these commands to open the build in XCode or Android Studio: diff --git a/mobileapp/fastlane/Fastfile b/mobileapp/fastlane/Fastfile index 17f67c39d8..c2e53e85dd 100644 --- a/mobileapp/fastlane/Fastfile +++ b/mobileapp/fastlane/Fastfile @@ -10,7 +10,7 @@ android_dir = File.expand_path("../android") private_lane :build_web_app do ensure_env_vars( - env_vars: ['SENTRY_AUTH_TOKEN', 'VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN'] + env_vars: ['SENTRY_AUTH_TOKEN', 'VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9'] ) # Build the web app if we have both environment variables set sh("pnpm", "run", "build-web") diff --git a/mockserver/public/v8/details/daily/DE.json b/mockserver/public/v9/details/daily/DE.json similarity index 100% rename from mockserver/public/v8/details/daily/DE.json rename to mockserver/public/v9/details/daily/DE.json diff --git a/mockserver/public/v8/details/daily/DK-DK2.json b/mockserver/public/v9/details/daily/DK-DK2.json similarity index 100% rename from mockserver/public/v8/details/daily/DK-DK2.json rename to mockserver/public/v9/details/daily/DK-DK2.json diff --git a/mockserver/public/v8/details/hourly/CN.json b/mockserver/public/v9/details/hourly/CN.json similarity index 100% rename from mockserver/public/v8/details/hourly/CN.json rename to mockserver/public/v9/details/hourly/CN.json diff --git a/mockserver/public/v8/details/hourly/DE.json b/mockserver/public/v9/details/hourly/DE.json similarity index 100% rename from mockserver/public/v8/details/hourly/DE.json rename to mockserver/public/v9/details/hourly/DE.json diff --git a/mockserver/public/v8/details/hourly/DK-DK2.json b/mockserver/public/v9/details/hourly/DK-DK2.json similarity index 100% rename from mockserver/public/v8/details/hourly/DK-DK2.json rename to mockserver/public/v9/details/hourly/DK-DK2.json diff --git a/mockserver/public/v8/details/monthly/DE.json b/mockserver/public/v9/details/monthly/DE.json similarity index 100% rename from mockserver/public/v8/details/monthly/DE.json rename to mockserver/public/v9/details/monthly/DE.json diff --git a/mockserver/public/v8/details/monthly/DK-DK2.json b/mockserver/public/v9/details/monthly/DK-DK2.json similarity index 100% rename from mockserver/public/v8/details/monthly/DK-DK2.json rename to mockserver/public/v9/details/monthly/DK-DK2.json diff --git a/mockserver/public/v8/details/yearly/DE.json b/mockserver/public/v9/details/yearly/DE.json similarity index 100% rename from mockserver/public/v8/details/yearly/DE.json rename to mockserver/public/v9/details/yearly/DE.json diff --git a/mockserver/public/v8/details/yearly/DK-DK2.json b/mockserver/public/v9/details/yearly/DK-DK2.json similarity index 100% rename from mockserver/public/v8/details/yearly/DK-DK2.json rename to mockserver/public/v9/details/yearly/DK-DK2.json diff --git a/mockserver/public/v8/gfs/solar.json b/mockserver/public/v9/gfs/solar.json similarity index 100% rename from mockserver/public/v8/gfs/solar.json rename to mockserver/public/v9/gfs/solar.json diff --git a/mockserver/public/v8/gfs/wind.json b/mockserver/public/v9/gfs/wind.json similarity index 100% rename from mockserver/public/v8/gfs/wind.json rename to mockserver/public/v9/gfs/wind.json diff --git a/mockserver/public/v8/meta.json b/mockserver/public/v9/meta.json similarity index 100% rename from mockserver/public/v8/meta.json rename to mockserver/public/v9/meta.json diff --git a/mockserver/public/v8/state/daily.json b/mockserver/public/v9/state/daily.json similarity index 100% rename from mockserver/public/v8/state/daily.json rename to mockserver/public/v9/state/daily.json diff --git a/mockserver/public/v8/state/hourly.json b/mockserver/public/v9/state/hourly.json similarity index 100% rename from mockserver/public/v8/state/hourly.json rename to mockserver/public/v9/state/hourly.json diff --git a/mockserver/public/v8/state/last_hour.json b/mockserver/public/v9/state/last_hour.json similarity index 100% rename from mockserver/public/v8/state/last_hour.json rename to mockserver/public/v9/state/last_hour.json diff --git a/mockserver/public/v8/state/monthly.json b/mockserver/public/v9/state/monthly.json similarity index 100% rename from mockserver/public/v8/state/monthly.json rename to mockserver/public/v9/state/monthly.json diff --git a/mockserver/public/v8/state/yearly.json b/mockserver/public/v9/state/yearly.json similarity index 100% rename from mockserver/public/v8/state/yearly.json rename to mockserver/public/v9/state/yearly.json diff --git a/web/Earthfile b/web/Earthfile index 6f04847ec2..d0989f166d 100644 --- a/web/Earthfile +++ b/web/Earthfile @@ -36,7 +36,7 @@ build: FROM +prepare RUN pnpm run create-generated-files RUN pnpm version minor - RUN --secret SENTRY_AUTH_TOKEN --secret VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN=ELECTRICITYMAP_PUBLIC_TOKEN pnpm run build + RUN --secret SENTRY_AUTH_TOKEN --secret VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9=ELECTRICITYMAPS_APP_PUBLIC_TOKEN_V9 pnpm run build # Local outputs for debugging SAVE ARTIFACT ./config/world.json AS LOCAL ./config/world.json diff --git a/web/README.md b/web/README.md index 5a2847cc3f..0867f35683 100644 --- a/web/README.md +++ b/web/README.md @@ -42,13 +42,13 @@ Prerequisites: As an eMap internal team member, you can also run the app connected to production API instead of the mockserver: -- Run `VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN='YOUR TOKEN' pnpm dev` +- Run `VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9='YOUR TOKEN' pnpm dev` - Add a `?remote=true` query parameter ### Building for production - Add an environment variable for `SENTRY_AUTH_TOKEN="find it here => https://sentry.io/settings/account/api/auth-tokens/"` -- Add an environment variable for `VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN='YOUR TOKEN'` +- Add an environment variable for `VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9='YOUR TOKEN'` ## Geometries development diff --git a/web/cypress/e2e/countrypanel.spec.ts b/web/cypress/e2e/countrypanel.spec.ts index 34ff368e93..a63c38e8e3 100644 --- a/web/cypress/e2e/countrypanel.spec.ts +++ b/web/cypress/e2e/countrypanel.spec.ts @@ -2,12 +2,12 @@ // TODO: Convert to component test describe('Country Panel', () => { beforeEach(() => { - cy.interceptAPI('v8/state/hourly'); - cy.interceptAPI('v8/meta'); + cy.interceptAPI('v9/state/hourly'); + cy.interceptAPI('v9/meta'); }); it('interacts with details', () => { - cy.interceptAPI('v8/details/hourly/DK-DK2'); + cy.interceptAPI('v9/details/hourly/DK-DK2'); cy.visit('/zone/DK-DK2?lang=en-GB', { onBeforeLoad(win) { @@ -15,8 +15,8 @@ describe('Country Panel', () => { }, }); cy.get('[data-test-id=close-modal]').click(); - cy.waitForAPISuccess('v8/state/hourly'); - cy.waitForAPISuccess('v8/details/hourly/DK-DK2'); + cy.waitForAPISuccess('v9/state/hourly'); + cy.waitForAPISuccess('v9/details/hourly/DK-DK2'); cy.get('[data-test-id=loading-overlay]').should('not.exist'); cy.contains('East Denmark'); cy.contains('Carbon Intensity'); @@ -69,14 +69,14 @@ describe('Country Panel', () => { // TODO bring back when we have a no recent data message it.skip('asserts countryPanel contains "no-recent-data" message', () => { - cy.interceptAPI('v8/details/hourly/UA'); + cy.interceptAPI('v9/details/hourly/UA'); cy.visit('/zone/UA?lang=en-GB', { onBeforeLoad(win) { delete win.navigator.__proto__.serviceWorker; }, }); - cy.waitForAPISuccess('v8/state/hourly'); - cy.waitForAPISuccess('v8/details/hourly/UA'); + cy.waitForAPISuccess('v9/state/hourly'); + cy.waitForAPISuccess('v9/details/hourly/UA'); cy.get('[data-test-id=no-data-overlay-message]') .should('exist') @@ -85,9 +85,9 @@ describe('Country Panel', () => { it('asserts countryPanel contains no parser message when zone has no data', () => { // Add all required API intercepts - cy.interceptAPI('v8/state/hourly'); - cy.interceptAPI('v8/details/hourly/CN'); - cy.interceptAPI('v8/meta'); // Add this if needed + cy.interceptAPI('v9/state/hourly'); + cy.interceptAPI('v9/details/hourly/CN'); + cy.interceptAPI('v9/meta'); // Add this if needed cy.visit('/zone/CN/24h?lang=en-GB', { onBeforeLoad(win) { @@ -95,15 +95,15 @@ describe('Country Panel', () => { }, }); - cy.waitForAPISuccess('v8/state/hourly'); - cy.waitForAPISuccess('v8/details/hourly/CN'); + cy.waitForAPISuccess('v9/state/hourly'); + cy.waitForAPISuccess('v9/details/hourly/CN'); cy.get('[data-test-id=no-parser-message]').should('exist'); }); // TODO(AVO-659): fix flaky tests it.skip('scrolls to anchor element if provided a hash in url', () => { - cy.interceptAPI('v8/details/hourly/DK-DK2'); + cy.interceptAPI('v9/details/hourly/DK-DK2'); cy.visit('/zone/DK-DK2?lang=en-GB#origin_chart', { onBeforeLoad(win) { @@ -111,14 +111,14 @@ describe('Country Panel', () => { }, }); cy.get('[data-test-id=close-modal]').click(); - cy.waitForAPISuccess('v8/state/hourly'); - cy.waitForAPISuccess('v8/details/hourly/DK-DK2'); + cy.waitForAPISuccess('v9/state/hourly'); + cy.waitForAPISuccess('v9/details/hourly/DK-DK2'); // eslint-disable-next-line cypress/require-data-selectors cy.get('#origin_chart').should('be.visible'); }); it.skip('scrolls to anchor element if provided a hash with caps in url', () => { - cy.interceptAPI('v8/details/hourly/DK-DK2'); + cy.interceptAPI('v9/details/hourly/DK-DK2'); cy.visit('/zone/DK-DK2?lang=en-GB#oRiGiN_ChArT', { onBeforeLoad(win) { @@ -126,14 +126,14 @@ describe('Country Panel', () => { }, }); cy.get('[data-test-id=close-modal]').click(); - cy.waitForAPISuccess('v8/state/hourly'); - cy.waitForAPISuccess('v8/details/hourly/DK-DK2'); + cy.waitForAPISuccess('v9/state/hourly'); + cy.waitForAPISuccess('v9/details/hourly/DK-DK2'); // eslint-disable-next-line cypress/require-data-selectors cy.get('#origin_chart').should('be.visible'); }); it('does not scroll or error if provided a non-sensical hash in url', () => { - cy.interceptAPI('v8/details/hourly/DK-DK2'); + cy.interceptAPI('v9/details/hourly/DK-DK2'); cy.visit('/zone/DK-DK2?lang=en-GB##not-a-thing', { onBeforeLoad(win) { @@ -141,8 +141,8 @@ describe('Country Panel', () => { }, }); cy.get('[data-test-id=close-modal]').click(); - cy.waitForAPISuccess('v8/state/hourly'); - cy.waitForAPISuccess('v8/details/hourly/DK-DK2'); + cy.waitForAPISuccess('v9/state/hourly'); + cy.waitForAPISuccess('v9/details/hourly/DK-DK2'); cy.get('[data-test-id=left-panel] [data-test-id=co2-square-value]').should( 'be.visible' ); diff --git a/web/cypress/e2e/map.spec.ts b/web/cypress/e2e/map.spec.ts index a99ad6b07e..b180cb25fa 100644 --- a/web/cypress/e2e/map.spec.ts +++ b/web/cypress/e2e/map.spec.ts @@ -2,10 +2,10 @@ // TODO: Uncomment tests describe('Map', () => { it('interacts with the map', () => { - cy.interceptAPI('v8/state/hourly'); + cy.interceptAPI('v9/state/hourly'); cy.visit('/?lang=en-GB'); cy.get('[data-test-id=close-modal]').click(); - cy.waitForAPISuccess(`v8/state/hourly`); + cy.waitForAPISuccess(`v9/state/hourly`); cy.get('[data-test-id=loading-overlay]').should('not.exist'); // test map diff --git a/web/cypress/e2e/ranking.spec.ts b/web/cypress/e2e/ranking.spec.ts index bf033a1f5f..b8654cb1d4 100644 --- a/web/cypress/e2e/ranking.spec.ts +++ b/web/cypress/e2e/ranking.spec.ts @@ -1,13 +1,13 @@ // TODO: Convert to component test and uncomment test describe('Ranking Panel', () => { it('interacts with details', () => { - cy.interceptAPI('v8/meta'); - cy.interceptAPI('v8/state/hourly'); - cy.interceptAPI('v8/details/hourly/DK-DK2'); + cy.interceptAPI('v9/meta'); + cy.interceptAPI('v9/state/hourly'); + cy.interceptAPI('v9/details/hourly/DK-DK2'); cy.visit('/?lang=en-GB'); cy.get('[data-test-id=close-modal]').click(); - cy.waitForAPISuccess(`v8/meta`); - cy.waitForAPISuccess(`v8/state/hourly`); + cy.waitForAPISuccess(`v9/meta`); + cy.waitForAPISuccess(`v9/state/hourly`); cy.get('[data-test-id=loading-overlay]').should('not.exist'); // Close the ranking panel accordion diff --git a/web/cypress/e2e/timeslider.spec.ts b/web/cypress/e2e/timeslider.spec.ts index 2ce065f4cd..f16ca8bcf4 100644 --- a/web/cypress/e2e/timeslider.spec.ts +++ b/web/cypress/e2e/timeslider.spec.ts @@ -1,7 +1,7 @@ -// import dailyData from '../../../mockserver/public/v8/details/daily/DK-DK2.json'; -import hourlyData from '../../../mockserver/public/v8/details/hourly/DK-DK2.json'; -import monthlyData from '../../../mockserver/public/v8/details/monthly/DK-DK2.json'; -import yearlyData from '../../../mockserver/public/v8/details/yearly/DK-DK2.json'; +// import dailyData from '../../../mockserver/public/v9/details/daily/DK-DK2.json'; +import hourlyData from '../../../mockserver/public/v9/details/hourly/DK-DK2.json'; +import monthlyData from '../../../mockserver/public/v9/details/monthly/DK-DK2.json'; +import yearlyData from '../../../mockserver/public/v9/details/yearly/DK-DK2.json'; // TODO: For some reason the project's date formatter // cannot be imported (webpack compilation error) here @@ -40,22 +40,22 @@ const getco2intensity = (index: number, data: Data) => { describe('TimeController', () => { it('interacts with the timecontroller on map', () => { // Intercepts all API network requests and serves fixtures directly - cy.interceptAPI('v8/state/hourly'); - cy.interceptAPI('v8/details/hourly/DK-DK2'); - cy.interceptAPI('v8/state/daily'); - cy.interceptAPI('v8/state/monthly'); - cy.interceptAPI('v8/state/yearly'); - cy.interceptAPI('v8/details/daily/DK-DK2'); - cy.interceptAPI('v8/details/monthly/DK-DK2'); - cy.interceptAPI('v8/details/yearly/DK-DK2'); + cy.interceptAPI('v9/state/hourly'); + cy.interceptAPI('v9/details/hourly/DK-DK2'); + cy.interceptAPI('v9/state/daily'); + cy.interceptAPI('v9/state/monthly'); + cy.interceptAPI('v9/state/yearly'); + cy.interceptAPI('v9/details/daily/DK-DK2'); + cy.interceptAPI('v9/details/monthly/DK-DK2'); + cy.interceptAPI('v9/details/yearly/DK-DK2'); // Note that we force language here as CI and local machines might display dates differently otherwise cy.visit('/zone/DK-DK2?lang=en-GB'); cy.get('[data-test-id=loading-overlay]').should('not.exist'); cy.get('[data-test-id=close-modal]').click(); // Hourly - cy.waitForAPISuccess(`v8/state/hourly`); - cy.waitForAPISuccess(`v8/details/hourly/DK-DK2`); + cy.waitForAPISuccess(`v9/state/hourly`); + cy.waitForAPISuccess(`v9/details/hourly/DK-DK2`); cy.contains('LIVE'); cy.get('[data-test-id=co2-square-value').should( 'contain.text', @@ -73,8 +73,8 @@ describe('TimeController', () => { // Monthly cy.get('[data-test-id="time-controller-daily"]').click(); - cy.waitForAPISuccess(`v8/state/daily`); - cy.waitForAPISuccess(`v8/details/daily/DK-DK2`); + cy.waitForAPISuccess(`v9/state/daily`); + cy.waitForAPISuccess(`v9/details/daily/DK-DK2`); // cy.get('[data-test-id=co2-square-value').should( // 'contain.text', // getco2intensity(30, dailyData) @@ -95,8 +95,8 @@ describe('TimeController', () => { // Yearly cy.get('[data-test-id="time-controller-monthly"]').click(); - cy.waitForAPISuccess(`v8/state/monthly`); - cy.waitForAPISuccess(`v8/details/monthly/DK-DK2`); + cy.waitForAPISuccess(`v9/state/monthly`); + cy.waitForAPISuccess(`v9/details/monthly/DK-DK2`); cy.get('[data-test-id=co2-square-value').should( 'contain.text', getco2intensity(12, monthlyData) @@ -117,8 +117,8 @@ describe('TimeController', () => { // 5 Years cy.get('[data-test-id="time-controller-yearly"]').click(); - cy.waitForAPISuccess(`v8/state/yearly`); - cy.waitForAPISuccess(`v8/details/yearly/DK-DK2`); + cy.waitForAPISuccess(`v9/state/yearly`); + cy.waitForAPISuccess(`v9/details/yearly/DK-DK2`); cy.get('[data-test-id=co2-square-value').should( 'contain.text', getco2intensity(-1, yearlyData) diff --git a/web/src/api/getMeta.ts b/web/src/api/getMeta.ts index d2ea4a1a42..84fa170065 100644 --- a/web/src/api/getMeta.ts +++ b/web/src/api/getMeta.ts @@ -9,7 +9,7 @@ export interface Meta { } export async function getMeta(): Promise { - const path: URL = new URL(`/v8/${QUERY_KEYS.META}`, getBasePath()); + const path: URL = new URL(`/v9/${QUERY_KEYS.META}`, getBasePath()); try { const response = await fetch(path); diff --git a/web/src/api/getState.ts b/web/src/api/getState.ts index 58dce45b31..d621aff165 100644 --- a/web/src/api/getState.ts +++ b/web/src/api/getState.ts @@ -5,7 +5,7 @@ import type { GridState, RouteParameters } from 'types'; import { TimeAverages } from 'utils/constants'; import { URL_TO_TIME_AVERAGE } from 'utils/state/atoms'; -import { cacheBuster, getBasePath, isValidDate, QUERY_KEYS } from './helpers'; +import { cacheBuster, getBasePath, getHeaders, isValidDate, QUERY_KEYS } from './helpers'; const getState = async ( timeAverage: TimeAverages, @@ -14,16 +14,21 @@ const getState = async ( const shouldQueryHistorical = targetDatetime && isValidDate(targetDatetime) && timeAverage === TimeAverages.HOURLY; const path: URL = new URL( - `v8/state/${timeAverage}${ + `v9/state/${timeAverage}${ shouldQueryHistorical ? `?targetDate=${targetDatetime}` : '' }`, getBasePath() ); + const requestOptions: RequestInit = { + method: 'GET', + headers: await getHeaders(path), + }; + if (!targetDatetime) { path.searchParams.append('cacheKey', cacheBuster()); } - const response = await fetch(path); + const response = await fetch(path, requestOptions); if (response.ok) { const result = (await response.json()) as GridState; return result; diff --git a/web/src/api/getWeatherData.ts b/web/src/api/getWeatherData.ts index 49ce5d7b09..10f550b4e1 100644 --- a/web/src/api/getWeatherData.ts +++ b/web/src/api/getWeatherData.ts @@ -59,7 +59,7 @@ export async function fetchGfsForecast( ): Promise { const targetTime = targetTimeFunction[period](endTime); - const path: URL = new URL(`v8/gfs/${resource}`, getBasePath()); + const path: URL = new URL(`v9/gfs/${resource}`, getBasePath()); path.searchParams.append('refTime', startTime.toISOString()); path.searchParams.append('targetTime', targetTime); diff --git a/web/src/api/getZone.ts b/web/src/api/getZone.ts index d5923b586c..26f9dbbb96 100644 --- a/web/src/api/getZone.ts +++ b/web/src/api/getZone.ts @@ -20,7 +20,7 @@ const getZone = async ( targetDatetime && isValidDate(targetDatetime) && timeAverage === TimeAverages.HOURLY; const path: URL = new URL( - `v8/details/${timeAverage}/${zoneId}${ + `v9/details/${timeAverage}/${zoneId}${ shouldQueryHistorical ? `?targetDate=${targetDatetime}` : '' }`, getBasePath() diff --git a/web/src/api/helpers.ts b/web/src/api/helpers.ts index 0c899a2bd3..33b54a7043 100644 --- a/web/src/api/helpers.ts +++ b/web/src/api/helpers.ts @@ -33,10 +33,10 @@ function isUsingLocalEndpoint(): boolean { function getToken(): string { invariant( - import.meta.env.VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN, - 'VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN is not defined in environment' + import.meta.env.VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9, + 'VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9 is not defined in environment' ); - return String(import.meta.env.VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN); + return String(import.meta.env.VITE_PUBLIC_ELECTRICITYMAP_PUBLIC_TOKEN_V9); } /**