Skip to content

Commit cac6e0c

Browse files
committed
test: 💍 make unit tests pass after refactor
1 parent dce7bbb commit cac6e0c

File tree

9 files changed

+82
-19
lines changed

9 files changed

+82
-19
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {setup} from './setup';
22
import {runBlockTests} from '../../../__tests__/json-crdt-server/block';
3+
import type {ApiTestSetup} from '../../../common/rpc/__tests__/runApiTests';
34

4-
runBlockTests(setup);
5+
runBlockTests(setup as ApiTestSetup);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {runPresenceTests} from '../../../__tests__/json-crdt-server/presence';
22
import {setup} from './setup';
3+
import type {ApiTestSetup} from '../../../common/rpc/__tests__/runApiTests';
34

4-
runPresenceTests(setup);
5+
runPresenceTests(setup as ApiTestSetup);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {runPubsubTests} from '../../../__tests__/json-crdt-server/pubsub';
22
import {setup} from './setup';
3+
import type {ApiTestSetup} from '../../../common/rpc/__tests__/runApiTests';
34

4-
runPubsubTests(setup);
5+
runPubsubTests(setup as ApiTestSetup);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {runUtilTests} from '../../../__tests__/json-crdt-server/util';
22
import {setup} from './setup';
3+
import type {ApiTestSetup} from '../../../common/rpc/__tests__/runApiTests';
34

4-
runUtilTests(setup);
5+
runUtilTests(setup as ApiTestSetup);

src/common/rpc/__tests__/RpcDuplex.spec.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,30 @@ const setup = () => {
5555
return {server, client};
5656
};
5757

58-
const setup1: ApiTestSetup = () => ({client: setup().client});
59-
const setup2: ApiTestSetup = () => ({client: setup().server});
58+
const setup1: ApiTestSetup = () => {
59+
const client = setup().client;
60+
const call = client.call.bind(client);
61+
const call$ = client.call$.bind(client);
62+
const stop = client.stop.bind(client);
63+
return {
64+
call,
65+
call$,
66+
stop,
67+
client: {call, call$, stop},
68+
};
69+
};
70+
const setup2: ApiTestSetup = () => {
71+
const client = setup().server;
72+
const call = client.call.bind(client);
73+
const call$ = client.call$.bind(client);
74+
const stop = client.stop.bind(client);
75+
return {
76+
call,
77+
call$,
78+
stop,
79+
client: {call, call$, stop},
80+
};
81+
};
6082

6183
describe('duplex 1', () => {
6284
runApiTests(setup1);

src/common/rpc/__tests__/RpcMessageStreamProcessorLocalClient-api.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,15 @@ const setup = () => {
2424
};
2525
};
2626

27-
runApiTests(() => ({client: setup().client}));
27+
runApiTests(() => {
28+
const client = setup().client;
29+
const call = client.call.bind(client);
30+
const call$ = client.call$.bind(client);
31+
const stop = client.stop.bind(client);
32+
return {
33+
call,
34+
call$,
35+
stop,
36+
client: {call, call$, stop},
37+
};
38+
});

src/common/rpc/__tests__/api.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,15 @@ const setup = () => {
3030
return {server, client};
3131
};
3232

33-
runApiTests(setup);
33+
runApiTests(() => {
34+
const client = setup().client;
35+
const call = client.call.bind(client);
36+
const call$ = client.call$.bind(client);
37+
const stop = client.stop.bind(client);
38+
return {
39+
call,
40+
call$,
41+
stop,
42+
client: {call, call$, stop},
43+
};
44+
});

src/common/rpc/caller/__tests__/RpcApiCaller.spec.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,21 @@ describe('streaming calls', () => {
105105
describe('smoke tests', () => {
106106
runApiTests(() => {
107107
const {caller} = setup();
108+
const call$ = (name: any, request: any) =>
109+
caller.call$(name, Rx.isObservable(request) ? request : Rx.of(request), {}).pipe(
110+
Rx.map((value) => value.data),
111+
catchError((error) => {
112+
throw error.data;
113+
}),
114+
);
115+
const client = {
116+
call$,
117+
call: (name: any, request: any) => Rx.firstValueFrom(call$(name, request)),
118+
stop: () => {},
119+
};
108120
return {
109-
client: {
110-
call$: (name: any, request: any) =>
111-
caller.call$(name, Rx.isObservable(request) ? request : Rx.of(request), {}).pipe(
112-
Rx.map((value) => value.data),
113-
catchError((error) => {
114-
throw error.data;
115-
}),
116-
),
117-
stop: () => {},
118-
},
121+
...client,
122+
client,
119123
};
120124
});
121125
});

src/common/rpc/client/__tests__/StaticRpcClient.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@ const setup = () => {
1919
return {server, client};
2020
};
2121

22-
runApiTests(setup);
22+
runApiTests(() => {
23+
const client = setup().client;
24+
const call = client.call.bind(client);
25+
const call$ = client.call$.bind(client);
26+
const stop = client.stop.bind(client);
27+
return {
28+
call,
29+
call$,
30+
stop,
31+
client: {call, call$, stop},
32+
};
33+
});

0 commit comments

Comments
 (0)