-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added randomness and started discover
- Loading branch information
1 parent
ef97e6a
commit 1d2756e
Showing
6 changed files
with
102 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { it, expect, describe } from "vitest"; | ||
import { type GraffitiFactory, type GraffitiSessionBase } from "../src/index"; | ||
import { randomString, randomValue, randomPutObject } from "./utils"; | ||
|
||
export const graffitiDiscoverTests = ( | ||
useGraffiti: GraffitiFactory, | ||
useSession1: () => GraffitiSessionBase, | ||
useSession2: () => GraffitiSessionBase, | ||
) => { | ||
describe("discover", () => { | ||
it("discover single", async () => { | ||
const graffiti = useGraffiti(); | ||
const session = useSession1(); | ||
const object = randomPutObject(); | ||
|
||
const putted = await graffiti.put(object, session); | ||
|
||
const queryChannels = [randomString(), object.channels[0]]; | ||
const iterator = graffiti.discover(queryChannels, {}); | ||
const result = (await iterator.next()).value; | ||
if (!result || result.error) throw new Error(); | ||
expect(result.value.value).toEqual(object.value); | ||
expect(result.value.channels).toEqual([object.channels[0]]); | ||
expect(result.value.allowed).toBeUndefined(); | ||
expect(result.value.actor).toEqual(session.actor); | ||
expect(result.value.tombstone).toBe(false); | ||
expect(result.value.lastModified).toEqual(putted.lastModified); | ||
const result2 = await iterator.next(); | ||
expect(result2.done).toBe(true); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./location"; | ||
export * from "./crud"; | ||
export * from "./synchronize"; | ||
export * from "./discover"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { GraffitiPutObject } from "../src"; | ||
|
||
export function randomString(): string { | ||
const array = new Uint8Array(16); | ||
crypto.getRandomValues(array); | ||
return Array.from(array) | ||
.map((b) => b.toString(16).padStart(2, "0")) | ||
.join(""); | ||
} | ||
|
||
export function randomValue() { | ||
return { | ||
[randomString()]: randomString(), | ||
}; | ||
} | ||
|
||
export function randomPutObject(): GraffitiPutObject<{}> { | ||
return { | ||
value: randomValue(), | ||
channels: [randomString(), randomString()], | ||
}; | ||
} |