Skip to content

4 - API (tests): Add ('Recorded') End-to-End Tests#229

Merged
RobertRosca merged 16 commits into
mainfrom
feat/api-e2e-rec-tests
Jul 20, 2026
Merged

4 - API (tests): Add ('Recorded') End-to-End Tests#229
RobertRosca merged 16 commits into
mainfrom
feat/api-e2e-rec-tests

Conversation

@RobertRosca

Copy link
Copy Markdown
Member

PR no. 4 of the big refactor.

This PR adds some 'black box' end to end tests which perform API calls to the server to do the tests, and compare the results with expected values. They (almost) never test functions directly, the point of these tests is to be here throughout the refactoring to verify things still (mostly and hopefully) behave the same as before as far as clients/the frontend is concerned.

Details

Lines changed are not as scary as they look, majority of this is external API calls/data that the server needs to be able to respond and stored responses to compare against.

Data

During the tests a few sources of data are used to give the server what it needs to respond and to give the tests something to compare against:

  • DAMNIT data:
    • Proposal 9669 data used - same data that the frontend demo uses, but as sqlite file
    • syrup used to make comparing the api responses easier (alternative is a billion assert expected[x] == result[x] checks)
  • External API calls handled by cassette/py-vcr which records and replays calls
    • Configured to only store required info and to scrub most sensitive details out of the saved responses
      • Keycloak - basically nothing apart from metadata, mocking handled elsewhere
      • MyMdC - all query responses, kinda anonymised (clear plain text info replaced, internal ids remain as they have to be stable, they're not that sensitive, and there's not that good of a way to replace them)
    • Used cassette as it makes managing/updating the recorded data easy

Mock MyMdC Client

Decided to update the mocked client implementation, before there was some hand-written mymdc.json file that it used to respond, how the mock client (1) responds with the cassette data and (2) is just used directly in the tests.

@RobertRosca
RobertRosca force-pushed the refactor/split-runs-package branch from 17e6b7d to 9349f50 Compare July 10, 2026 14:13
@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch 2 times, most recently from bd0db2e to 934a15f Compare July 10, 2026 14:20
@RobertRosca
RobertRosca force-pushed the refactor/split-runs-package branch from 9349f50 to 0d3a985 Compare July 10, 2026 14:20
@RobertRosca RobertRosca changed the title API (tests): Add ('Recorded') End-to-End Tests 4 - API (tests): Add ('Recorded') End-to-End Tests Jul 10, 2026
@CammilleCC

CammilleCC commented Jul 13, 2026

Copy link
Copy Markdown
Member

The CI test workflow would fail if the KeyCloak URL env var is not linked. Could you please add it to the repo accordingly and change the test-api.yml with something similar?:

DW_API_AUTH__SERVER_METADATA_URL: ${{ vars.KEYCLOAK_METADATA_URL }}

Please use the test KeyCloak instance.

@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch from 934a15f to d3b6985 Compare July 17, 2026 06:20
@RobertRosca
RobertRosca force-pushed the refactor/split-runs-package branch from 4afcf68 to c8ef2ed Compare July 17, 2026 06:21
@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch from d3b6985 to 0a44707 Compare July 17, 2026 06:21
@RobertRosca
RobertRosca force-pushed the refactor/split-runs-package branch from c8ef2ed to c5c9b7f Compare July 17, 2026 08:40
@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch from 0a44707 to 9288103 Compare July 17, 2026 08:40
@RobertRosca
RobertRosca force-pushed the refactor/split-runs-package branch from c5c9b7f to c38fdcc Compare July 17, 2026 09:09
@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch from 9288103 to d15702f Compare July 17, 2026 09:09
@RobertRosca
RobertRosca force-pushed the refactor/split-runs-package branch from c38fdcc to 2d39500 Compare July 17, 2026 09:11
@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch from d15702f to 7b7216a Compare July 17, 2026 09:11
Base automatically changed from refactor/split-runs-package to main July 17, 2026 09:12
@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch 2 times, most recently from 92d115c to 22719a6 Compare July 17, 2026 09:12
@RobertRosca
RobertRosca marked this pull request as ready for review July 17, 2026 09:19
@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch from 22719a6 to a454529 Compare July 17, 2026 10:46
@RobertRosca

Copy link
Copy Markdown
Member Author

Done, thanks. Changed test-api.yml to source it from the repo variable (commit 3967e92e):

DW_API_AUTH__SERVER_METADATA_URL: ${{ vars.KEYCLOAK_METADATA_URL }}

and set the repo Actions variable KEYCLOAK_METADATA_URL to the test KeyCloak instance's discovery URL — https://keycloak-console.desy.de/auth/realms/XFEL/.well-known/openid-configuration — which matches the host the e2e cassettes were recorded against, so vcrpy replays them instead of hitting the network. Re-running CI now.

@CammilleCC

Copy link
Copy Markdown
Member

I mispoke: the KeyCloak instance doesn't matter, it's the same metadata server thoughout.

LGTM

@RobertRosca
RobertRosca force-pushed the feat/api-e2e-rec-tests branch from 3967e92 to 9dd4463 Compare July 20, 2026 09:25
@RobertRosca
RobertRosca merged commit 196ff34 into main Jul 20, 2026
1 check passed
@RobertRosca
RobertRosca deleted the feat/api-e2e-rec-tests branch July 20, 2026 09:28
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.

2 participants