From a8e4e5145b36cab7ef0b29e1f284ea0b1e1ae0eb Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Sat, 22 Jul 2023 15:46:52 -0400 Subject: [PATCH] add tests --- Makefile | 3 +- client/src/state.ts | 11 ++++-- client/src/track.ts | 3 +- client/src/views/Login.vue | 13 +++++-- client/src/views/TableView.vue | 5 +++ docker-compose_test.yml | 45 +++++++++++++++++++++++ server/Cargo.lock | 14 ++++++++ server/Cargo.toml | 1 + server/src/api/auth.rs | 41 +++++++++++++++------ server/src/api/mod.rs | 4 ++- server/src/api/tracks.rs | 66 +++++++++++++++++++++++----------- server/src/api/update.rs | 9 +++-- server/src/db/mod.rs | 33 +++++++++++++++++ server/src/lib.rs | 8 +++++ server/src/main.rs | 27 ++------------ server/shell.nix => shell.nix | 5 +++ test.py | 61 +++++++++++++++++++++++++++++++ 17 files changed, 283 insertions(+), 66 deletions(-) create mode 100644 docker-compose_test.yml create mode 100644 server/src/lib.rs rename server/shell.nix => shell.nix (59%) create mode 100644 test.py diff --git a/Makefile b/Makefile index 274c3d3..bc6334b 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,5 @@ start-server: build-client clean: docker compose down - rm -r server/public/ client/dist/ + -rm -r server/public/ client/dist/ + diff --git a/client/src/state.ts b/client/src/state.ts index 13e3312..67c0955 100644 --- a/client/src/state.ts +++ b/client/src/state.ts @@ -26,6 +26,7 @@ class AppState { tracks: Array state: State user?: LoggedInUser + source?: EventSource constructor() { this.tracks = new Array @@ -79,16 +80,22 @@ class AppState { window.location = window.location }) window.addEventListener('beforeunload', () => source.close()) + this.source = source } async repopulate() { + if (!this.user) { + this.tracks = [] + return + } this.state = State.Fetching this.tracks = await Track.fetchAll() + this.source?.close() + this.streamUpdatesFromServer() + this.state = State.Fetched } async populate() { if (this.state != State.Unfetched) return await this.repopulate() - this.streamUpdatesFromServer() - this.state = State.Fetched } async taskCompleted(track: Track, date: Date): Promise { const query = dateQuery(date) diff --git a/client/src/track.ts b/client/src/track.ts index 83947a3..9893eca 100644 --- a/client/src/track.ts +++ b/client/src/track.ts @@ -1,4 +1,5 @@ import { error } from "./error" +import { Tick, ITick } from './ticks' export interface ITrack { id?: number @@ -97,4 +98,4 @@ export class Track implements ITrack { } return [] } -} \ No newline at end of file +} diff --git a/client/src/views/Login.vue b/client/src/views/Login.vue index 2ef2efe..9f21ab0 100644 --- a/client/src/views/Login.vue +++ b/client/src/views/Login.vue @@ -1,6 +1,7 @@