Skip to content

Commit 65829f9

Browse files
committed
test(reactive-rpc): 💍 use client.* in blocks.* tests
1 parent 33aed5c commit 65829f9

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

src/server/__tests__/blocks.spec.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {tick, until} from '../../__tests__/util';
77
describe('blocks.*', () => {
88
describe('blocks.create', () => {
99
test('can create an empty block', async () => {
10-
const {caller} = setup();
11-
await caller.call('blocks.create', {id: 'my-block', patches: []}, {});
12-
const {block} = (await caller.call('blocks.get', {id: 'my-block'}, {})).data;
10+
const {call} = setup();
11+
await call('blocks.create', {id: 'my-block', patches: []});
12+
const {block} = (await call('blocks.get', {id: 'my-block'}));
1313
expect(block).toMatchObject({
1414
id: 'my-block',
1515
seq: -1,
@@ -283,48 +283,48 @@ describe('blocks.*', () => {
283283

284284
describe('blocks.listen', () => {
285285
test('can listen for block changes', async () => {
286-
const {call, caller} = setup();
287-
await call('blocks.create', {id: 'my-block', patches: []});
286+
const {client} = setup();
287+
await client.call('blocks.create', {id: 'my-block', patches: []});
288288
await tick(11);
289289
const emits: any[] = [];
290-
caller.call$('blocks.listen', of({id: 'my-block'}), {}).subscribe((data) => emits.push(data));
290+
client.call$('blocks.listen', of({id: 'my-block'})).subscribe((data) => emits.push(data));
291291
const model = Model.withLogicalClock();
292292
model.api.root({
293293
text: 'Hell',
294294
});
295295
const patch1 = model.api.flush();
296296
await tick(12);
297297
expect(emits.length).toBe(0);
298-
await call('blocks.edit', {id: 'my-block', patches: [{seq: 0, created: Date.now(), blob: patch1.toBinary()}]});
298+
await client.call('blocks.edit', {id: 'my-block', patches: [{seq: 0, created: Date.now(), blob: patch1.toBinary()}]});
299299
await until(() => emits.length === 1);
300300
expect(emits.length).toBe(1);
301-
expect(emits[0].data.patches.length).toBe(1);
302-
expect(emits[0].data.patches[0].seq).toBe(0);
301+
expect(emits[0].patches.length).toBe(1);
302+
expect(emits[0].patches[0].seq).toBe(0);
303303
model.api.root({
304304
text: 'Hello',
305305
});
306306
const patch2 = model.api.flush();
307307
await tick(12);
308308
expect(emits.length).toBe(1);
309-
await call('blocks.edit', {id: 'my-block', patches: [{seq: 1, created: Date.now(), blob: patch2.toBinary()}]});
309+
await client.call('blocks.edit', {id: 'my-block', patches: [{seq: 1, created: Date.now(), blob: patch2.toBinary()}]});
310310
await until(() => emits.length === 2);
311311
expect(emits.length).toBe(2);
312-
expect(emits[1].data.patches.length).toBe(1);
313-
expect(emits[1].data.patches[0].seq).toBe(1);
312+
expect(emits[1].patches.length).toBe(1);
313+
expect(emits[1].patches[0].seq).toBe(1);
314314
});
315315

316316
test('can subscribe before block is created', async () => {
317-
const {call, caller} = setup();
317+
const {client} = setup();
318318
const emits: any[] = [];
319-
caller.call$('blocks.listen', of({id: 'my-block'}), {}).subscribe((data) => emits.push(data));
319+
client.call$('blocks.listen', of({id: 'my-block'})).subscribe((data) => emits.push(data));
320320
const model = Model.withLogicalClock();
321321
model.api.root({
322322
text: 'Hell',
323323
});
324324
const patch1 = model.api.flush();
325325
await tick(12);
326326
expect(emits.length).toBe(0);
327-
await call('blocks.create', {
327+
await client.call('blocks.create', {
328328
id: 'my-block',
329329
patches: [
330330
{
@@ -336,21 +336,22 @@ describe('blocks.*', () => {
336336
});
337337
await until(() => emits.length === 1);
338338
expect(emits.length).toBe(1);
339-
expect(emits[0].data.patches.length).toBe(1);
340-
expect(emits[0].data.patches[0].seq).toBe(0);
341-
expect(emits[0].data.patches[0].blob).toStrictEqual(patch1.toBinary());
339+
expect(emits[0].patches.length).toBe(1);
340+
expect(emits[0].patches[0].seq).toBe(0);
341+
expect(emits[0].patches[0].blob).toStrictEqual(patch1.toBinary());
342342
});
343343

344344
test('can receive deletion events', async () => {
345-
const {call, caller} = setup();
345+
const {client} = setup();
346346
const emits: any[] = [];
347-
caller.call$('blocks.listen', of({id: 'my-block'}), {}).subscribe((data) => emits.push(data));
348-
await call('blocks.create', {id: 'my-block', patches: []});
347+
client.call$('blocks.listen', of({id: 'my-block'})).subscribe((data) => emits.push(data));
348+
await client.call('blocks.create', {id: 'my-block', patches: []});
349349
await until(() => emits.length === 1);
350-
expect(emits[0].data.block.seq).toBe(-1);
351-
await call('blocks.remove', {id: 'my-block'});
350+
expect(emits[0].block.seq).toBe(-1);
351+
await tick(3);
352+
await client.call('blocks.remove', {id: 'my-block'});
352353
await until(() => emits.length === 2);
353-
expect(emits[1].data.deleted).toBe(true);
354+
expect(emits[1].deleted).toBe(true);
354355
});
355356
});
356357

src/server/__tests__/setup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {Services} from '../services/Services';
55
export const setup = () => {
66
const services = new Services();
77
const {caller} = createCaller(services);
8-
const call = caller.callSimple.bind(caller);
98
const {client} = buildE2eClient(caller, {
109
writerDefaultBufferKb: [1, 32],
1110
clientBufferSize: [1, 3],
@@ -15,5 +14,7 @@ export const setup = () => {
1514
requestLatency: [1, 10],
1615
responseLatency: [1, 10],
1716
});
18-
return {services, caller, call, client};
17+
const call = client.call.bind(client);
18+
const call$ = client.call$.bind(client);
19+
return {services, caller, client, call, call$};
1920
};

0 commit comments

Comments
 (0)