Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Tests

on:
pull_request:

jobs:
test:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
cache-dependency-path: |
package-lock.json
backend/package-lock.json
- run: npm ci
- run: npm ci --prefix backend
- name: Frontend tests (components and hooks)
run: npm test
- name: API tests (GraphQL against in-memory test database)
run: npm run test:api
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Users can mark countries as visited or want to visit. The data is stored in the
- **Backend**: GraphQL (Node.js/TypeScript)
- **Database**: PostgreSQL, installed directly on the group's VM
- **Data**: countries and cities from open datasets (see [Data](#data))
- **Testing**: Vitest (coming)
- **Testing**: Vitest and React Testing Library
- **Linting/formatting**: ESLint and Prettier

## Architecture and Scalability
Expand Down Expand Up @@ -158,10 +158,33 @@ Unless otherwise specified, run these commands from the repository root.
| `npm run format` | Format code with Prettier |
| `npm run format:check` | Check formatting without changing files |
| `npm run preview` | Preview the production build locally |
| `npm test` | Run frontend component and hook tests (Vitest) |
| `npm run test:api` | Run GraphQL API tests against the test database |
| `npm run fetch-data` | Fetch and process country and city data into `data/` |
| `npm run db:check` | Check the database connection (run from `backend/`) |
| `npm run db:seed` | Populate the database with country and city data (run from `backend/`) |

## Testing

Tests use [Vitest](https://vitest.dev/) and React Testing Library. They use fixed test data and require neither the production database nor the NTNU VPN.

| Command | What it runs |
| ------------------ | -------------------------------------------------------------------------------------------------------- |
| `npm test` | Component, hook and Apollo cache tests (`src/**/*.test.ts(x)`). Use `npm run test:watch` for watch mode. |
| `npm run test:api` | GraphQL API tests (`backend/test/`). Same as `npm test` run inside `backend/`. |

Before running the API tests for the first time, install the backend dependencies with `cd backend && npm install`.

The API tests run the real resolvers against an in-memory PostgreSQL database ([PGlite](https://pglite.dev/)) that is created and filled with fixed data from `backend/test/testDb.ts` for each run. Nothing needs to be installed or started.

The tests cover search (case-insensitive), filtering, pagination, `totalCount`, loading/error/empty states, debounce (300 ms), "Load more" (offset, counter, last page, retry) and Apollo cache behaviour (separate searches, merged pages without duplicates).

When server-side sorting/filtering ([#27](https://git.ntnu.no/IT2810-H26/T28-Project-2/issues/27)) and search in both countries and cities ([#55](https://git.ntnu.no/IT2810-H26/T28-Project-2/issues/55)) are implemented, extend `backend/test/graphql.test.ts` and `src/lib/apollo.test.ts` with sorting tests on the full result set before pagination, and separate country/city results.

The workflow `.github/workflows/test.yml` runs both test suites on every pull request.

git.ntnu.no has no GitHub-hosted runners, so the workflow runs on a self-hosted runner installed as a service on the group's NTNU VM (`it2810-28.idi.ntnu.no`). The runner is registered under _Settings → Actions → Runners_. If jobs are stuck in "Queued", check that the runner is online there, or run `sudo ./svc.sh status` in the runner folder on the VM.

## Data

The dataset is generated by `scripts/fetch-data.ts` and saved to `data/`:
Expand Down
Loading