[7] Add rollback tests - #342
Conversation
JonoPrest
commented
Nov 18, 2024
- Adds tests for entity history db functions
- Fixes an error in the prune stale history function
| FROM | ||
| public.${sql(tableName)} | ||
| WHERE | ||
| serial >= (SELECT serial FROM first_change) |
There was a problem hiding this comment.
This was a bug, caught by the test 🐛
| | DELETE => | ||
| let {id} = v["entityData"]->(Utils.magic: Js.Dict.t<unknown> => entityIdOnly) | ||
| Delete({id: id}) |
There was a problem hiding this comment.
Just stripping the null fields instead of casting. Helps making the tests pass.
| type testEntity = { | ||
| id: string, | ||
| fieldA: int, | ||
| fieldB: option<string>, | ||
| } | ||
|
|
||
| let testEntitySchema: S.t<testEntity> = S.schema(s => { | ||
| id: s.matches(S.string), | ||
| fieldA: s.matches(S.int), | ||
| fieldB: s.matches(S.option(S.string)), | ||
| }) | ||
|
|
There was a problem hiding this comment.
Moved these into an entity module to help with tests.
| fieldB: option<string>, | ||
| } | ||
|
|
||
| let name = "TestEntity"->(Utils.magic: string => Enums.EntityType.t) |
There was a problem hiding this comment.
This is dangerous if it were to match on the entity type but right now the code doesn't do that.
There was a problem hiding this comment.
In the future I'd actually want to:
- Remove the enum for entity type
- Change entityMod to simply be a record type
There was a problem hiding this comment.
Sounds good 💪🏼, I have some ideas as well. Eg. I'm keen to derive the table from the rescript schema. And do some runtime validations there to start making it more pluggable as a library without needing a gql schema file.
There was a problem hiding this comment.
This is exactly how I visioned it myself 👍
| sql, | ||
| ~isUnorderedMultichainMode, | ||
| ~eventIdentifier: Types.eventIdentifier, | ||
| ~allEntities=Entities.allEntities, |
There was a problem hiding this comment.
Added injection params for these functions to make it testable.
| fieldB: option<string>, | ||
| } | ||
|
|
||
| let name = "TestEntity"->(Utils.magic: string => Enums.EntityType.t) |
There was a problem hiding this comment.
In the future I'd actually want to:
- Remove the enum for entity type
- Change entityMod to simply be a record type