Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[i18n-Audio] Add DB schemas and shared API/store stubs #3987

Merged
merged 7 commits into from
Sep 21, 2023

Conversation

kofi-q
Copy link
Contributor

@kofi-q kofi-q commented Sep 21, 2023

Overview

🔍 Easier to review individual commits.

Related spec here.

Adding:

  • DB schemas to Mark, Scan, Mark-Scan
    • (Technically, Scan doesn't need the audio tables, but it made things simpler to have everything be identical across apps - the apps can then enable/disable audio functionality as needed).
  • Shared backend API handler and store stubs
    • Wanted to avoid duplicating code across 3 apps and keeping them in sync.
    • We're not currently architected to naturally support shared API/store logic in this way, so I'm open to pushback if it feels like this is breaking patterns a bit too much.

Testing Plan

  • Added a shared test runner invoked by each app to verify the shared handlers and store logic work in the context of the app (which, in turn will help ensure the DB schemas stay consistent, since I couldn't find an easy way to extract the table schemas to a common location)

Checklist

  • [ ] I have added logging where appropriate to any new user actions, system updates such as file reads or storage writes, or errors introduced.
  • [ ] I have added a screenshot and/or video to this PR to demo the change
  • [ ] I have added the "user_facing_change" label to this PR to automate an announcement in #machine-product-updates

@kofi-q kofi-q requested a review from arsalansufi September 21, 2023 15:47
@kofi-q kofi-q requested a review from a team as a code owner September 21, 2023 15:47
@kofi-q kofi-q requested review from adghayes and removed request for a team and adghayes September 21, 2023 15:47
Copy link
Contributor

@arsalansufi arsalansufi left a comment

Choose a reason for hiding this comment

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

Looks great! Really liking the new sharing patterns, with one question around the testing pattern


create table ui_string_audio_keys (
language_code text primary key,
data text not null, -- JSON blob - see libs/types/UiStringTranslationsSchema
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to reference libs/types/UiStringAudioKeysSchema here (and same in the other schema.sql files)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks for the catch!

);

create table audio_clips (
id text not null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Double checking my understanding: These id values are the same as the audio keys as described in the spec, e.g. d5b21f, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, these correspond the audio keys - and I'm realising the inconsistent naming is confusing (especially once I started building on this PR 😅 ). I think I'm going to settle on id and change the property names in related schemas to id/audioId to make things more consistent

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I like that!

return new Store(DbClient.fileClient(dbPath, SchemaPath));
const client = DbClient.fileClient(dbPath, SchemaPath);
const uiStringsStore = createUiStringStore(client);
return new Store(client, uiStringsStore);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I like these patterns that you're setting for shared store and API code. I'd been with experimenting with similar ideas recently, e.g.

import {
clearCastVoteRecordHashes,
getCastVoteRecordRootHash,
updateCastVoteRecordHashes,
} from '@votingworks/auth';

getCastVoteRecordRootHash(): string {
return getCastVoteRecordRootHash(this.client);
}
updateCastVoteRecordHashes(cvrId: string, cvrHash: string): void {
updateCastVoteRecordHashes(this.client, cvrId, cvrHash);
}
clearCastVoteRecordHashes(): void {
clearCastVoteRecordHashes(this.client);
}

I like that what you're setting up is more automatic than what I'd set up. Looks like we can add new methods to libs/backend and the app stores and APIs will automatically update 🪄.

Re SQL schemas, I too just copied the schemas since we don't yet have a clear pattern for sharing those - that seems fine to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! I missed those - makes me feel better knowing that we have other instances where we're sharing the query code

@@ -240,3 +254,40 @@ test('configureWithSampleBallotPackageForIntegrationTest configures electionGene
const electionDefinitionResult = await apiClient.getElectionDefinition();
expect(electionDefinitionResult).toEqual(electionGeneralDefinition);
});

test('installs UI Strings API', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm taking a sec to wrap my mind around the difference between these tests and the tests in app.ui_strings.test.ts, specifically trying to understand why the former are necessary.

It seems like the main thing tested in this file that's not tested in app.ui_strings.test.ts is the Grout client's ability to access the endpoints. Otherwise, app.ui_strings.test.ts tests everything tested in here and more (installation of the UI strings API + actual implementation since it doesn't mock).

I wonder if we can just assume that the Grout client will work fine, given libs/grout tests. Or alternatively, have the shared ui_strings_api_test_runner.ts create a Grout client for testing.

I might be missing something! Just wondering if we can get rid of these app.test.ts tests so that everything, tests included, really is automatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks - I lost perspective on this after a couple iterations. Initially had the shared test runner just taking in a store input and testing that, but you're spot on WRT not needing these tests since the test runner is testing against an app's actual API.
Will go ahead and drop these!

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Figured that might've been the case re iterations!

Copy link
Contributor

@arsalansufi arsalansufi left a comment

Choose a reason for hiding this comment

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

LGTM!

@kofi-q kofi-q merged commit d9a9d06 into main Sep 21, 2023
@kofi-q kofi-q deleted the i18n-audio-db-schemas branch September 21, 2023 19:03
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