-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(key-value): add domains to key value
- Loading branch information
1 parent
59550b7
commit ca7e0a8
Showing
6 changed files
with
64 additions
and
32 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
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,26 +1,45 @@ | ||
import { keyValueStoreApiService } from "."; | ||
import { createKeyValueDomainPersistenceService } from "."; | ||
import { KeyValueDomain } from "./types"; | ||
|
||
const keyValueStoreApiService = createKeyValueDomainPersistenceService< | ||
Record<string, unknown> | ||
>("test-me" as KeyValueDomain); | ||
|
||
const unTouchedkeyValueStoreApiService = createKeyValueDomainPersistenceService< | ||
Record<string, unknown> | ||
>("un-touched" as KeyValueDomain); | ||
|
||
describe("KeyValueStoreApiService", () => { | ||
it("should return empty for none saved items", async () => { | ||
expect(await keyValueStoreApiService.getItem("non-existent")).toBeNull(); | ||
}); | ||
it("should upsert data", async () => { | ||
await keyValueStoreApiService.persistItem({ bar: "bar" }); | ||
await unTouchedkeyValueStoreApiService.persistItem({ bar: "bar" }); | ||
expect(await keyValueStoreApiService.getItem()).toEqual({ | ||
bar: "bar", | ||
}); | ||
|
||
it("should persist items", async () => { | ||
await keyValueStoreApiService.persistItem("persist", { bar: "baz" }); | ||
expect(await keyValueStoreApiService.getItem("persist")).toEqual({ | ||
bar: "baz", | ||
expect(await unTouchedkeyValueStoreApiService.getItem()).toEqual({ | ||
bar: "bar", | ||
}); | ||
|
||
await keyValueStoreApiService.persistItem({ foo: "foo" }); | ||
expect(await keyValueStoreApiService.getItem()).toEqual({ | ||
foo: "foo", | ||
}); | ||
|
||
expect(await unTouchedkeyValueStoreApiService.getItem()).toEqual({ | ||
bar: "bar", | ||
}); | ||
}); | ||
|
||
it("should clear items", async () => { | ||
await keyValueStoreApiService.persistItem("clear1", { bar1: "baz1" }); | ||
await keyValueStoreApiService.persistItem("clear2", { bar2: "baz2" }); | ||
await keyValueStoreApiService.persistItem({ bar2: "baz2" }); | ||
|
||
await keyValueStoreApiService.clearItem(); | ||
|
||
await keyValueStoreApiService.clearItem("clear1"); | ||
expect(await keyValueStoreApiService.getItem()).toBeNull(); | ||
|
||
expect(await keyValueStoreApiService.getItem("clear1")).toBeNull(); | ||
expect(await keyValueStoreApiService.getItem("clear2")).toEqual({ | ||
bar2: "baz2", | ||
expect(await unTouchedkeyValueStoreApiService.getItem()).toEqual({ | ||
bar: "bar", | ||
}); | ||
}); | ||
}); |
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 @@ | ||
export { type PortalKeyValueDomain } from "./main"; |
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 @@ | ||
export type PortalKeyValueDomain = ""; |
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,3 @@ | ||
import { PortalKeyValueDomain } from "./portal"; | ||
|
||
export type KeyValueDomain = PortalKeyValueDomain; |