jazz-tools 0.7.35-guest-auth.5 → 0.7.35-guest-auth.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -443,3 +443,56 @@ describe("BinaryCoStream loading & Subscription", async () => {
443
443
  });
444
444
  });
445
445
  });
446
+
447
+ describe("BinaryCoStream.loadAsBlob", async () => {
448
+ async function setup() {
449
+ const me = await Account.create({
450
+ creationProps: { name: "Hermes Puggington" },
451
+ crypto: Crypto,
452
+ });
453
+
454
+ const stream = BinaryCoStream.create({ owner: me });
455
+
456
+ stream.start({ mimeType: "text/plain" });
457
+
458
+ return { stream, me };
459
+ }
460
+
461
+ test("resolves only when the stream is ended", async () => {
462
+ const { stream, me } = await setup();
463
+ stream.push(new Uint8Array([1]));
464
+
465
+ const promise = BinaryCoStream.loadAsBlob(stream.id, me);
466
+
467
+ await stream.ensureLoaded([]);
468
+
469
+ stream.push(new Uint8Array([2]));
470
+ stream.end();
471
+
472
+ const blob = await promise;
473
+
474
+ // The promise resolves only when the stream is ended
475
+ // so we get a blob with all the chunks
476
+ expect(blob?.size).toBe(2);
477
+ });
478
+
479
+ test("resolves with an unfinshed blob if allowUnfinished: true", async () => {
480
+ const { stream, me } = await setup();
481
+ stream.push(new Uint8Array([1]));
482
+
483
+ const promise = BinaryCoStream.loadAsBlob(stream.id, me, {
484
+ allowUnfinished: true,
485
+ });
486
+
487
+ await stream.ensureLoaded([]);
488
+
489
+ stream.push(new Uint8Array([2]));
490
+ stream.end();
491
+
492
+ const blob = await promise;
493
+
494
+ // The promise resolves before the stream is ended
495
+ // so we get a blob only with the first chunk
496
+ expect(blob?.size).toBe(1);
497
+ });
498
+ });
@@ -60,6 +60,7 @@ describe("Deep loading with depth arg", async () => {
60
60
  });
61
61
 
62
62
  test("loading a deeply nested object will wait until all required refs are loaded", async () => {
63
+ const ownership = { owner: me };
63
64
  const map = TestMap.create(
64
65
  {
65
66
  list: TestList.create(
@@ -70,19 +71,19 @@ describe("Deep loading with depth arg", async () => {
70
71
  [
71
72
  InnermostMap.create(
72
73
  { value: "hello" },
73
- { owner: me },
74
+ ownership,
74
75
  ),
75
76
  ],
76
- { owner: me },
77
+ ownership,
77
78
  ),
78
79
  },
79
- { owner: me },
80
+ ownership,
80
81
  ),
81
82
  ],
82
- { owner: me },
83
+ ownership,
83
84
  ),
84
85
  },
85
- { owner: me },
86
+ ownership,
86
87
  );
87
88
 
88
89
  const map1 = await TestMap.load(map.id, meOnSecondPeer, {});
@@ -141,8 +142,7 @@ describe("Deep loading with depth arg", async () => {
141
142
  throw new Error("map4 is undefined");
142
143
  }
143
144
  expect(map4.list[0]?.stream).not.toBe(null);
144
- // TODO: why is this actually defined?
145
- // expect(map4.list[0]?.stream?.[me.id]).toBe(undefined)
145
+ expect(map4.list[0]?.stream?.[me.id]).not.toBe(null);
146
146
  expect(map4.list[0]?.stream?.byMe?.value).toBe(null);
147
147
 
148
148
  const map5 = await TestMap.load(map.id, meOnSecondPeer, {