@roc-db/test-utils 0.1.0 → 0.2.0-pre.10
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.
- package/dist/index.js +98 -30
- package/dist/types/schemas/BlockParagraphSchema.d.ts +1 -0
- package/dist/types/schemas/BlockRefSchema.d.ts +2 -0
- package/dist/types/schemas/BlockRowSchema.d.ts +33 -0
- package/dist/types/schemas/PostSchema.d.ts +1 -0
- package/package.json +10 -17
- package/dist/roc-db-test-utils-0.1.0.tgz +0 -0
package/dist/index.js
CHANGED
|
@@ -179,7 +179,6 @@ var createBlockRow = writeOperation3(CreateBlockRowMutationSchema, BlockParagrap
|
|
|
179
179
|
const ref = txn.createRef("BlockRow");
|
|
180
180
|
const { parentRef } = txn.payload;
|
|
181
181
|
return QueryChain2(Query3(() => txn.readEntity(parentRef)), Query3((parent) => {
|
|
182
|
-
console.log("asdfasfd", parent);
|
|
183
182
|
return txn.patchEntity(parentRef, {
|
|
184
183
|
children: { blocks: [...parent.children.blocks, ref] }
|
|
185
184
|
});
|
|
@@ -344,7 +343,7 @@ var operations = [
|
|
|
344
343
|
];
|
|
345
344
|
// src/testAdapterImplementation.ts
|
|
346
345
|
import { beforeAll, describe, expect, test } from "bun:test";
|
|
347
|
-
import { NotFoundError as NotFoundError2 } from "roc-db";
|
|
346
|
+
import { BadRequestError, NotFoundError as NotFoundError2 } from "roc-db";
|
|
348
347
|
var prepareChangeSetTest = async (adapter) => {
|
|
349
348
|
const [post] = await adapter.createPost({
|
|
350
349
|
title: "Title 1",
|
|
@@ -378,54 +377,123 @@ var testAdapterImplementation = (adapterConstructor, engineArgsAdapter1 = {}, en
|
|
|
378
377
|
return async () => {
|
|
379
378
|
const adapter1 = adapterConstructor({ operations, entities, ...engineArgsAdapter1 });
|
|
380
379
|
const adapter2 = adapterConstructor({ operations, entities, ...engineArgsAdapter2 });
|
|
380
|
+
describe("Post CRUD", async () => {
|
|
381
|
+
let postRef;
|
|
382
|
+
let post;
|
|
383
|
+
let createPostMutation;
|
|
384
|
+
beforeAll(async () => {
|
|
385
|
+
const createPostRes = await adapter1.createPost({
|
|
386
|
+
title: "Title 1",
|
|
387
|
+
slug: "title-1",
|
|
388
|
+
tags: ["Foo", "Bar"]
|
|
389
|
+
});
|
|
390
|
+
post = createPostRes[0];
|
|
391
|
+
postRef = createPostRes[0].ref;
|
|
392
|
+
createPostMutation = createPostRes[1];
|
|
393
|
+
});
|
|
394
|
+
test("create (createEntity function)", async () => {
|
|
395
|
+
expect(post).toMatchZodSchema(PostSchema);
|
|
396
|
+
expect(post.data.title).toBe("Title 1");
|
|
397
|
+
expect(post.data.tags).toStrictEqual(["Foo", "Bar"]);
|
|
398
|
+
});
|
|
399
|
+
test("read (readEntity function)", async () => {
|
|
400
|
+
const readPostRes = await adapter1.readPost(postRef);
|
|
401
|
+
expect(readPostRes.data.title).toStrictEqual("Title 1");
|
|
402
|
+
expect(readPostRes.data.tags).toStrictEqual(["Foo", "Bar"]);
|
|
403
|
+
expect(readPostRes).toMatchZodSchema(PostSchema);
|
|
404
|
+
});
|
|
405
|
+
test("update (updateEntity function)", async () => {
|
|
406
|
+
const [post2] = await adapter1.updatePost({
|
|
407
|
+
ref: postRef,
|
|
408
|
+
title: "Title 2",
|
|
409
|
+
tags: ["Foo"]
|
|
410
|
+
});
|
|
411
|
+
expect(post2.data.tags).toStrictEqual(["Foo"]);
|
|
412
|
+
expect(post2.data.title).toBe("Title 2");
|
|
413
|
+
expect(post2).toMatchZodSchema(PostSchema);
|
|
414
|
+
});
|
|
415
|
+
test("updateTitle (patchEntity function + debounce)", async () => {
|
|
416
|
+
const updatePostTitleRes1 = await adapter1.updatePostTitle({
|
|
417
|
+
ref: postRef,
|
|
418
|
+
title: "Title 3"
|
|
419
|
+
});
|
|
420
|
+
expect(updatePostTitleRes1[0]).toMatchZodSchema(PostSchema);
|
|
421
|
+
const updatePostTitleRes2 = await adapter1.updatePostTitle({
|
|
422
|
+
ref: postRef,
|
|
423
|
+
title: "Title 4"
|
|
424
|
+
});
|
|
425
|
+
expect(updatePostTitleRes2[0]).toMatchZodSchema(PostSchema);
|
|
426
|
+
expect(updatePostTitleRes2[1].ref).toBe(updatePostTitleRes1[1].ref);
|
|
427
|
+
expect(updatePostTitleRes2[1].timestamp >= updatePostTitleRes1[1].timestamp).toBeTrue();
|
|
428
|
+
});
|
|
429
|
+
test("delete (deleteEntity function)", async () => {
|
|
430
|
+
const [count, mutation] = await adapter1.deletePost(postRef);
|
|
431
|
+
expect(count).toBe(1);
|
|
432
|
+
expect(mutation.log).toStrictEqual([[postRef, "delete", null]]);
|
|
433
|
+
});
|
|
434
|
+
test("sync mutation", async () => {
|
|
435
|
+
const res = await adapter2.syncOptimisticMutation(createPostMutation);
|
|
436
|
+
expect(res[0]).toStrictEqual(post);
|
|
437
|
+
expect(res[1]).toStrictEqual(createPostMutation);
|
|
438
|
+
expect(() => adapter2.syncOptimisticMutation(createPostMutation)).toThrowError(BadRequestError);
|
|
439
|
+
});
|
|
440
|
+
});
|
|
381
441
|
describe("changeSet", async () => {
|
|
382
|
-
let postRef, draftRef, changeSetAdapter,
|
|
442
|
+
let postRef, draftRef, changeSetAdapter, blockParagraph1, post, blockRow, blockParagraph2;
|
|
383
443
|
beforeAll(async () => {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
444
|
+
({
|
|
445
|
+
postRef,
|
|
446
|
+
draftRef,
|
|
447
|
+
changeSetAdapter,
|
|
448
|
+
blockParagraph1,
|
|
449
|
+
post,
|
|
450
|
+
blockRow,
|
|
451
|
+
blockParagraph2
|
|
452
|
+
} = await prepareChangeSetTest(adapter1));
|
|
392
453
|
});
|
|
393
454
|
test("create (createEntity function w/changeSetRef)", async () => {
|
|
394
|
-
expect(
|
|
455
|
+
expect(blockParagraph1).toMatchZodSchema(BlockParagraphSchema);
|
|
395
456
|
expect(post).toMatchZodSchema(PostSchema);
|
|
396
457
|
});
|
|
397
458
|
test("read (readEntity function w/changeSetRef)", async () => {
|
|
398
|
-
const read = await changeSetAdapter.readEntity(
|
|
459
|
+
const read = await changeSetAdapter.readEntity(blockParagraph1.ref);
|
|
399
460
|
expect(read).toMatchZodSchema(BlockParagraphSchema);
|
|
400
461
|
});
|
|
462
|
+
test("update (patchEntity function w/changeSetRef)", async () => {
|
|
463
|
+
const [updatedBlock] = await changeSetAdapter.updateBlockParagraph({
|
|
464
|
+
ref: blockParagraph1.ref,
|
|
465
|
+
content: "Hello, world!"
|
|
466
|
+
});
|
|
467
|
+
expect(updatedBlock).toMatchZodSchema(BlockParagraphSchema);
|
|
468
|
+
});
|
|
401
469
|
test("delete (with cascade delete)", async () => {
|
|
402
470
|
const [count, mutation] = await changeSetAdapter.deletePost(postRef);
|
|
403
471
|
expect(count).toBe(4);
|
|
404
472
|
expect(mutation.log).toStrictEqual([
|
|
405
|
-
[
|
|
473
|
+
[blockParagraph1.ref, "delete", draftRef],
|
|
406
474
|
[blockRow.ref, "delete", draftRef],
|
|
407
475
|
[blockParagraph2.ref, "delete", draftRef],
|
|
408
476
|
[postRef, "delete", draftRef]
|
|
409
477
|
]);
|
|
478
|
+
await expect(() => changeSetAdapter.readEntity(blockParagraph1.ref)).toThrow(NotFoundError2);
|
|
479
|
+
await expect(() => changeSetAdapter.updateBlockParagraph({
|
|
480
|
+
ref: blockParagraph1.ref,
|
|
481
|
+
content: "Foo"
|
|
482
|
+
})).toThrow(NotFoundError2);
|
|
410
483
|
});
|
|
411
|
-
test("
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
content: "Hello, world!"
|
|
484
|
+
test("pageMutations", async () => {
|
|
485
|
+
const res = await changeSetAdapter.pageMutations({
|
|
486
|
+
changeSetRef: draftRef
|
|
415
487
|
});
|
|
416
|
-
expect(
|
|
488
|
+
expect(res.length).toBeGreaterThan(0);
|
|
489
|
+
expect(res.every((m) => m.changeSetRef === draftRef)).toBeTrue();
|
|
417
490
|
});
|
|
418
|
-
test
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
expect(() => changeSetAdapter.readEntity(block.ref)).toThrow(NotFoundError2);
|
|
425
|
-
expect(() => changeSetAdapter.updateBlockParagraph({
|
|
426
|
-
ref: block.ref,
|
|
427
|
-
content: "Foo"
|
|
428
|
-
})).toThrow(NotFoundError2);
|
|
491
|
+
test("pageMutations2", async () => {
|
|
492
|
+
const res = await changeSetAdapter.pageMutations({
|
|
493
|
+
changeSetRef: draftRef
|
|
494
|
+
});
|
|
495
|
+
expect(res.length).toBeGreaterThan(0);
|
|
496
|
+
expect(res.every((m) => m.changeSetRef === draftRef)).toBeTrue();
|
|
429
497
|
});
|
|
430
498
|
});
|
|
431
499
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const BlockRowSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
3
|
+
ref: z.ZodType<never, z.ZodTypeDef, never>;
|
|
4
|
+
entity: z.ZodString;
|
|
5
|
+
created: z.ZodObject<{
|
|
6
|
+
mutationRef: z.ZodType<`Mutation/${string}`, z.ZodTypeDef, `Mutation/${string}`>;
|
|
7
|
+
timestamp: z.ZodString;
|
|
8
|
+
}, "strict", z.ZodTypeAny, {
|
|
9
|
+
mutationRef: `Mutation/${string}`;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
}, {
|
|
12
|
+
mutationRef: `Mutation/${string}`;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
}>;
|
|
15
|
+
updated: z.ZodObject<{
|
|
16
|
+
mutationRef: z.ZodType<`Mutation/${string}`, z.ZodTypeDef, `Mutation/${string}`>;
|
|
17
|
+
timestamp: z.ZodString;
|
|
18
|
+
}, "strict", z.ZodTypeAny, {
|
|
19
|
+
mutationRef: `Mutation/${string}`;
|
|
20
|
+
timestamp: string;
|
|
21
|
+
}, {
|
|
22
|
+
mutationRef: `Mutation/${string}`;
|
|
23
|
+
timestamp: string;
|
|
24
|
+
}>;
|
|
25
|
+
data: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
26
|
+
parents: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
27
|
+
ancestors: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
28
|
+
}, z.ZodRawShape>, "strict", z.ZodTypeAny, {
|
|
29
|
+
[x: string]: any;
|
|
30
|
+
}, {
|
|
31
|
+
[x: string]: any;
|
|
32
|
+
}>;
|
|
33
|
+
export type BlockRow = z.infer<typeof BlockRowSchema>;
|
package/package.json
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roc-db/test-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-pre.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
".":
|
|
7
|
-
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts"
|
|
9
|
+
},
|
|
10
|
+
"./setup": {
|
|
11
|
+
"import": "./dist/setup/index.js",
|
|
12
|
+
"types": "./dist/types/setup/index.d.ts"
|
|
13
|
+
}
|
|
8
14
|
},
|
|
9
15
|
"files": [
|
|
10
16
|
"dist"
|
|
11
17
|
],
|
|
12
18
|
"sideEffects": false,
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "NODE_ENV=production bun run scripts/build.ts",
|
|
15
|
-
"build:types": "rm -rf dist/types && bun run tsc --noCheck",
|
|
16
|
-
"test": "echo"
|
|
17
|
-
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@faker-js/faker": "9.6.0",
|
|
20
|
-
"@types/bun": "1.2.5",
|
|
21
|
-
"@types/sanitize-html": "2.13.0",
|
|
22
|
-
"bun": "1.2.5",
|
|
23
|
-
"expect-type": "1.2.0",
|
|
24
|
-
"roc-db": "0.1.0"
|
|
25
|
-
},
|
|
26
19
|
"peerDependencies": {
|
|
27
|
-
"roc-db": "0.
|
|
20
|
+
"roc-db": "0.2.0-pre.10",
|
|
28
21
|
"zod": "3.24.2"
|
|
29
22
|
},
|
|
30
23
|
"keywords": [],
|
|
Binary file
|