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

Slightly improved tests for loadRange method #387

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading