From eade3d7af68614aaf48a3e9e933663603d2f0f49 Mon Sep 17 00:00:00 2001 From: Niki Wycherley Date: Wed, 23 Apr 2025 14:09:06 +0100 Subject: [PATCH 01/10] fixing issues on sonarcloud https://eaflood.atlassian.net/browse/FSR-1324 From 55e85cb8902170780fcc0638845149524c795145 Mon Sep 17 00:00:00 2001 From: Ash Date: Mon, 11 Aug 2025 19:23:34 +0100 Subject: [PATCH 02/10] test fn. update ci.yml --- .github/workflows/ci.yml | 20 +------------------- server/models/floods-message.js | 11 ++++++++++- test/models/flood-message.js | 11 ++++++++++- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a23392d6..9ef138c6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,26 +47,8 @@ jobs: args: > -Dsonar.organization=defra -Dsonar.projectKey=DEFRA_flood-app + -Dsonar.sources=server -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** -Dsonar.coverage.exclusions=**/server/routes/status.js - -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} - -Dsonar.pullrequest.branch=${{ github.head_ref }} - -Dsonar.pullrequest.base=${{ github.base_ref }} - - - name: Analyse code quality (non-PR) - if: github.event_name != 'pull_request' - uses: sonarsource/sonarqube-scan-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - args: > - -Dsonar.organization=defra - -Dsonar.projectKey=DEFRA_flood-app - -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** - -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info - -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** - -Dsonar.coverage.exclusions=**/server/routes/status.js - -Dsonar.branch.name=${{ github.ref_name }} diff --git a/server/models/floods-message.js b/server/models/floods-message.js index 6b1cf3c35..ebd7d09c0 100644 --- a/server/models/floods-message.js +++ b/server/models/floods-message.js @@ -8,6 +8,15 @@ const formatFloodWarnings = (floods, isLocalised) => { return text.replace('$counts', counts) } +const getSonar = () => { + return { + sonar: { + organization: 'defra', + projectKey: 'DEFRA_flood-app' + } + } +} + const getText = (all, isLocalised) => `There ${all === 1 ? 'is' : 'are'} currently $counts in force${isLocalised ? ' at this location' : ''}.` const getCounts = (severeWarnings, warnings, alerts) => { @@ -34,4 +43,4 @@ const getSevereWarnings = severeWarnings => `${severeWarnings === 1 ? 'one' : se const displayGetWarningsLink = warnings => `${warnings === 1 ? 'one' : warnings} flood warning${warnings > 1 ? 's' : ''}` const getAlerts = alerts => `${alerts === 1 ? 'one' : alerts} flood alert${alerts > 1 ? 's' : ''}` -module.exports = { formatFloodWarnings, getSevereWarnings, displayGetWarningsLink } +module.exports = { formatFloodWarnings, getSevereWarnings, displayGetWarningsLink, getSonar } diff --git a/test/models/flood-message.js b/test/models/flood-message.js index 1e7519bf4..c51aebbb3 100644 --- a/test/models/flood-message.js +++ b/test/models/flood-message.js @@ -3,10 +3,19 @@ const Lab = require('@hapi/lab') const { expect } = require('@hapi/code') const { describe, it } = (exports.lab = Lab.script()) -const { getSevereWarnings, displayGetWarningsLink } = require('../../server/models/floods-message') +const { getSevereWarnings, displayGetWarningsLink, getSonar } = require('../../server/models/floods-message') describe('Model - Flood Message', () => { describe('getSevereWarnings', () => { + it('should get sonar', () => { + expect(getSonar()).to.equal({ + sonar: { + organization: 'defra', + projectKey: 'DEFRA_flood-app' + } + }) + }) + it('should return "one severe flood warning" for a single severe warning', () => { expect(getSevereWarnings(1)).to.equal('one severe flood warning') }) From 6d836c3a53c7bd3425921c6e91a2a46bdb0d3043 Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 12 Aug 2025 08:47:09 +0100 Subject: [PATCH 03/10] debug sonar --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ef138c6b..02fac2497 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,8 +37,7 @@ jobs: run: | npm run unit-test - - name: Analyse code quality (pull_request) - if: github.event_name == 'pull_request' + - name: Analyse code quality uses: sonarsource/sonarqube-scan-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -48,6 +47,8 @@ jobs: -Dsonar.organization=defra -Dsonar.projectKey=DEFRA_flood-app -Dsonar.sources=server + -Dsonar.test=server + -Dsonar.test.inclusions=**/test/** -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** From 61b16bbf1e350ac31fc78456bd0a3fb307f9c5e9 Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 12 Aug 2025 08:49:29 +0100 Subject: [PATCH 04/10] sonar config fix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02fac2497..8d9d17b1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: -Dsonar.organization=defra -Dsonar.projectKey=DEFRA_flood-app -Dsonar.sources=server - -Dsonar.test=server + -Dsonar.tests=server -Dsonar.test.inclusions=**/test/** -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info From ab58ad3b0b170421ecf7d1743760c13fe94ec091 Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 12 Aug 2025 08:52:51 +0100 Subject: [PATCH 05/10] debug: remove coverage of fn --- test/models/flood-message.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/models/flood-message.js b/test/models/flood-message.js index c51aebbb3..f82308002 100644 --- a/test/models/flood-message.js +++ b/test/models/flood-message.js @@ -3,18 +3,18 @@ const Lab = require('@hapi/lab') const { expect } = require('@hapi/code') const { describe, it } = (exports.lab = Lab.script()) -const { getSevereWarnings, displayGetWarningsLink, getSonar } = require('../../server/models/floods-message') +const { getSevereWarnings, displayGetWarningsLink } = require('../../server/models/floods-message') describe('Model - Flood Message', () => { describe('getSevereWarnings', () => { - it('should get sonar', () => { - expect(getSonar()).to.equal({ - sonar: { - organization: 'defra', - projectKey: 'DEFRA_flood-app' - } - }) - }) + // it('should get sonar', () => { + // expect(getSonar()).to.equal({ + // sonar: { + // organization: 'defra', + // projectKey: 'DEFRA_flood-app' + // } + // }) + // }) it('should return "one severe flood warning" for a single severe warning', () => { expect(getSevereWarnings(1)).to.equal('one severe flood warning') From 50eb745a19f0b16a60540e8fc64094992e05f824 Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 12 Aug 2025 11:18:59 +0100 Subject: [PATCH 06/10] debug main --- .github/workflows/ci.yml | 139 +++++++++++++++++++++++++-------------- 1 file changed, 91 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d9d17b1a..82c6e8b66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,55 +1,98 @@ name: CI -on: [push, pull_request] +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "**" ] + workflow_dispatch: + inputs: + target_ref: + description: "Branch (or SHA) to analyze as a PR against main" + type: string + required: false + default: main env: TZ: 'Europe/London' jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install nodejs - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - - name: Install node dependencies - run: npm ci --engine-strict - - - name: Run linting - run: npm run lint - - - name: Run unit tests - env: - FLOOD_APP_BING_KEY: "${{ secrets.FLOOD_APP_BING_KEY }}" - FLOOD_APP_BING_KEY_LOCATION: "${{ secrets.FLOOD_APP_BING_KEY_LOCATION }}" - FLOOD_APP_BING_KEY_MAP: "${{ secrets.FLOOD_APP_BING_KEY_MAP }}" - FLOOD_APP_BING_URL: "${{ secrets.FLOOD_APP_BING_URL }}" - FLOOD_APP_NRW_STATION_URL: "${{ secrets.FLOOD_APP_NRW_STATION_URL }}" - FLOOD_APP_SESSION_PASSWORD: "${{ secrets.FLOOD_APP_SESSION_PASSWORD }}" - run: | - npm run unit-test - - - name: Analyse code quality - uses: sonarsource/sonarqube-scan-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - args: > - -Dsonar.organization=defra - -Dsonar.projectKey=DEFRA_flood-app - -Dsonar.sources=server - -Dsonar.tests=server - -Dsonar.test.inclusions=**/test/** - -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** - -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info - -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** - -Dsonar.coverage.exclusions=**/server/routes/status.js + build: + runs-on: ubuntu-latest + + steps: + # Checkout: use selected ref for manual runs; otherwise use the event's default ref + - name: Checkout (manual run) + if: github.event_name == 'workflow_dispatch' + uses: actions/checkout@v4 + with: + ref: ${{ inputs.target_ref }} + fetch-depth: 0 + + - name: Checkout (push/PR) + if: github.event_name != 'workflow_dispatch' + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install nodejs + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + + - name: Install node dependencies + run: npm ci --engine-strict + + - name: Run linting + run: npm run lint + + - name: Run unit tests + env: + FLOOD_APP_BING_KEY: "${{ secrets.FLOOD_APP_BING_KEY }}" + FLOOD_APP_BING_KEY_LOCATION: "${{ secrets.FLOOD_APP_BING_KEY_LOCATION }}" + FLOOD_APP_BING_KEY_MAP: "${{ secrets.FLOOD_APP_BING_KEY_MAP }}" + FLOOD_APP_BING_URL: "${{ secrets.FLOOD_APP_BING_URL }}" + FLOOD_APP_NRW_STATION_URL: "${{ secrets.FLOOD_APP_NRW_STATION_URL }}" + FLOOD_APP_SESSION_PASSWORD: "${{ secrets.FLOOD_APP_SESSION_PASSWORD }}" + run: npm run unit-test + + # -------- Sonar: normal branch/PR behaviour on push/pull_request ---------- + - name: Analyse code quality (normal CI) + if: github.event_name != 'workflow_dispatch' + uses: sonarsource/sonarqube-scan-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.organization=defra + -Dsonar.projectKey=DEFRA_flood-app + -Dsonar.sources=server + -Dsonar.tests=server + -Dsonar.test.inclusions=**/test/** + -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info + -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** + -Dsonar.coverage.exclusions=**/server/routes/status.js + + # -------- Sonar: PR-style analysis against main for manual runs ---------- + - name: Analyse code quality (manual run as PR → main) + if: github.event_name == 'workflow_dispatch' + uses: sonarsource/sonarqube-scan-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.organization=defra + -Dsonar.projectKey=DEFRA_flood-app + -Dsonar.sources=server + -Dsonar.tests=server + -Dsonar.test.inclusions=**/test/** + -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info + -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** + -Dsonar.coverage.exclusions=**/server/routes/status.js + -Dsonar.pullrequest.key=${{ github.run_id }} + -Dsonar.pullrequest.branch=${{ inputs.target_ref }} + -Dsonar.pullrequest.base=main From b4ff88dacf5c8d5d89946c3a534aa6dd712341fd Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 14 Aug 2025 10:26:04 +0100 Subject: [PATCH 07/10] debug sonar --- .github/workflows/ci.yml | 139 +++++++++++--------------------- server/models/floods-message.js | 1 + test/models/flood-message.js | 19 ++--- 3 files changed, 59 insertions(+), 100 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 82c6e8b66..8d9d17b1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,98 +1,55 @@ name: CI -on: - push: - branches: [ "**" ] - pull_request: - branches: [ "**" ] - workflow_dispatch: - inputs: - target_ref: - description: "Branch (or SHA) to analyze as a PR against main" - type: string - required: false - default: main +on: [push, pull_request] env: TZ: 'Europe/London' jobs: - build: - runs-on: ubuntu-latest - - steps: - # Checkout: use selected ref for manual runs; otherwise use the event's default ref - - name: Checkout (manual run) - if: github.event_name == 'workflow_dispatch' - uses: actions/checkout@v4 - with: - ref: ${{ inputs.target_ref }} - fetch-depth: 0 - - - name: Checkout (push/PR) - if: github.event_name != 'workflow_dispatch' - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install nodejs - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - - name: Install node dependencies - run: npm ci --engine-strict - - - name: Run linting - run: npm run lint - - - name: Run unit tests - env: - FLOOD_APP_BING_KEY: "${{ secrets.FLOOD_APP_BING_KEY }}" - FLOOD_APP_BING_KEY_LOCATION: "${{ secrets.FLOOD_APP_BING_KEY_LOCATION }}" - FLOOD_APP_BING_KEY_MAP: "${{ secrets.FLOOD_APP_BING_KEY_MAP }}" - FLOOD_APP_BING_URL: "${{ secrets.FLOOD_APP_BING_URL }}" - FLOOD_APP_NRW_STATION_URL: "${{ secrets.FLOOD_APP_NRW_STATION_URL }}" - FLOOD_APP_SESSION_PASSWORD: "${{ secrets.FLOOD_APP_SESSION_PASSWORD }}" - run: npm run unit-test - - # -------- Sonar: normal branch/PR behaviour on push/pull_request ---------- - - name: Analyse code quality (normal CI) - if: github.event_name != 'workflow_dispatch' - uses: sonarsource/sonarqube-scan-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - args: > - -Dsonar.organization=defra - -Dsonar.projectKey=DEFRA_flood-app - -Dsonar.sources=server - -Dsonar.tests=server - -Dsonar.test.inclusions=**/test/** - -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** - -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info - -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** - -Dsonar.coverage.exclusions=**/server/routes/status.js - - # -------- Sonar: PR-style analysis against main for manual runs ---------- - - name: Analyse code quality (manual run as PR → main) - if: github.event_name == 'workflow_dispatch' - uses: sonarsource/sonarqube-scan-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - args: > - -Dsonar.organization=defra - -Dsonar.projectKey=DEFRA_flood-app - -Dsonar.sources=server - -Dsonar.tests=server - -Dsonar.test.inclusions=**/test/** - -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** - -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info - -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** - -Dsonar.coverage.exclusions=**/server/routes/status.js - -Dsonar.pullrequest.key=${{ github.run_id }} - -Dsonar.pullrequest.branch=${{ inputs.target_ref }} - -Dsonar.pullrequest.base=main + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install nodejs + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + + - name: Install node dependencies + run: npm ci --engine-strict + + - name: Run linting + run: npm run lint + + - name: Run unit tests + env: + FLOOD_APP_BING_KEY: "${{ secrets.FLOOD_APP_BING_KEY }}" + FLOOD_APP_BING_KEY_LOCATION: "${{ secrets.FLOOD_APP_BING_KEY_LOCATION }}" + FLOOD_APP_BING_KEY_MAP: "${{ secrets.FLOOD_APP_BING_KEY_MAP }}" + FLOOD_APP_BING_URL: "${{ secrets.FLOOD_APP_BING_URL }}" + FLOOD_APP_NRW_STATION_URL: "${{ secrets.FLOOD_APP_NRW_STATION_URL }}" + FLOOD_APP_SESSION_PASSWORD: "${{ secrets.FLOOD_APP_SESSION_PASSWORD }}" + run: | + npm run unit-test + + - name: Analyse code quality + uses: sonarsource/sonarqube-scan-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.organization=defra + -Dsonar.projectKey=DEFRA_flood-app + -Dsonar.sources=server + -Dsonar.tests=server + -Dsonar.test.inclusions=**/test/** + -Dsonar.exclusions=**/node_modules/**,**/test/**,**/test-output/** + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info + -Dsonar.javascript.exclusions=**/node_modules/**,**/test/**,**/test-output/**,**/mock/**,**/server/dist/**,**/server/src/**,**/service-down/** + -Dsonar.coverage.exclusions=**/server/routes/status.js diff --git a/server/models/floods-message.js b/server/models/floods-message.js index ebd7d09c0..fcb4fe9a9 100644 --- a/server/models/floods-message.js +++ b/server/models/floods-message.js @@ -11,6 +11,7 @@ const formatFloodWarnings = (floods, isLocalised) => { const getSonar = () => { return { sonar: { + num: 5032000, organization: 'defra', projectKey: 'DEFRA_flood-app' } diff --git a/test/models/flood-message.js b/test/models/flood-message.js index f82308002..2c39ad5b1 100644 --- a/test/models/flood-message.js +++ b/test/models/flood-message.js @@ -3,18 +3,19 @@ const Lab = require('@hapi/lab') const { expect } = require('@hapi/code') const { describe, it } = (exports.lab = Lab.script()) -const { getSevereWarnings, displayGetWarningsLink } = require('../../server/models/floods-message') +const { getSevereWarnings, displayGetWarningsLink, getSonar } = require('../../server/models/floods-message') describe('Model - Flood Message', () => { describe('getSevereWarnings', () => { - // it('should get sonar', () => { - // expect(getSonar()).to.equal({ - // sonar: { - // organization: 'defra', - // projectKey: 'DEFRA_flood-app' - // } - // }) - // }) + it('should get sonar', () => { + expect(getSonar()).to.equal({ + sonar: { + num: 5032000, + organization: 'defra', + projectKey: 'DEFRA_flood-app' + } + }) + }) it('should return "one severe flood warning" for a single severe warning', () => { expect(getSevereWarnings(1)).to.equal('one severe flood warning') From 9aadefb4100117b1eea73be10b80ba12bc8ffcae Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 14 Aug 2025 10:41:19 +0100 Subject: [PATCH 08/10] debug sonar --- server/models/floods-message.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/models/floods-message.js b/server/models/floods-message.js index fcb4fe9a9..cdc43acc6 100644 --- a/server/models/floods-message.js +++ b/server/models/floods-message.js @@ -18,6 +18,16 @@ const getSonar = () => { } } +const getSonars = () => { + return { + sonar: { + num: 5032000, + organization: 'defra', + projectKey: 'DEFRA_flood-app' + } + } +} + const getText = (all, isLocalised) => `There ${all === 1 ? 'is' : 'are'} currently $counts in force${isLocalised ? ' at this location' : ''}.` const getCounts = (severeWarnings, warnings, alerts) => { @@ -44,4 +54,4 @@ const getSevereWarnings = severeWarnings => `${severeWarnings === 1 ? 'one' : se const displayGetWarningsLink = warnings => `${warnings === 1 ? 'one' : warnings} flood warning${warnings > 1 ? 's' : ''}` const getAlerts = alerts => `${alerts === 1 ? 'one' : alerts} flood alert${alerts > 1 ? 's' : ''}` -module.exports = { formatFloodWarnings, getSevereWarnings, displayGetWarningsLink, getSonar } +module.exports = { formatFloodWarnings, getSevereWarnings, displayGetWarningsLink, getSonar, getSonars } From acfb69726198b944ac60c0e70fe5747a87328461 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 14 Aug 2025 10:46:28 +0100 Subject: [PATCH 09/10] debug sonar --- test/models/flood-message.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/test/models/flood-message.js b/test/models/flood-message.js index 2c39ad5b1..1e7519bf4 100644 --- a/test/models/flood-message.js +++ b/test/models/flood-message.js @@ -3,20 +3,10 @@ const Lab = require('@hapi/lab') const { expect } = require('@hapi/code') const { describe, it } = (exports.lab = Lab.script()) -const { getSevereWarnings, displayGetWarningsLink, getSonar } = require('../../server/models/floods-message') +const { getSevereWarnings, displayGetWarningsLink } = require('../../server/models/floods-message') describe('Model - Flood Message', () => { describe('getSevereWarnings', () => { - it('should get sonar', () => { - expect(getSonar()).to.equal({ - sonar: { - num: 5032000, - organization: 'defra', - projectKey: 'DEFRA_flood-app' - } - }) - }) - it('should return "one severe flood warning" for a single severe warning', () => { expect(getSevereWarnings(1)).to.equal('one severe flood warning') }) From 3303ac515555633c6d39efadf15c3a1d1570fe0c Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 14 Aug 2025 10:57:22 +0100 Subject: [PATCH 10/10] remove test fn --- server/models/floods-message.js | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/server/models/floods-message.js b/server/models/floods-message.js index cdc43acc6..6b1cf3c35 100644 --- a/server/models/floods-message.js +++ b/server/models/floods-message.js @@ -8,26 +8,6 @@ const formatFloodWarnings = (floods, isLocalised) => { return text.replace('$counts', counts) } -const getSonar = () => { - return { - sonar: { - num: 5032000, - organization: 'defra', - projectKey: 'DEFRA_flood-app' - } - } -} - -const getSonars = () => { - return { - sonar: { - num: 5032000, - organization: 'defra', - projectKey: 'DEFRA_flood-app' - } - } -} - const getText = (all, isLocalised) => `There ${all === 1 ? 'is' : 'are'} currently $counts in force${isLocalised ? ' at this location' : ''}.` const getCounts = (severeWarnings, warnings, alerts) => { @@ -54,4 +34,4 @@ const getSevereWarnings = severeWarnings => `${severeWarnings === 1 ? 'one' : se const displayGetWarningsLink = warnings => `${warnings === 1 ? 'one' : warnings} flood warning${warnings > 1 ? 's' : ''}` const getAlerts = alerts => `${alerts === 1 ? 'one' : alerts} flood alert${alerts > 1 ? 's' : ''}` -module.exports = { formatFloodWarnings, getSevereWarnings, displayGetWarningsLink, getSonar, getSonars } +module.exports = { formatFloodWarnings, getSevereWarnings, displayGetWarningsLink }