@roc-db/test-utils 0.2.0-pre.39 → 0.2.0-pre.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +22 -9
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -514,12 +514,13 @@ var prepareChangeSetTest = async (adapter, adapter2) => {
514
514
  };
515
515
  };
516
516
  var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
517
- let createAdapter = async () => {
517
+ let createAdapter = async ({ optimistic = false } = {}) => {
518
518
  return adapterConstructor({
519
519
  operations,
520
520
  entities,
521
521
  session: { identityRef: "User/42" },
522
522
  snowflake,
523
+ optimistic,
523
524
  ...await generateArgs()
524
525
  });
525
526
  };
@@ -600,10 +601,8 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
600
601
  expect2(() => adapter1.readPost(postRef)).toThrow(NotFoundError2);
601
602
  });
602
603
  test("sync mutation", async () => {
603
- const res = await adapter2.syncOptimisticMutation(createPostMutation);
604
- expect2(res[0]).toStrictEqual(post);
605
- expect2(res[1]).toStrictEqual(createPostMutation);
606
- expect2(() => adapter2.syncOptimisticMutation(createPostMutation)).toThrowError(BadRequestError);
604
+ const [{ persistedAt, ...mutation }] = await adapter2.persistOptimisticMutations([createPostMutation]);
605
+ expect2(mutation).toStrictEqual(createPostMutation);
607
606
  });
608
607
  test("create, patch and delete the same item within the same transaction", async () => {
609
608
  const [post1] = await adapter1.createPost({ title: "Post 1" });
@@ -733,8 +732,8 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
733
732
  });
734
733
  });
735
734
  test("init adapter2", async () => {
736
- const adapterA = await createAdapter();
737
- const adapterB = await createAdapter();
735
+ const adapterA = await createAdapter({ optimistic: true });
736
+ const adapterB = await createAdapter({ optimistic: true });
738
737
  const { draftRef: draftRef2 } = await prepareChangeSetTest(adapterA, adapterB);
739
738
  const mutations = await adapterA.pageMutations({
740
739
  changeSetRef: draftRef2
@@ -743,10 +742,24 @@ var testAdapterImplementation = async (adapterConstructor, generateArgs) => {
743
742
  const allMutationsAdapter2 = await adapterB.pageMutations({});
744
743
  expect2(allMutationsAdapter1).not.toBeEmpty();
745
744
  expect2(allMutationsAdapter2).toBeEmpty();
746
- const res = await adapterB.loadOptimisticMutations(allMutationsAdapter1);
745
+ const res = await adapterB.loadMutations(allMutationsAdapter1);
747
746
  const allMutationsAdapter2after = await adapterB.pageMutations({});
748
747
  expect2(allMutationsAdapter2after.length).toBe(allMutationsAdapter1.length);
749
- const res2 = await adapterB.loadOptimisticMutations(allMutationsAdapter1);
748
+ const res2 = await adapterB.loadMutations(allMutationsAdapter1);
749
+ });
750
+ test("persistOptimisticMutations", async () => {
751
+ const persistedAdapter = await createAdapter({ optimistic: false });
752
+ const optimisticAdapter = await createAdapter({ optimistic: true });
753
+ expect2(persistedAdapter.persistOptimisticMutations).toBeDefined();
754
+ expect2(optimisticAdapter.loadMutations).toBeDefined();
755
+ const [, createPostMutation] = await optimisticAdapter.createPost({
756
+ title: "Foo",
757
+ tags: []
758
+ });
759
+ const [persistCratePostMutation] = await persistedAdapter.persistOptimisticMutations([
760
+ createPostMutation
761
+ ]);
762
+ expect2(persistCratePostMutation.persistedAt >= createPostMutation.timestamp).toBeTrue();
750
763
  });
751
764
  });
752
765
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roc-db/test-utils",
3
- "version": "0.2.0-pre.39",
3
+ "version": "0.2.0-pre.40",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "sideEffects": false,
19
19
  "peerDependencies": {
20
- "roc-db": "0.2.0-pre.39",
20
+ "roc-db": "0.2.0-pre.40",
21
21
  "zod": "3.24.2"
22
22
  },
23
23
  "keywords": [],