LOC-24 Close and re-open DB connection, and implement E2E test
These are part of one commit because implementing the test revealed a potential race.
API requests can fail because of lock contention with the test script, leading to a failed test (and often then an exception when we try to query the database).
Now, we open a new connection to the database just before querying and then close straight after to ensure locks do not become an issue.
This wouldn't be an issue with a production deployment as the DB is in memory and only ever being accessed by the one thread.