Skip to content

Commit

Permalink
Merge pull request #387 from bijela-gora/main
Browse files Browse the repository at this point in the history
Slightly improved tests for loadRange method
  • Loading branch information
pvh authored Dec 2, 2024
2 parents 1e494c8 + 0dd72b9 commit 5a4c87e
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions packages/automerge-repo/src/helpers/tests/storage-adapter-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,26 @@ export function runStorageAdapterTests(setup: SetupFn, title?: string): void {
await adapter.save(["AAAAA", "snapshot", "yyyyy"], PAYLOAD_B())
await adapter.save(["AAAAA", "sync-state", "zzzzz"], PAYLOAD_C())

expect(await adapter.loadRange(["AAAAA"])).toStrictEqual(
expect.arrayContaining([
{ key: ["AAAAA", "sync-state", "xxxxx"], data: PAYLOAD_A() },
{ key: ["AAAAA", "snapshot", "yyyyy"], data: PAYLOAD_B() },
{ key: ["AAAAA", "sync-state", "zzzzz"], data: PAYLOAD_C() },
])
)

expect(await adapter.loadRange(["AAAAA", "sync-state"])).toStrictEqual(
expect.arrayContaining([
{ key: ["AAAAA", "sync-state", "xxxxx"], data: PAYLOAD_A() },
{ key: ["AAAAA", "sync-state", "zzzzz"], data: PAYLOAD_C() },
])
)
expect(await adapter.loadRange(["AAAAA"])).toStrictEqual([
{ key: ["AAAAA", "sync-state", "xxxxx"], data: PAYLOAD_A() },
{ key: ["AAAAA", "snapshot", "yyyyy"], data: PAYLOAD_B() },
{ key: ["AAAAA", "sync-state", "zzzzz"], data: PAYLOAD_C() },
])

expect(await adapter.loadRange(["AAAAA", "sync-state"])).toStrictEqual([
{ key: ["AAAAA", "sync-state", "xxxxx"], data: PAYLOAD_A() },
{ key: ["AAAAA", "sync-state", "zzzzz"], data: PAYLOAD_C() },
])
})

it("should only load values that match they key", async ({ adapter }) => {
await adapter.save(["AAAAA", "sync-state", "xxxxx"], PAYLOAD_A())
await adapter.save(["BBBBB", "sync-state", "zzzzz"], PAYLOAD_C())

const actual = await adapter.loadRange(["AAAAA"])
expect(actual).toStrictEqual(
expect.arrayContaining([
{ key: ["AAAAA", "sync-state", "xxxxx"], data: PAYLOAD_A() },
])
)
expect(actual).toStrictEqual(
expect.not.arrayContaining([
{ key: ["BBBBB", "sync-state", "zzzzz"], data: PAYLOAD_C() },
])
)
expect(actual).toStrictEqual([
{ key: ["AAAAA", "sync-state", "xxxxx"], data: PAYLOAD_A() },
])
})
})

Expand Down

0 comments on commit 5a4c87e

Please sign in to comment.