Skip to content

Commit

Permalink
Add test of Document with initialRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
raararaara committed Oct 22, 2024
1 parent d36f2f4 commit dc4a048
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions packages/sdk/test/integration/document_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import yorkie, {
Text,
JSONArray,
SyncMode,
PrimitiveValue,

Check failure on line 7 in packages/sdk/test/integration/document_test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'PrimitiveValue' is defined but never used
Tree,
JSONElement,
} from '@yorkie-js-sdk/src/yorkie';
import {
testRPCAddr,
Expand All @@ -22,6 +25,8 @@ import {
import { OperationInfo } from '@yorkie-js-sdk/src/document/operation/operation';
import { YorkieError } from '@yorkie-js-sdk/src/util/error';
import { CounterType } from '@yorkie-js-sdk/src/document/crdt/counter';
import {LeafElement} from "@yorkie-js-sdk/src/document/json/element";

Check failure on line 28 in packages/sdk/test/integration/document_test.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'LeafElement' is defined but never used
import Long from "long";

describe('Document', function () {
afterEach(() => {
Expand Down Expand Up @@ -1174,5 +1179,79 @@ describe('Document', function () {
await c1.deactivate();
await c2.deactivate();
});

describe('With various types', () => {
interface TestCase {
caseName: string;
input: JSONElement;
expectedJSON: string;
}

// TODO(raararaara): Need test cases for Double, Bytes, Date, Object, Array
const testCases: Array<TestCase> = [
// Custom CRDT Types
{
caseName: 'json.Tree',
input: new Tree({
type: 'doc',
children: [
{ type: 'p', children: [{ type: 'text', value: 'ab' }] },
],
}),
expectedJSON: `{"k":{"type":"doc","children":[{"type":"p","children":[{"type":"text","value":"ab"}]}]}}`,
},
{
caseName: 'json.Text',
input: new Text(),
expectedJSON: `{"k":[]}`,
},
{
caseName: 'json.Counter',
input: new Counter(CounterType.IntegerCnt, 1),
expectedJSON: `{"k":1}`,
},
// Primitives
{
caseName: 'null',
input: null,
expectedJSON: `{"k":null}`,
},
{
caseName: 'boolean',
input: true,
expectedJSON: `{"k":true}`,
},
{
caseName: 'number',
input: 1,
expectedJSON: `{"k":1}`,
},
{
caseName: 'Long',
input: Long.MAX_VALUE,
expectedJSON: `{"k":9223372036854775807}`,
},
];

it('Can support various types', async function ({ task }) {
for (const { caseName, input, expectedJSON } of testCases) {
const c1 = new yorkie.Client(testRPCAddr);
await c1.activate();
const docKey = toDocKey(
`${task.name}-${caseName}-${new Date().getTime()}`,
);
const doc = new yorkie.Document(docKey);

await c1.attach(doc, {
initialRoot: {
k: input,
},
});
assert.equal(doc.toSortedJSON(), expectedJSON);

await c1.deactivate();
}
});
});
});
});

0 comments on commit dc4a048

Please sign in to comment.