@graffiti-garden/api 1.0.2 → 1.0.3

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/tests/discover.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  import { it, expect, describe, assert, beforeAll } from "vitest";
2
2
  import type {
3
3
  Graffiti,
4
- GraffitiObjectBase,
5
4
  GraffitiSession,
6
5
  JSONSchema,
7
6
  } from "@graffiti-garden/api";
7
+ import {
8
+ GraffitiErrorForbidden,
9
+ GraffitiErrorInvalidSchema,
10
+ GraffitiErrorNotFound,
11
+ } from "@graffiti-garden/api";
8
12
  import {
9
13
  randomString,
10
14
  nextStreamValue,
@@ -103,6 +107,19 @@ export const graffitiDiscoverTests = (
103
107
  expect(value.actor).toEqual(session1.actor);
104
108
  });
105
109
 
110
+ it("discover bad schema", async () => {
111
+ const iterator = graffiti.discover([], {
112
+ properties: {
113
+ value: {
114
+ //@ts-ignore
115
+ type: "asdf",
116
+ },
117
+ },
118
+ });
119
+
120
+ await expect(iterator.next()).rejects.toThrow(GraffitiErrorInvalidSchema);
121
+ });
122
+
106
123
  it("discover for actor", async () => {
107
124
  const object1 = randomPostObject();
108
125
  const posted1 = await graffiti.post<{}>(object1, session1);
@@ -396,12 +413,47 @@ export const graffitiDiscoverTests = (
396
413
  assert(!value.done && !value.value.error, "value is done");
397
414
  assert(value.value.tombstone, "value is not tombstone");
398
415
  expect(value.value.object.url).toEqual(posted.url);
399
- await expect(tombIterator.next()).resolves.toHaveProperty(
416
+ const returnValue2 = await tombIterator.next();
417
+ assert(returnValue2.done, "value2 is not done");
418
+
419
+ // Post another object
420
+ const posted2 = await graffiti.post<{}>(object, session);
421
+ const doubleContinueIterator = continueStream<{}>(
422
+ graffiti,
423
+ returnValue2.value,
424
+ continueType,
425
+ );
426
+ const value2 = await doubleContinueIterator.next();
427
+ assert(!value2.done && !value2.value.error, "value2 is done");
428
+ assert(!value2.value.tombstone, "value2 is tombstone");
429
+ expect(value2.value.object.url).toEqual(posted2.url);
430
+ await expect(doubleContinueIterator.next()).resolves.toHaveProperty(
400
431
  "done",
401
432
  true,
402
433
  );
403
434
  });
435
+
436
+ it("continue with wrong actor", async () => {
437
+ const iterator = graffiti.discover<{}>([], {}, session1);
438
+ const result = await iterator.next();
439
+ assert(result.done, "iterator is not done");
440
+
441
+ const continuation = continueStream<{}>(
442
+ graffiti,
443
+ result.value,
444
+ continueType,
445
+ session2,
446
+ );
447
+ await expect(continuation.next()).rejects.toThrow(
448
+ GraffitiErrorForbidden,
449
+ );
450
+ });
404
451
  });
405
452
  }
453
+
454
+ it("lookup non-existant cursor", async () => {
455
+ const iterator = graffiti.continueDiscover(randomString());
456
+ await expect(iterator.next()).rejects.toThrow(GraffitiErrorNotFound);
457
+ });
406
458
  });
407
459
  };