@fireproof/core-test 0.23.1 → 0.23.2
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/blockstore/interceptor-gateway.test.js.map +1 -1
- package/blockstore/keyed-crypto-indexeddb-file.test.js.map +1 -1
- package/blockstore/keyed-crypto.test.js.map +1 -1
- package/blockstore/loader.test.js.map +1 -1
- package/blockstore/standalone.test.js.map +1 -1
- package/blockstore/store.test.js.map +1 -1
- package/blockstore/transaction.test.js.map +1 -1
- package/fireproof/all-gateway.test.js.map +1 -1
- package/fireproof/attachable.test.js.map +1 -1
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js.map +1 -1
- package/fireproof/charwise-boolean.test.js.map +1 -1
- package/fireproof/compact-strategy.test.js.map +1 -1
- package/fireproof/concurrent.test.js.map +1 -1
- package/fireproof/crdt.test.js.map +1 -1
- package/fireproof/database.test.js.map +1 -1
- package/fireproof/deleted-docs-handling.test.js.map +1 -1
- package/fireproof/fireproof.test.fixture.js.map +1 -1
- package/fireproof/fireproof.test.js.map +1 -1
- package/fireproof/hello.test.js.map +1 -1
- package/fireproof/indexer.test.js.map +1 -1
- package/fireproof/multiple-ledger.test.js.map +1 -1
- package/fireproof/query-docs.test.js.map +1 -1
- package/fireproof/query-limit-issue.test.js.map +1 -1
- package/fireproof/query-property-inconsistency.test.js.map +1 -1
- package/fireproof/query-result-properties.test.js.map +1 -1
- package/fireproof/stable-cid.test.js.map +1 -1
- package/fireproof/utils.test.js.map +1 -1
- package/gateway/file/loader-config.test.js.map +1 -1
- package/gateway/indexeddb/create-db-on-write.test.js.map +1 -1
- package/gateway/indexeddb/loader-config.test.js.map +1 -1
- package/global-setup.js.map +1 -1
- package/helpers.js.map +1 -1
- package/package.json +18 -18
- package/protocols/cloud/msger.test.js.map +1 -1
- package/runtime/fp-envelope-serialize.test.js.map +1 -1
- package/runtime/key-bag.test.js.map +1 -1
- package/runtime/meta-key-hack.test.js.map +1 -1
- package/setup.file.js.map +1 -1
- package/setup.indexeddb.js.map +1 -1
- package/setup.memory.js.map +1 -1
- package/vitest.config.js.map +1 -1
- package/vitest.file.config.js.map +1 -1
- package/vitest.indexeddb.config.js.map +1 -1
- package/vitest.memory.config.js.map +1 -1
- package/blockstore/fp-envelope.test.ts-off +0 -65
- package/blockstore/fragment-gateway.test.ts-off +0 -106
- package/blockstore/interceptor-gateway.test.ts +0 -259
- package/blockstore/keyed-crypto-indexeddb-file.test.ts +0 -134
- package/blockstore/keyed-crypto.test.ts +0 -381
- package/blockstore/loader.test.ts +0 -313
- package/blockstore/standalone.test.ts +0 -156
- package/blockstore/store.test.ts +0 -199
- package/blockstore/transaction.test.ts +0 -132
- package/fireproof/all-gateway.test.ts +0 -477
- package/fireproof/attachable.test.ts +0 -677
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
- package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +0 -324
- package/fireproof/charwise-boolean.test.ts +0 -68
- package/fireproof/compact-strategy.test.ts +0 -40
- package/fireproof/concurrent.test.ts +0 -37
- package/fireproof/crdt.test.ts +0 -572
- package/fireproof/database.test.ts +0 -772
- package/fireproof/deleted-docs-handling.test.ts +0 -112
- package/fireproof/fireproof.test.fixture.ts +0 -133
- package/fireproof/fireproof.test.ts +0 -767
- package/fireproof/hello.test.ts +0 -75
- package/fireproof/indexer.test.ts +0 -459
- package/fireproof/multiple-ledger.test.ts +0 -67
- package/fireproof/query-docs.test.ts +0 -117
- package/fireproof/query-limit-issue.test.ts +0 -147
- package/fireproof/query-property-inconsistency.test.ts +0 -90
- package/fireproof/query-result-properties.test.ts +0 -43
- package/fireproof/stable-cid.test.ts +0 -72
- package/fireproof/utils.test.ts +0 -137
- package/gateway/file/loader-config.test.ts +0 -309
- package/gateway/indexeddb/create-db-on-write.test.ts +0 -202
- package/gateway/indexeddb/loader-config.test.ts +0 -80
- package/global-setup.ts +0 -11
- package/helpers.ts +0 -177
- package/protocols/cloud/msger.test.ts +0 -559
- package/runtime/fp-envelope-serialize.test.ts +0 -266
- package/runtime/key-bag.test.ts +0 -243
- package/runtime/meta-key-hack.test.ts +0 -103
- package/setup.file.ts +0 -1
- package/setup.indexeddb.ts +0 -0
- package/setup.memory.ts +0 -2
- package/tsconfig.json +0 -18
- package/vitest.config.ts +0 -8
- package/vitest.file.config.ts +0 -11
- package/vitest.indexeddb.config.ts +0 -34
- package/vitest.memory.config.ts +0 -24
|
@@ -1,559 +0,0 @@
|
|
|
1
|
-
import { Result, URI } from "@adviser/cement";
|
|
2
|
-
import {
|
|
3
|
-
ExchangedGestalt,
|
|
4
|
-
ActiveStream,
|
|
5
|
-
OnMsgFn,
|
|
6
|
-
defaultMsgParams,
|
|
7
|
-
VirtualConnected,
|
|
8
|
-
Msger,
|
|
9
|
-
MsgerParamsWithEnDe,
|
|
10
|
-
} from "@fireproof/core-protocols-cloud";
|
|
11
|
-
import { ensureSuperThis } from "@fireproof/core-runtime";
|
|
12
|
-
import { SuperThis, UnReg } from "@fireproof/core-types-base";
|
|
13
|
-
import {
|
|
14
|
-
MsgRawConnection,
|
|
15
|
-
MsgBase,
|
|
16
|
-
RequestOpts,
|
|
17
|
-
MsgWithError,
|
|
18
|
-
defaultGestalt,
|
|
19
|
-
MsgIsReqGestalt,
|
|
20
|
-
buildResGestalt,
|
|
21
|
-
NotReadyErrorMsg,
|
|
22
|
-
MsgIsReqOpen,
|
|
23
|
-
buildResOpen,
|
|
24
|
-
MsgIsReqChat,
|
|
25
|
-
buildResChat,
|
|
26
|
-
MsgIsError,
|
|
27
|
-
} from "@fireproof/core-types-protocols-cloud";
|
|
28
|
-
import { vi, it, expect, describe, beforeEach, afterEach, assert } from "vitest";
|
|
29
|
-
const sthis = ensureSuperThis();
|
|
30
|
-
|
|
31
|
-
class TestConnection implements MsgRawConnection {
|
|
32
|
-
readonly sthis: SuperThis;
|
|
33
|
-
readonly exchangedGestalt: ExchangedGestalt;
|
|
34
|
-
readonly activeBinds: Map<string, ActiveStream>;
|
|
35
|
-
readonly id: string;
|
|
36
|
-
|
|
37
|
-
isReady = true;
|
|
38
|
-
|
|
39
|
-
constructor(sthis: SuperThis, exGestalt: ExchangedGestalt) {
|
|
40
|
-
this.sthis = sthis;
|
|
41
|
-
this.exchangedGestalt = exGestalt;
|
|
42
|
-
this.activeBinds = new Map();
|
|
43
|
-
this.id = this.sthis.nextId().str;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
readonly bindFn = vi.fn();
|
|
47
|
-
bind<S extends MsgBase, Q extends MsgBase>(req: Q, opts: RequestOpts): ReadableStream<MsgWithError<S>> {
|
|
48
|
-
this.bindFn(req, opts);
|
|
49
|
-
return new ReadableStream<MsgWithError<S>>({
|
|
50
|
-
start: (ctl) => {
|
|
51
|
-
ctl.enqueue({
|
|
52
|
-
tid: req.tid,
|
|
53
|
-
type: req.type,
|
|
54
|
-
version: req.version,
|
|
55
|
-
auth: {
|
|
56
|
-
type: "error",
|
|
57
|
-
},
|
|
58
|
-
} as S);
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
readonly requestFn = vi.fn();
|
|
63
|
-
request<S extends MsgBase, Q extends MsgBase>(req: Q, opts: RequestOpts): Promise<MsgWithError<S>> {
|
|
64
|
-
this.requestFn(req, opts);
|
|
65
|
-
// console.log("request", req);
|
|
66
|
-
return Promise.resolve({
|
|
67
|
-
tid: req.tid,
|
|
68
|
-
type: req.type,
|
|
69
|
-
version: req.version,
|
|
70
|
-
auth: {
|
|
71
|
-
type: "error",
|
|
72
|
-
},
|
|
73
|
-
} as S);
|
|
74
|
-
}
|
|
75
|
-
readonly sendFn = vi.fn();
|
|
76
|
-
send<S extends MsgBase, Q extends MsgBase>(msg: Q): Promise<MsgWithError<S>> {
|
|
77
|
-
this.sendFn(msg);
|
|
78
|
-
// console.log("send", msg);
|
|
79
|
-
return Promise.resolve({
|
|
80
|
-
tid: msg.tid,
|
|
81
|
-
type: msg.type,
|
|
82
|
-
version: msg.version,
|
|
83
|
-
auth: {
|
|
84
|
-
type: "error",
|
|
85
|
-
},
|
|
86
|
-
} as S);
|
|
87
|
-
}
|
|
88
|
-
readonly startFn = vi.fn();
|
|
89
|
-
start(): Promise<Result<void>> {
|
|
90
|
-
this.startFn();
|
|
91
|
-
// console.log("start", this.id); //, this.startFn.mock.calls);
|
|
92
|
-
return Promise.resolve(Result.Ok(undefined));
|
|
93
|
-
}
|
|
94
|
-
readonly closeFn = vi.fn();
|
|
95
|
-
close(o: MsgBase): Promise<Result<void>> {
|
|
96
|
-
this.closeFn(o);
|
|
97
|
-
// console.log("close", this.id); //, o, this.closeFn.mock.calls);
|
|
98
|
-
return Promise.resolve(Result.Ok(undefined));
|
|
99
|
-
}
|
|
100
|
-
readonly onMsgFn = vi.fn();
|
|
101
|
-
onMsg(msg: OnMsgFn<MsgBase>): UnReg {
|
|
102
|
-
this.onMsgFn(msg);
|
|
103
|
-
return () => {
|
|
104
|
-
/* no-op */
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
it("queued-raw-connection", async () => {
|
|
110
|
-
const msgP = defaultMsgParams(sthis, { hasPersistent: true });
|
|
111
|
-
const my = defaultGestalt(msgP, { id: "FP-Universal-Client" });
|
|
112
|
-
const realConn = new MockWSConnection(sthis, {
|
|
113
|
-
my,
|
|
114
|
-
remote: defaultGestalt(msgP, { id: "FP-Universal-Server" }),
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const vconn = new VirtualConnected(sthis, {
|
|
118
|
-
curl: "http://localhost:8080",
|
|
119
|
-
msgerParams: msgP,
|
|
120
|
-
openWSorHttp: {
|
|
121
|
-
openHttp: async function (): Promise<Result<MsgRawConnection>> {
|
|
122
|
-
return Result.Ok(
|
|
123
|
-
new MockHttpConnection(sthis, {
|
|
124
|
-
my,
|
|
125
|
-
remote: defaultGestalt(msgP, { id: "FP-Universal-Server" }),
|
|
126
|
-
}),
|
|
127
|
-
);
|
|
128
|
-
},
|
|
129
|
-
openWS: async function (): Promise<Result<MsgRawConnection>> {
|
|
130
|
-
return Result.Ok(realConn);
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
await vconn.send({
|
|
136
|
-
tid: "1234",
|
|
137
|
-
type: "test",
|
|
138
|
-
version: "1.0",
|
|
139
|
-
auth: {
|
|
140
|
-
type: "error",
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
await vconn.request(
|
|
145
|
-
{
|
|
146
|
-
tid: "1234",
|
|
147
|
-
type: "test",
|
|
148
|
-
version: "1.0",
|
|
149
|
-
auth: {
|
|
150
|
-
type: "error",
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
waitFor: (msg) => {
|
|
155
|
-
return msg.type === "test" && msg.tid === "1234";
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
await vconn.close({
|
|
161
|
-
tid: "1234",
|
|
162
|
-
type: "test",
|
|
163
|
-
version: "1.0",
|
|
164
|
-
auth: {
|
|
165
|
-
type: "error",
|
|
166
|
-
},
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// await sleep(100);
|
|
170
|
-
|
|
171
|
-
expect(realConn.startFn).toHaveBeenCalledTimes(1);
|
|
172
|
-
expect(realConn.sendFn).toHaveBeenCalledTimes(1);
|
|
173
|
-
expect(realConn.closeFn).toHaveBeenCalledTimes(1);
|
|
174
|
-
expect(realConn.requestFn).toHaveBeenCalledTimes(2); // open + test
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
class MockHttpConnection extends TestConnection implements MsgRawConnection {
|
|
178
|
-
sthis: SuperThis;
|
|
179
|
-
exchangedGestalt: ExchangedGestalt;
|
|
180
|
-
activeBinds: Map<string, ActiveStream>;
|
|
181
|
-
|
|
182
|
-
readonly isReady = true;
|
|
183
|
-
|
|
184
|
-
constructor(sthis: SuperThis, exGestalt: ExchangedGestalt) {
|
|
185
|
-
super(sthis, exGestalt);
|
|
186
|
-
this.sthis = sthis;
|
|
187
|
-
this.exchangedGestalt = exGestalt;
|
|
188
|
-
this.activeBinds = new Map();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
bind<S extends MsgBase, Q extends MsgBase>(req: Q, opts: RequestOpts): ReadableStream<MsgWithError<S>> {
|
|
192
|
-
super.bind(req, opts);
|
|
193
|
-
// console.log("http-bind", req, opts);
|
|
194
|
-
return new ReadableStream<MsgWithError<S>>({
|
|
195
|
-
start: (ctl) => {
|
|
196
|
-
ctl.enqueue({
|
|
197
|
-
tid: req.tid,
|
|
198
|
-
type: req.type,
|
|
199
|
-
version: req.version,
|
|
200
|
-
auth: {
|
|
201
|
-
type: "error",
|
|
202
|
-
},
|
|
203
|
-
} as S);
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
request<S extends MsgBase, Q extends MsgBase>(req: Q, opts: RequestOpts): Promise<MsgWithError<S>> {
|
|
208
|
-
super.request(req, opts);
|
|
209
|
-
switch (true) {
|
|
210
|
-
case MsgIsReqGestalt(req):
|
|
211
|
-
// console.log("http-request-gestalt", req, opts);
|
|
212
|
-
return Promise.resolve(buildResGestalt(req, this.exchangedGestalt.remote, req.auth) as unknown as S);
|
|
213
|
-
}
|
|
214
|
-
// console.log("http-request", req, opts);
|
|
215
|
-
return Promise.resolve({
|
|
216
|
-
tid: req.tid,
|
|
217
|
-
type: req.type,
|
|
218
|
-
version: req.version,
|
|
219
|
-
auth: {
|
|
220
|
-
type: "error",
|
|
221
|
-
},
|
|
222
|
-
} as S);
|
|
223
|
-
}
|
|
224
|
-
send<S extends MsgBase, Q extends MsgBase>(msg: Q): Promise<MsgWithError<S>> {
|
|
225
|
-
super.send(msg);
|
|
226
|
-
// console.log("http-send", msg);
|
|
227
|
-
return Promise.resolve({
|
|
228
|
-
tid: msg.tid,
|
|
229
|
-
type: msg.type,
|
|
230
|
-
version: msg.version,
|
|
231
|
-
auth: {
|
|
232
|
-
type: "error",
|
|
233
|
-
},
|
|
234
|
-
} as S);
|
|
235
|
-
}
|
|
236
|
-
start(): Promise<Result<void>> {
|
|
237
|
-
super.start();
|
|
238
|
-
// console.log("http-start");
|
|
239
|
-
return Promise.resolve(Result.Ok(undefined));
|
|
240
|
-
}
|
|
241
|
-
close(o: MsgBase): Promise<Result<void>> {
|
|
242
|
-
// console.log("http-close");
|
|
243
|
-
super.close(o);
|
|
244
|
-
return Promise.resolve(Result.Ok(undefined));
|
|
245
|
-
}
|
|
246
|
-
onMsg(msg: OnMsgFn<MsgBase>): UnReg {
|
|
247
|
-
super.onMsg(msg);
|
|
248
|
-
// console.log("http-onMsg", msg);
|
|
249
|
-
return () => {
|
|
250
|
-
/* no-op */
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
class MockWSConnection extends TestConnection implements MsgRawConnection {
|
|
256
|
-
sthis: SuperThis;
|
|
257
|
-
exchangedGestalt: ExchangedGestalt;
|
|
258
|
-
activeBinds: Map<string, ActiveStream>;
|
|
259
|
-
|
|
260
|
-
isReady = false;
|
|
261
|
-
|
|
262
|
-
constructor(sthis: SuperThis, exGestalt: ExchangedGestalt) {
|
|
263
|
-
super(sthis, exGestalt);
|
|
264
|
-
this.sthis = sthis;
|
|
265
|
-
this.exchangedGestalt = exGestalt;
|
|
266
|
-
this.activeBinds = new Map();
|
|
267
|
-
}
|
|
268
|
-
bind<S extends MsgBase, Q extends MsgBase>(req: Q, opts: RequestOpts): ReadableStream<MsgWithError<S>> {
|
|
269
|
-
super.bind(req, opts);
|
|
270
|
-
// console.log("ws-bind", req, opts);
|
|
271
|
-
const id = this.sthis.nextId().str;
|
|
272
|
-
return new ReadableStream<MsgWithError<S>>({
|
|
273
|
-
cancel: () => {
|
|
274
|
-
// console.log("ws-bind-close");
|
|
275
|
-
this.activeBinds.delete(id);
|
|
276
|
-
},
|
|
277
|
-
start: (controller) => {
|
|
278
|
-
this.activeBinds.set(id, {
|
|
279
|
-
id,
|
|
280
|
-
bind: {
|
|
281
|
-
msg: req,
|
|
282
|
-
opts,
|
|
283
|
-
},
|
|
284
|
-
controller,
|
|
285
|
-
});
|
|
286
|
-
this.send(req).catch((e) => {
|
|
287
|
-
// eslint-disable-next-line no-console
|
|
288
|
-
console.error("send-error", e);
|
|
289
|
-
});
|
|
290
|
-
},
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
request<S extends MsgBase, Q extends MsgBase>(req: Q, opts: RequestOpts): Promise<MsgWithError<S>> {
|
|
294
|
-
super.request(req, opts);
|
|
295
|
-
if (!this.isReady) {
|
|
296
|
-
return Promise.resolve({
|
|
297
|
-
tid: req.tid,
|
|
298
|
-
type: "error",
|
|
299
|
-
version: req.version,
|
|
300
|
-
reason: "not-ready",
|
|
301
|
-
src: "not-ready",
|
|
302
|
-
message: "Not Ready",
|
|
303
|
-
auth: {
|
|
304
|
-
type: "error",
|
|
305
|
-
},
|
|
306
|
-
} satisfies NotReadyErrorMsg);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
switch (true) {
|
|
310
|
-
case MsgIsReqOpen(req):
|
|
311
|
-
// console.log("ws-request-open", req);
|
|
312
|
-
return Promise.resolve(buildResOpen(this.sthis, req) as unknown as S);
|
|
313
|
-
}
|
|
314
|
-
// console.log("ws-request", req, opts);
|
|
315
|
-
return Promise.resolve({
|
|
316
|
-
tid: req.tid,
|
|
317
|
-
type: req.type,
|
|
318
|
-
version: req.version,
|
|
319
|
-
auth: {
|
|
320
|
-
type: "error",
|
|
321
|
-
},
|
|
322
|
-
} as S);
|
|
323
|
-
}
|
|
324
|
-
send<S extends MsgBase, Q extends MsgBase>(msg: Q): Promise<MsgWithError<S>> {
|
|
325
|
-
super.send(msg);
|
|
326
|
-
// console.log("ws-send", msg);
|
|
327
|
-
if (MsgIsReqChat(msg)) {
|
|
328
|
-
const res = buildResChat(msg, msg.conn, `got[${msg.message}]`);
|
|
329
|
-
|
|
330
|
-
for (const [_, bind] of this.activeBinds.entries()) {
|
|
331
|
-
// console.log("ws-to-bind", res);
|
|
332
|
-
bind.controller?.enqueue(res);
|
|
333
|
-
}
|
|
334
|
-
return Promise.resolve(msg as unknown as S);
|
|
335
|
-
}
|
|
336
|
-
return Promise.resolve({
|
|
337
|
-
tid: msg.tid,
|
|
338
|
-
type: msg.type,
|
|
339
|
-
version: msg.version,
|
|
340
|
-
auth: {
|
|
341
|
-
type: "error",
|
|
342
|
-
},
|
|
343
|
-
} as S);
|
|
344
|
-
}
|
|
345
|
-
start(): Promise<Result<void>> {
|
|
346
|
-
super.start();
|
|
347
|
-
this.isReady = true;
|
|
348
|
-
return Promise.resolve(Result.Ok(undefined));
|
|
349
|
-
}
|
|
350
|
-
close(o: MsgBase): Promise<Result<void>> {
|
|
351
|
-
super.close(o);
|
|
352
|
-
|
|
353
|
-
for (const [_, bind] of this.activeBinds.entries()) {
|
|
354
|
-
try {
|
|
355
|
-
bind.controller?.close();
|
|
356
|
-
} catch (e) {
|
|
357
|
-
this.sthis.logger.Error().Err(e).Msg("Error closing bind controller");
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (!this.isReady) {
|
|
361
|
-
return Promise.resolve(Result.Err("Not ready"));
|
|
362
|
-
}
|
|
363
|
-
return Promise.resolve(Result.Ok(undefined));
|
|
364
|
-
}
|
|
365
|
-
onMsg(msg: OnMsgFn<MsgBase>): UnReg {
|
|
366
|
-
super.onMsg(msg);
|
|
367
|
-
throw new Error("Method not implemented.");
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
describe("retry-connection", () => {
|
|
372
|
-
let wsMock: MockWSConnection;
|
|
373
|
-
let connected: VirtualConnected;
|
|
374
|
-
beforeEach(async () => {
|
|
375
|
-
const rMsc = await Msger.connect(sthis, "http://localhost:8080", {
|
|
376
|
-
mowh: {
|
|
377
|
-
openHttp: async function (
|
|
378
|
-
sthis: SuperThis,
|
|
379
|
-
urls: URI[],
|
|
380
|
-
msgP: MsgerParamsWithEnDe,
|
|
381
|
-
exGestalt: ExchangedGestalt,
|
|
382
|
-
): Promise<Result<MsgRawConnection>> {
|
|
383
|
-
return Result.Ok(new MockHttpConnection(sthis, exGestalt));
|
|
384
|
-
},
|
|
385
|
-
openWS: async function (
|
|
386
|
-
sthis: SuperThis,
|
|
387
|
-
url: URI,
|
|
388
|
-
msgP: MsgerParamsWithEnDe,
|
|
389
|
-
exGestalt: ExchangedGestalt,
|
|
390
|
-
): Promise<Result<MsgRawConnection>> {
|
|
391
|
-
// if (wsMock) {
|
|
392
|
-
// assert.fail("WS connection already created");
|
|
393
|
-
// }
|
|
394
|
-
wsMock = new MockWSConnection(sthis, exGestalt);
|
|
395
|
-
return Result.Ok(wsMock);
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
expect(rMsc.isOk()).toBe(true);
|
|
401
|
-
connected = rMsc.unwrap();
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
afterEach(async () => {
|
|
405
|
-
await connected.close({
|
|
406
|
-
tid: "1234",
|
|
407
|
-
type: "test",
|
|
408
|
-
version: "1.0",
|
|
409
|
-
auth: {
|
|
410
|
-
type: "error",
|
|
411
|
-
},
|
|
412
|
-
});
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it("bind", async () => {
|
|
416
|
-
const result = connected.bind(
|
|
417
|
-
{
|
|
418
|
-
tid: "1234",
|
|
419
|
-
type: "reqChat",
|
|
420
|
-
version: "1.0",
|
|
421
|
-
message: `ping[i]`,
|
|
422
|
-
auth: {
|
|
423
|
-
type: "error",
|
|
424
|
-
},
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
waitFor: (msg) => {
|
|
428
|
-
return msg.type === "resChat";
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
);
|
|
432
|
-
const reader = result.getReader();
|
|
433
|
-
|
|
434
|
-
const { done, value: msg } = await reader.read();
|
|
435
|
-
expect(done).toBe(false);
|
|
436
|
-
if (msg && !MsgIsError(msg)) {
|
|
437
|
-
expect(msg).toEqual({
|
|
438
|
-
auth: {
|
|
439
|
-
type: "error",
|
|
440
|
-
},
|
|
441
|
-
conn: msg.conn,
|
|
442
|
-
message: "got[ping[i]]",
|
|
443
|
-
targets: undefined,
|
|
444
|
-
tid: "1234",
|
|
445
|
-
type: "resChat",
|
|
446
|
-
version: "FP-MSG-1.0",
|
|
447
|
-
});
|
|
448
|
-
} else {
|
|
449
|
-
assert.fail("msg is error");
|
|
450
|
-
}
|
|
451
|
-
const refConn = msg.conn;
|
|
452
|
-
|
|
453
|
-
for (let i = 0; i < 3; i++) {
|
|
454
|
-
await connected.send({
|
|
455
|
-
tid: "1234" + i,
|
|
456
|
-
type: "reqChat",
|
|
457
|
-
version: "1.0",
|
|
458
|
-
message: `ping[${i}]`,
|
|
459
|
-
auth: {
|
|
460
|
-
type: "error",
|
|
461
|
-
},
|
|
462
|
-
});
|
|
463
|
-
wsMock.isReady = false; // trigger not-ready error
|
|
464
|
-
if (i > 0) {
|
|
465
|
-
const { done, value: msgl } = await reader.read();
|
|
466
|
-
expect(done).toBe(false);
|
|
467
|
-
if (msgl && !MsgIsError(msgl)) {
|
|
468
|
-
expect(msgl).toEqual({
|
|
469
|
-
auth: {
|
|
470
|
-
type: "error",
|
|
471
|
-
},
|
|
472
|
-
conn: refConn,
|
|
473
|
-
message: "got[ping[i]]",
|
|
474
|
-
targets: undefined,
|
|
475
|
-
tid: "1234",
|
|
476
|
-
type: "resChat",
|
|
477
|
-
version: "FP-MSG-1.0",
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
const { done, value: msgl } = await reader.read();
|
|
482
|
-
expect(done).toBe(false);
|
|
483
|
-
if (msgl && !MsgIsError(msgl)) {
|
|
484
|
-
expect(msgl).toEqual({
|
|
485
|
-
auth: {
|
|
486
|
-
type: "error",
|
|
487
|
-
},
|
|
488
|
-
conn: refConn,
|
|
489
|
-
message: "got[ping[" + i + "]]",
|
|
490
|
-
targets: undefined,
|
|
491
|
-
tid: "1234" + i,
|
|
492
|
-
type: "resChat",
|
|
493
|
-
version: "FP-MSG-1.0",
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
await connected.close({
|
|
499
|
-
tid: "1234",
|
|
500
|
-
type: "error",
|
|
501
|
-
version: "1.0",
|
|
502
|
-
message: "Not Happy",
|
|
503
|
-
auth: {
|
|
504
|
-
type: "error",
|
|
505
|
-
},
|
|
506
|
-
} as MsgBase);
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
it("request", async () => {
|
|
510
|
-
for (let i = 0; i < 3; i++) {
|
|
511
|
-
const result = await connected.request(
|
|
512
|
-
{
|
|
513
|
-
tid: "1234" + i,
|
|
514
|
-
type: "test",
|
|
515
|
-
version: "1.0",
|
|
516
|
-
auth: {
|
|
517
|
-
type: "error",
|
|
518
|
-
},
|
|
519
|
-
},
|
|
520
|
-
{
|
|
521
|
-
waitFor: (msg) => {
|
|
522
|
-
return msg.type === "test" && msg.tid === "1234";
|
|
523
|
-
},
|
|
524
|
-
},
|
|
525
|
-
);
|
|
526
|
-
expect(result).toEqual({
|
|
527
|
-
tid: "1234" + i,
|
|
528
|
-
type: "test",
|
|
529
|
-
version: "1.0",
|
|
530
|
-
auth: {
|
|
531
|
-
type: "error",
|
|
532
|
-
},
|
|
533
|
-
});
|
|
534
|
-
wsMock.isReady = false; // trigger not-ready error
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
it("send", async () => {
|
|
539
|
-
for (let i = 0; i < 3; i++) {
|
|
540
|
-
const result = await connected.send({
|
|
541
|
-
tid: "1234" + i,
|
|
542
|
-
type: "test",
|
|
543
|
-
version: "1.0",
|
|
544
|
-
auth: {
|
|
545
|
-
type: "error",
|
|
546
|
-
},
|
|
547
|
-
});
|
|
548
|
-
expect(result).toEqual({
|
|
549
|
-
tid: "1234" + i,
|
|
550
|
-
type: "test",
|
|
551
|
-
version: "1.0",
|
|
552
|
-
auth: {
|
|
553
|
-
type: "error",
|
|
554
|
-
},
|
|
555
|
-
});
|
|
556
|
-
wsMock.isReady = false; // trigger not-ready error
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
});
|