Skip to content

Implementing unit test and input validation for API along with structured error handling - #258

Merged
CharlieWells13 merged 7 commits into
mainfrom
implementing-testing-framework
Jan 16, 2026
Merged

CharlieWells13 merged 7 commits into
mainfrom
implementing-testing-framework

Conversation

@Hbarsanti

@Hbarsanti Hbarsanti commented Nov 10, 2025 •

Copy link
Copy Markdown
Collaborator

Issue link: #261 , #268

Started looking deeper into implementing unit tests, specifically with React Testing Framework.

Updated the Env Configuration so the wind velocity input has a stable data-testid, and added a Jest/RTL suite (EnvironmentConfiguration.test.jsx) that mocks Google Maps to exercise the map-click origin update and the wind-force clamping logic.

To run the tests:
npm test

@Hbarsanti

Copy link
Copy Markdown
Collaborator Author

Still working to get the backend and frontend linked together, so I can start writing some tests for the backend.

@Hbarsanti Hbarsanti changed the title Implementing unit test and input validation for the frontend Implementing unit test and input validation for API Nov 17, 2025
Comment on lines +59 to +92
frontend-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "16"

- name: Install dependencies
run: |
cd frontend
npm install

- name: Run frontend tests
run: |
cd frontend
npm run test:ci

- name: Upload coverage report as artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 11 months ago

To address the problem, a permissions block should be added explicitly to the workflow file to restrict the access of the GITHUB_TOKEN used by the jobs. The recommended least privilege baseline is contents: read, which covers basic operations like code checkout and reading artifacts, and is sufficient for almost all build/test/upload workflows. This block can be added at the root of the workflow file (just below the name: and before on:) to apply to all jobs, or per-job if finer granularity is needed. For this case, adding a root-level permissions: block with contents: read is the best and simplest solution. Edit the file .github/workflows/frontend-ci.yml by inserting the following:

permissions:
  contents: read

directly after the name: line, at line 2.

Suggested changeset 1
.github/workflows/frontend-ci.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/frontend-ci.yml b/.github/workflows/frontend-ci.yml
--- a/.github/workflows/frontend-ci.yml
+++ b/.github/workflows/frontend-ci.yml
@@ -1,4 +1,6 @@
 name: Frontend CI
+permissions:
+  contents: read
 
 on:
   push:
EOF
@@ -1,4 +1,6 @@
name: Frontend CI
permissions:
contents: read

on:
push:
Copilot is powered by AI and may make mistakes. Always verify output.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a valuable and quick win for security.

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "16"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully trivial updates like this will go away with the work @ahmedbektic is doing.

@Hbarsanti Hbarsanti changed the title Implementing unit test and input validation for API Implementing unit test and input validation for API along with structured error handling Dec 5, 2025
@CharlieWells13
CharlieWells13 self-requested a review as a code owner January 16, 2026 19:22

@CharlieWells13 CharlieWells13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, this should develop into something really useful over time. It would be nice if there was a file somewhere detailing every test and what is does in detail.

@CharlieWells13
CharlieWells13 merged commit 12c286c into main Jan 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants