@fedify/botkit 0.5.0-dev.210 → 0.5.0-dev.226
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/dist/bot-group.test.d.ts +2 -0
- package/dist/bot-group.test.js +220 -0
- package/dist/bot-group.test.js.map +1 -0
- package/dist/bot-impl.d.ts +132 -13
- package/dist/bot-impl.d.ts.map +1 -1
- package/dist/bot-impl.js +400 -178
- package/dist/bot-impl.js.map +1 -1
- package/dist/bot-impl.test.js +214 -76
- package/dist/bot-impl.test.js.map +1 -1
- package/dist/bot.d.ts +94 -48
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +2 -104
- package/dist/bot.js.map +1 -1
- package/dist/bot.test.js +59 -0
- package/dist/bot.test.js.map +1 -1
- package/dist/components/FollowButton.d.ts +3 -1
- package/dist/components/FollowButton.d.ts.map +1 -1
- package/dist/components/FollowButton.js +2 -2
- package/dist/components/FollowButton.js.map +1 -1
- package/dist/components/Layout.js +1 -1
- package/dist/components/Layout.js.map +1 -1
- package/dist/components/Message.d.ts +2 -2
- package/dist/deno.js +3 -13
- package/dist/deno.js.map +1 -1
- package/dist/follow-impl.test.js +3 -3
- package/dist/follow-impl.test.js.map +1 -1
- package/dist/instance-impl.d.ts +158 -0
- package/dist/instance-impl.d.ts.map +1 -0
- package/dist/instance-impl.js +603 -0
- package/dist/instance-impl.js.map +1 -0
- package/dist/instance-impl.test.d.ts +2 -0
- package/dist/instance-impl.test.js +103 -0
- package/dist/instance-impl.test.js.map +1 -0
- package/dist/instance-multi.test.d.ts +2 -0
- package/dist/instance-multi.test.js +151 -0
- package/dist/instance-multi.test.js.map +1 -0
- package/dist/instance-routing.test.d.ts +2 -0
- package/dist/instance-routing.test.js +367 -0
- package/dist/instance-routing.test.js.map +1 -0
- package/dist/instance.d.ts +318 -0
- package/dist/instance.d.ts.map +1 -0
- package/dist/instance.js +51 -0
- package/dist/instance.js.map +1 -0
- package/dist/message-impl.d.ts.map +1 -1
- package/dist/message-impl.js +17 -10
- package/dist/message-impl.js.map +1 -1
- package/dist/message-impl.test.js +43 -9
- package/dist/message-impl.test.js.map +1 -1
- package/dist/mod.d.ts +5 -3
- package/dist/mod.js +4 -2
- package/dist/pages.d.ts +10 -1
- package/dist/pages.d.ts.map +1 -1
- package/dist/pages.js +112 -41
- package/dist/pages.js.map +1 -1
- package/dist/pages.test.d.ts +2 -0
- package/dist/pages.test.js +170 -0
- package/dist/pages.test.js.map +1 -0
- package/dist/repository.d.ts +385 -138
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +595 -223
- package/dist/repository.js.map +1 -1
- package/dist/repository.test.js +564 -136
- package/dist/repository.test.js.map +1 -1
- package/dist/session-impl.d.ts.map +1 -1
- package/dist/session-impl.js +13 -4
- package/dist/session-impl.js.map +1 -1
- package/dist/session-impl.test.d.ts.map +1 -1
- package/dist/session-impl.test.js +9 -9
- package/dist/session-impl.test.js.map +1 -1
- package/dist/session.d.ts +8 -3
- package/dist/session.d.ts.map +1 -1
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +27 -10
- package/dist/text.js.map +1 -1
- package/dist/text.test.js +37 -2
- package/dist/text.test.js.map +1 -1
- package/dist/uri.d.ts +46 -0
- package/dist/uri.d.ts.map +1 -0
- package/dist/uri.js +64 -0
- package/dist/uri.js.map +1 -0
- package/dist/uri.test.d.ts +2 -0
- package/dist/uri.test.js +93 -0
- package/dist/uri.test.js.map +1 -0
- package/package.json +6 -2
package/dist/bot-impl.test.js
CHANGED
|
@@ -139,7 +139,7 @@ test("BotImpl.dispatchActor()", async () => {
|
|
|
139
139
|
assert.ok(publicKey != null);
|
|
140
140
|
assert.deepStrictEqual(publicKey.ownerId, actor.id);
|
|
141
141
|
assert.ok(publicKey.publicKey != null);
|
|
142
|
-
const keys = await repository.getKeyPairs();
|
|
142
|
+
const keys = await repository.getKeyPairs("bot");
|
|
143
143
|
assert.ok(keys != null);
|
|
144
144
|
assert.deepStrictEqual(publicKey.publicKey, keys[0].publicKey);
|
|
145
145
|
const assertionMethods = await Array.fromAsync(actor.getAssertionMethods());
|
|
@@ -166,7 +166,7 @@ test("BotImpl.dispatchActorKeyPairs()", async () => {
|
|
|
166
166
|
const ctx = bot.federation.createContext(new URL("https://example.com"), void 0);
|
|
167
167
|
assert.deepStrictEqual(await bot.dispatchActorKeyPairs(ctx, "non-existent"), []);
|
|
168
168
|
const keyPairs = await bot.dispatchActorKeyPairs(ctx, "bot");
|
|
169
|
-
const storedKeyPairs = await repository.getKeyPairs();
|
|
169
|
+
const storedKeyPairs = await repository.getKeyPairs("bot");
|
|
170
170
|
assert.deepStrictEqual(keyPairs, storedKeyPairs);
|
|
171
171
|
const keyPairs2 = await bot.dispatchActorKeyPairs(ctx, "bot");
|
|
172
172
|
assert.deepStrictEqual(keyPairs2, storedKeyPairs);
|
|
@@ -187,17 +187,17 @@ test("BotImpl.dispatchFollowers()", async () => {
|
|
|
187
187
|
items: [],
|
|
188
188
|
nextCursor: null
|
|
189
189
|
});
|
|
190
|
-
await repository.addFollower(new URL("https://example.com/actor/1#follow"), new Person({
|
|
190
|
+
await repository.addFollower("bot", new URL("https://example.com/actor/1#follow"), new Person({
|
|
191
191
|
id: new URL("https://example.com/actor/1"),
|
|
192
192
|
preferredUsername: "john",
|
|
193
193
|
inbox: new URL("https://example.com/actor/1/inbox")
|
|
194
194
|
}));
|
|
195
|
-
await repository.addFollower(new URL("https://example.com/actor/2#follow"), new Person({
|
|
195
|
+
await repository.addFollower("bot", new URL("https://example.com/actor/2#follow"), new Person({
|
|
196
196
|
id: new URL("https://example.com/actor/2"),
|
|
197
197
|
preferredUsername: "jane",
|
|
198
198
|
inbox: new URL("https://example.com/actor/2/inbox")
|
|
199
199
|
}));
|
|
200
|
-
await repository.addFollower(new URL("https://example.com/actor/3#follow"), new Person({
|
|
200
|
+
await repository.addFollower("bot", new URL("https://example.com/actor/3#follow"), new Person({
|
|
201
201
|
id: new URL("https://example.com/actor/3"),
|
|
202
202
|
preferredUsername: "joe",
|
|
203
203
|
inbox: new URL("https://example.com/actor/3/inbox")
|
|
@@ -249,17 +249,17 @@ test("BotImpl.countFollowers()", async () => {
|
|
|
249
249
|
const ctx = bot.federation.createContext(new URL("https://example.com"), void 0);
|
|
250
250
|
assert.deepStrictEqual(await bot.countFollowers(ctx, "non-existent"), null);
|
|
251
251
|
assert.deepStrictEqual(await bot.countFollowers(ctx, "bot"), 0);
|
|
252
|
-
await repository.addFollower(new URL("https://example.com/actor/1#follow"), new Person({
|
|
252
|
+
await repository.addFollower("bot", new URL("https://example.com/actor/1#follow"), new Person({
|
|
253
253
|
id: new URL("https://example.com/actor/1"),
|
|
254
254
|
preferredUsername: "john",
|
|
255
255
|
inbox: new URL("https://example.com/actor/1/inbox")
|
|
256
256
|
}));
|
|
257
|
-
await repository.addFollower(new URL("https://example.com/actor/2#follow"), new Person({
|
|
257
|
+
await repository.addFollower("bot", new URL("https://example.com/actor/2#follow"), new Person({
|
|
258
258
|
id: new URL("https://example.com/actor/2"),
|
|
259
259
|
preferredUsername: "jane",
|
|
260
260
|
inbox: new URL("https://example.com/actor/2/inbox")
|
|
261
261
|
}));
|
|
262
|
-
await repository.addFollower(new URL("https://example.com/actor/3#follow"), new Person({
|
|
262
|
+
await repository.addFollower("bot", new URL("https://example.com/actor/3#follow"), new Person({
|
|
263
263
|
id: new URL("https://example.com/actor/3"),
|
|
264
264
|
preferredUsername: "joe",
|
|
265
265
|
inbox: new URL("https://example.com/actor/3/inbox")
|
|
@@ -298,7 +298,7 @@ test("BotImpl.getPermissionChecker()", async () => {
|
|
|
298
298
|
assert.deepStrictEqual(nonFollower(unlistedPost), true);
|
|
299
299
|
assert.deepStrictEqual(nonFollower(followersPost), false);
|
|
300
300
|
assert.deepStrictEqual(nonFollower(directPost), false);
|
|
301
|
-
await repository.addFollower(new URL("https://example.com/actor/john#follow"), new Person({
|
|
301
|
+
await repository.addFollower("bot", new URL("https://example.com/actor/john#follow"), new Person({
|
|
302
302
|
id: new URL("https://example.com/actor/john"),
|
|
303
303
|
preferredUsername: "john"
|
|
304
304
|
}));
|
|
@@ -337,7 +337,7 @@ test("BotImpl.dispatchOutbox()", async () => {
|
|
|
337
337
|
items: [],
|
|
338
338
|
nextCursor: null
|
|
339
339
|
});
|
|
340
|
-
await repository.addMessage("78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
340
|
+
await repository.addMessage("bot", "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
341
341
|
id: new URL("https://example.com/ap/actor/bot/create/78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"),
|
|
342
342
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
343
343
|
to: PUBLIC_COLLECTION,
|
|
@@ -352,7 +352,7 @@ test("BotImpl.dispatchOutbox()", async () => {
|
|
|
352
352
|
}),
|
|
353
353
|
published: Temporal.Instant.from("2025-01-01T00:00:00Z")
|
|
354
354
|
}));
|
|
355
|
-
await repository.addMessage("46442170-836d-4a0d-9142-f31242abe2f9", new Create({
|
|
355
|
+
await repository.addMessage("bot", "46442170-836d-4a0d-9142-f31242abe2f9", new Create({
|
|
356
356
|
id: new URL("https://example.com/ap/actor/bot/create/46442170-836d-4a0d-9142-f31242abe2f9"),
|
|
357
357
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
358
358
|
to: PUBLIC_COLLECTION,
|
|
@@ -367,7 +367,7 @@ test("BotImpl.dispatchOutbox()", async () => {
|
|
|
367
367
|
}),
|
|
368
368
|
published: Temporal.Instant.from("2025-01-02T00:00:00Z")
|
|
369
369
|
}));
|
|
370
|
-
await repository.addMessage("8386a4c7-06f8-409f-ad72-2bba43e83363", new Create({
|
|
370
|
+
await repository.addMessage("bot", "8386a4c7-06f8-409f-ad72-2bba43e83363", new Create({
|
|
371
371
|
id: new URL("https://example.com/ap/actor/bot/create/8386a4c7-06f8-409f-ad72-2bba43e83363"),
|
|
372
372
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
373
373
|
to: new URL("https://example.com/ap/actor/john"),
|
|
@@ -427,7 +427,7 @@ test("BotImpl.countOutbox()", async () => {
|
|
|
427
427
|
const ctx = bot.federation.createContext(new URL("https://example.com"), void 0);
|
|
428
428
|
assert.deepStrictEqual(await bot.countOutbox(ctx, "non-existent"), null);
|
|
429
429
|
assert.deepStrictEqual(await bot.countOutbox(ctx, "bot"), 0);
|
|
430
|
-
await repository.addMessage("78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
430
|
+
await repository.addMessage("bot", "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
431
431
|
id: new URL("https://example.com/ap/actor/bot/create/78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"),
|
|
432
432
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
433
433
|
to: PUBLIC_COLLECTION,
|
|
@@ -440,7 +440,7 @@ test("BotImpl.countOutbox()", async () => {
|
|
|
440
440
|
content: "Hello, world!"
|
|
441
441
|
})
|
|
442
442
|
}));
|
|
443
|
-
await repository.addMessage("46442170-836d-4a0d-9142-f31242abe2f9", new Create({
|
|
443
|
+
await repository.addMessage("bot", "46442170-836d-4a0d-9142-f31242abe2f9", new Create({
|
|
444
444
|
id: new URL("https://example.com/ap/actor/bot/create/46442170-836d-4a0d-9142-f31242abe2f9"),
|
|
445
445
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
446
446
|
to: PUBLIC_COLLECTION,
|
|
@@ -453,7 +453,7 @@ test("BotImpl.countOutbox()", async () => {
|
|
|
453
453
|
content: "Hello, followers!"
|
|
454
454
|
})
|
|
455
455
|
}));
|
|
456
|
-
await repository.addMessage("8386a4c7-06f8-409f-ad72-2bba43e83363", new Create({
|
|
456
|
+
await repository.addMessage("bot", "8386a4c7-06f8-409f-ad72-2bba43e83363", new Create({
|
|
457
457
|
id: new URL("https://example.com/ap/actor/bot/create/8386a4c7-06f8-409f-ad72-2bba43e83363"),
|
|
458
458
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
459
459
|
to: new URL("https://example.com/ap/actor/john"),
|
|
@@ -475,14 +475,20 @@ test("BotImpl.dispatchFollow()", async () => {
|
|
|
475
475
|
username: "bot"
|
|
476
476
|
});
|
|
477
477
|
const ctx = bot.federation.createContext(new Request("https://example.com/"), void 0);
|
|
478
|
-
assert.deepStrictEqual(await bot.dispatchFollow(ctx, {
|
|
479
|
-
|
|
478
|
+
assert.deepStrictEqual(await bot.dispatchFollow(ctx, {
|
|
479
|
+
identifier: "bot",
|
|
480
|
+
id: crypto.randomUUID()
|
|
481
|
+
}), null);
|
|
482
|
+
await repository.addSentFollow("bot", "b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a", new Follow({
|
|
480
483
|
id: new URL("https://example.com/ap/follow/b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a"),
|
|
481
484
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
482
485
|
object: new URL("https://example.com/ap/actor/john"),
|
|
483
486
|
to: new URL("https://example.com/ap/actor/john")
|
|
484
487
|
}));
|
|
485
|
-
const follow = await bot.dispatchFollow(ctx, {
|
|
488
|
+
const follow = await bot.dispatchFollow(ctx, {
|
|
489
|
+
identifier: "bot",
|
|
490
|
+
id: "b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a"
|
|
491
|
+
});
|
|
486
492
|
assert.ok(follow instanceof Follow);
|
|
487
493
|
assert.deepStrictEqual(follow.id, new URL("https://example.com/ap/follow/b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a"));
|
|
488
494
|
assert.deepStrictEqual(follow.actorId, new URL("https://example.com/ap/actor/bot"));
|
|
@@ -497,7 +503,7 @@ test("BotImpl.authorizeFollow()", async () => {
|
|
|
497
503
|
username: "bot"
|
|
498
504
|
});
|
|
499
505
|
const ctx = bot.federation.createContext(new Request("https://example.com/"), void 0);
|
|
500
|
-
await repository.addSentFollow("b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a", new Follow({
|
|
506
|
+
await repository.addSentFollow("bot", "b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a", new Follow({
|
|
501
507
|
id: new URL("https://example.com/ap/follow/b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a"),
|
|
502
508
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
503
509
|
object: new URL("https://example.com/ap/actor/john"),
|
|
@@ -511,13 +517,25 @@ test("BotImpl.authorizeFollow()", async () => {
|
|
|
511
517
|
});
|
|
512
518
|
};
|
|
513
519
|
setSignedKeyOwner(new Person({ id: new URL("https://example.com/ap/actor/john") }));
|
|
514
|
-
assert.ok(await bot.authorizeFollow(ctx, {
|
|
520
|
+
assert.ok(await bot.authorizeFollow(ctx, {
|
|
521
|
+
identifier: "bot",
|
|
522
|
+
id: "b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a"
|
|
523
|
+
}));
|
|
515
524
|
setSignedKeyOwner(await new SessionImpl(bot, ctx).getActor());
|
|
516
|
-
assert.ok(await bot.authorizeFollow(ctx, {
|
|
525
|
+
assert.ok(await bot.authorizeFollow(ctx, {
|
|
526
|
+
identifier: "bot",
|
|
527
|
+
id: "b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a"
|
|
528
|
+
}));
|
|
517
529
|
setSignedKeyOwner(new Person({ id: new URL("https://example.com/ap/actor/alice") }));
|
|
518
|
-
assert.deepStrictEqual(await bot.authorizeFollow(ctx, {
|
|
530
|
+
assert.deepStrictEqual(await bot.authorizeFollow(ctx, {
|
|
531
|
+
identifier: "bot",
|
|
532
|
+
id: "b51f6ca8-53e6-4f7d-ac1f-d039e8c6df5a"
|
|
533
|
+
}), false);
|
|
519
534
|
setSignedKeyOwner(new Person({ id: new URL("https://example.com/ap/actor/john") }));
|
|
520
|
-
assert.deepStrictEqual(await bot.authorizeFollow(ctx, {
|
|
535
|
+
assert.deepStrictEqual(await bot.authorizeFollow(ctx, {
|
|
536
|
+
identifier: "bot",
|
|
537
|
+
id: crypto.randomUUID()
|
|
538
|
+
}), false);
|
|
521
539
|
});
|
|
522
540
|
test("BotImpl.dispatchCreate()", async () => {
|
|
523
541
|
const repository = new MemoryRepository();
|
|
@@ -527,8 +545,11 @@ test("BotImpl.dispatchCreate()", async () => {
|
|
|
527
545
|
username: "bot"
|
|
528
546
|
});
|
|
529
547
|
const ctx = bot.federation.createContext(new Request("https://example.com/"), void 0);
|
|
530
|
-
assert.deepStrictEqual(await bot.dispatchCreate(ctx, {
|
|
531
|
-
|
|
548
|
+
assert.deepStrictEqual(await bot.dispatchCreate(ctx, {
|
|
549
|
+
identifier: "bot",
|
|
550
|
+
id: "non-existent"
|
|
551
|
+
}), null);
|
|
552
|
+
await repository.addMessage("bot", "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
532
553
|
id: new URL("https://example.com/ap/actor/bot/create/78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"),
|
|
533
554
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
534
555
|
to: PUBLIC_COLLECTION,
|
|
@@ -541,14 +562,20 @@ test("BotImpl.dispatchCreate()", async () => {
|
|
|
541
562
|
content: "Hello, world!"
|
|
542
563
|
})
|
|
543
564
|
}));
|
|
544
|
-
const create = await bot.dispatchCreate(ctx, {
|
|
565
|
+
const create = await bot.dispatchCreate(ctx, {
|
|
566
|
+
identifier: "bot",
|
|
567
|
+
id: "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"
|
|
568
|
+
});
|
|
545
569
|
assert.ok(create instanceof Create);
|
|
546
570
|
assert.deepStrictEqual(create.id, new URL("https://example.com/ap/actor/bot/create/78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"));
|
|
547
571
|
const ctx2 = bot.federation.createContext(new Request("https://example.com/"), void 0);
|
|
548
572
|
const actor = new Person({ id: new URL("https://example.com/ap/actor/john") });
|
|
549
573
|
ctx2.getSignedKeyOwner = () => Promise.resolve(actor);
|
|
550
|
-
assert.deepStrictEqual(await bot.dispatchCreate(ctx2, {
|
|
551
|
-
|
|
574
|
+
assert.deepStrictEqual(await bot.dispatchCreate(ctx2, {
|
|
575
|
+
identifier: "bot",
|
|
576
|
+
id: "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"
|
|
577
|
+
}), create);
|
|
578
|
+
await repository.addMessage("bot", "8386a4c7-06f8-409f-ad72-2bba43e83363", new Create({
|
|
552
579
|
id: new URL("https://example.com/ap/actor/bot/create/8386a4c7-06f8-409f-ad72-2bba43e83363"),
|
|
553
580
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
554
581
|
to: new URL("https://example.com/ap/actor/john"),
|
|
@@ -559,18 +586,27 @@ test("BotImpl.dispatchCreate()", async () => {
|
|
|
559
586
|
content: "Hello, followers!"
|
|
560
587
|
})
|
|
561
588
|
}));
|
|
562
|
-
assert.deepStrictEqual(await bot.dispatchCreate(ctx, {
|
|
563
|
-
|
|
589
|
+
assert.deepStrictEqual(await bot.dispatchCreate(ctx, {
|
|
590
|
+
identifier: "bot",
|
|
591
|
+
id: "8386a4c7-06f8-409f-ad72-2bba43e83363"
|
|
592
|
+
}), null);
|
|
593
|
+
const create2 = await bot.dispatchCreate(ctx2, {
|
|
594
|
+
identifier: "bot",
|
|
595
|
+
id: "8386a4c7-06f8-409f-ad72-2bba43e83363"
|
|
596
|
+
});
|
|
564
597
|
assert.ok(create2 instanceof Create);
|
|
565
598
|
assert.deepStrictEqual(create2.id, new URL("https://example.com/ap/actor/bot/create/8386a4c7-06f8-409f-ad72-2bba43e83363"));
|
|
566
|
-
await repository.addMessage("ce8081ac-f238-484b-9a70-5d8a4b66d829", new Announce({
|
|
599
|
+
await repository.addMessage("bot", "ce8081ac-f238-484b-9a70-5d8a4b66d829", new Announce({
|
|
567
600
|
id: new URL("https://example.com/ap/actor/bot/announce/ce8081ac-f238-484b-9a70-5d8a4b66d829"),
|
|
568
601
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
569
602
|
to: PUBLIC_COLLECTION,
|
|
570
603
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
571
604
|
object: new URL("https://example.com/ap/actor/bot/note/2")
|
|
572
605
|
}));
|
|
573
|
-
assert.deepStrictEqual(await bot.dispatchCreate(ctx, {
|
|
606
|
+
assert.deepStrictEqual(await bot.dispatchCreate(ctx, {
|
|
607
|
+
identifier: "bot",
|
|
608
|
+
id: "ce8081ac-f238-484b-9a70-5d8a4b66d829"
|
|
609
|
+
}), null);
|
|
574
610
|
});
|
|
575
611
|
test("BotImpl.dispatchMessage()", async () => {
|
|
576
612
|
const repository = new MemoryRepository();
|
|
@@ -581,7 +617,7 @@ test("BotImpl.dispatchMessage()", async () => {
|
|
|
581
617
|
});
|
|
582
618
|
const ctx = bot.federation.createContext(new Request("https://example.com/"), void 0);
|
|
583
619
|
assert.deepStrictEqual(await bot.dispatchMessage(Note, ctx, "non-existent"), null);
|
|
584
|
-
await repository.addMessage("78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
620
|
+
await repository.addMessage("bot", "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
585
621
|
id: new URL("https://example.com/ap/actor/bot/create/78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"),
|
|
586
622
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
587
623
|
to: PUBLIC_COLLECTION,
|
|
@@ -602,7 +638,7 @@ test("BotImpl.dispatchMessage()", async () => {
|
|
|
602
638
|
ctx2.getSignedKeyOwner = () => Promise.resolve(actor);
|
|
603
639
|
assert.deepStrictEqual(await bot.dispatchMessage(Note, ctx2, "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"), note);
|
|
604
640
|
assert.deepStrictEqual(await bot.dispatchMessage(Article, ctx, "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"), null);
|
|
605
|
-
await repository.addMessage("8386a4c7-06f8-409f-ad72-2bba43e83363", new Create({
|
|
641
|
+
await repository.addMessage("bot", "8386a4c7-06f8-409f-ad72-2bba43e83363", new Create({
|
|
606
642
|
id: new URL("https://example.com/ap/actor/bot/create/8386a4c7-06f8-409f-ad72-2bba43e83363"),
|
|
607
643
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
608
644
|
to: new URL("https://example.com/ap/actor/john"),
|
|
@@ -617,7 +653,7 @@ test("BotImpl.dispatchMessage()", async () => {
|
|
|
617
653
|
const note2 = await bot.dispatchMessage(Note, ctx2, "8386a4c7-06f8-409f-ad72-2bba43e83363");
|
|
618
654
|
assert.ok(note2 instanceof Note);
|
|
619
655
|
assert.deepStrictEqual(note2.id, new URL("https://example.com/ap/actor/bot/note/3"));
|
|
620
|
-
await repository.addMessage("ce8081ac-f238-484b-9a70-5d8a4b66d829", new Announce({
|
|
656
|
+
await repository.addMessage("bot", "ce8081ac-f238-484b-9a70-5d8a4b66d829", new Announce({
|
|
621
657
|
id: new URL("https://example.com/ap/actor/bot/announce/ce8081ac-f238-484b-9a70-5d8a4b66d829"),
|
|
622
658
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
623
659
|
to: PUBLIC_COLLECTION,
|
|
@@ -634,18 +670,24 @@ test("BotImpl.dispatchAnnounce()", async () => {
|
|
|
634
670
|
username: "bot"
|
|
635
671
|
});
|
|
636
672
|
const ctx = bot.federation.createContext(new Request("https://example.com/"), void 0);
|
|
637
|
-
assert.deepStrictEqual(await bot.dispatchAnnounce(ctx, {
|
|
638
|
-
|
|
673
|
+
assert.deepStrictEqual(await bot.dispatchAnnounce(ctx, {
|
|
674
|
+
identifier: "bot",
|
|
675
|
+
id: "non-existent"
|
|
676
|
+
}), null);
|
|
677
|
+
await repository.addMessage("bot", "ce8081ac-f238-484b-9a70-5d8a4b66d829", new Announce({
|
|
639
678
|
id: new URL("https://example.com/ap/actor/bot/announce/ce8081ac-f238-484b-9a70-5d8a4b66d829"),
|
|
640
679
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
641
680
|
to: PUBLIC_COLLECTION,
|
|
642
681
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
643
682
|
object: new URL("https://example.com/ap/actor/bot/note/2")
|
|
644
683
|
}));
|
|
645
|
-
const announce = await bot.dispatchAnnounce(ctx, {
|
|
684
|
+
const announce = await bot.dispatchAnnounce(ctx, {
|
|
685
|
+
identifier: "bot",
|
|
686
|
+
id: "ce8081ac-f238-484b-9a70-5d8a4b66d829"
|
|
687
|
+
});
|
|
646
688
|
assert.ok(announce instanceof Announce);
|
|
647
689
|
assert.deepStrictEqual(announce.id, new URL("https://example.com/ap/actor/bot/announce/ce8081ac-f238-484b-9a70-5d8a4b66d829"));
|
|
648
|
-
await repository.addMessage("78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
690
|
+
await repository.addMessage("bot", "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
649
691
|
id: new URL("https://example.com/ap/actor/bot/create/78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"),
|
|
650
692
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
651
693
|
to: PUBLIC_COLLECTION,
|
|
@@ -658,18 +700,27 @@ test("BotImpl.dispatchAnnounce()", async () => {
|
|
|
658
700
|
content: "Hello, world!"
|
|
659
701
|
})
|
|
660
702
|
}));
|
|
661
|
-
assert.deepStrictEqual(await bot.dispatchAnnounce(ctx, {
|
|
662
|
-
|
|
703
|
+
assert.deepStrictEqual(await bot.dispatchAnnounce(ctx, {
|
|
704
|
+
identifier: "bot",
|
|
705
|
+
id: "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"
|
|
706
|
+
}), null);
|
|
707
|
+
await repository.addMessage("bot", "d4a7ef9b-682c-4de9-b23c-87747d6725cb", new Announce({
|
|
663
708
|
id: new URL("https://example.com/ap/actor/bot/announce/d4a7ef9b-682c-4de9-b23c-87747d6725cb"),
|
|
664
709
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
665
710
|
to: new URL("https://example.com/ap/actor/john"),
|
|
666
711
|
object: new URL("https://example.com/ap/actor/bot/note/2")
|
|
667
712
|
}));
|
|
668
|
-
assert.deepStrictEqual(await bot.dispatchAnnounce(ctx, {
|
|
713
|
+
assert.deepStrictEqual(await bot.dispatchAnnounce(ctx, {
|
|
714
|
+
identifier: "bot",
|
|
715
|
+
id: "d4a7ef9b-682c-4de9-b23c-87747d6725cb"
|
|
716
|
+
}), null);
|
|
669
717
|
const ctx2 = bot.federation.createContext(new Request("https://example.com/"), void 0);
|
|
670
718
|
const actor = new Person({ id: new URL("https://example.com/ap/actor/john") });
|
|
671
719
|
ctx2.getSignedKeyOwner = () => Promise.resolve(actor);
|
|
672
|
-
const announce2 = await bot.dispatchAnnounce(ctx2, {
|
|
720
|
+
const announce2 = await bot.dispatchAnnounce(ctx2, {
|
|
721
|
+
identifier: "bot",
|
|
722
|
+
id: "d4a7ef9b-682c-4de9-b23c-87747d6725cb"
|
|
723
|
+
});
|
|
673
724
|
assert.ok(announce2 instanceof Announce);
|
|
674
725
|
assert.deepStrictEqual(announce2.id, new URL("https://example.com/ap/actor/bot/announce/d4a7ef9b-682c-4de9-b23c-87747d6725cb"));
|
|
675
726
|
});
|
|
@@ -762,7 +813,7 @@ for (const policy of [
|
|
|
762
813
|
object: new URL("https://example.com/ap/actor/bot")
|
|
763
814
|
});
|
|
764
815
|
await bot.onFollowed(ctx, followWithoutActor);
|
|
765
|
-
assert.deepStrictEqual(await repository.countFollowers(), 0);
|
|
816
|
+
assert.deepStrictEqual(await repository.countFollowers("bot"), 0);
|
|
766
817
|
});
|
|
767
818
|
await t.test("with wrong actor", async () => {
|
|
768
819
|
const followWithWrongActor = new Follow({
|
|
@@ -771,7 +822,7 @@ for (const policy of [
|
|
|
771
822
|
object: new URL("https://example.com/ap/actor/bot")
|
|
772
823
|
});
|
|
773
824
|
await bot.onFollowed(ctx, followWithWrongActor);
|
|
774
|
-
assert.deepStrictEqual(await repository.countFollowers(), 0);
|
|
825
|
+
assert.deepStrictEqual(await repository.countFollowers("bot"), 0);
|
|
775
826
|
});
|
|
776
827
|
const actor = new Person({
|
|
777
828
|
id: new URL("https://example.com/ap/actor/john"),
|
|
@@ -784,7 +835,7 @@ for (const policy of [
|
|
|
784
835
|
object: new URL("https://example.com/ap/actor/non-existent")
|
|
785
836
|
});
|
|
786
837
|
await bot.onFollowed(ctx, followWithWrongRecipient);
|
|
787
|
-
assert.deepStrictEqual(await repository.countFollowers(), 0);
|
|
838
|
+
assert.deepStrictEqual(await repository.countFollowers("bot"), 0);
|
|
788
839
|
});
|
|
789
840
|
await t.test("with correct follow", async () => {
|
|
790
841
|
const follow = new Follow({
|
|
@@ -794,9 +845,9 @@ for (const policy of [
|
|
|
794
845
|
});
|
|
795
846
|
await bot.onFollowed(ctx, follow);
|
|
796
847
|
if (policy === "accept") {
|
|
797
|
-
assert.deepStrictEqual(await repository.countFollowers(), 1);
|
|
798
|
-
assert.ok(await repository.hasFollower(new URL("https://example.com/ap/actor/john")));
|
|
799
|
-
const [storedFollower] = await Array.fromAsync(repository.getFollowers());
|
|
848
|
+
assert.deepStrictEqual(await repository.countFollowers("bot"), 1);
|
|
849
|
+
assert.ok(await repository.hasFollower("bot", new URL("https://example.com/ap/actor/john")));
|
|
850
|
+
const [storedFollower] = await Array.fromAsync(repository.getFollowers("bot"));
|
|
800
851
|
assert.ok(storedFollower instanceof Person);
|
|
801
852
|
assert.deepStrictEqual(storedFollower.id, actor.id);
|
|
802
853
|
assert.deepStrictEqual(ctx.sentActivities.length, 1);
|
|
@@ -809,7 +860,7 @@ for (const policy of [
|
|
|
809
860
|
assert.deepStrictEqual(ctx.forwardedRecipients, []);
|
|
810
861
|
assert.deepStrictEqual(followRequests.length, 1);
|
|
811
862
|
} else {
|
|
812
|
-
assert.deepStrictEqual(await repository.countFollowers(), 0);
|
|
863
|
+
assert.deepStrictEqual(await repository.countFollowers("bot"), 0);
|
|
813
864
|
if (policy === "reject") {
|
|
814
865
|
assert.deepStrictEqual(ctx.sentActivities.length, 1);
|
|
815
866
|
const { activity, recipients } = ctx.sentActivities[0];
|
|
@@ -838,13 +889,13 @@ test("BotImpl.onUnfollowed()", async (t) => {
|
|
|
838
889
|
const unfollowed = [];
|
|
839
890
|
bot.onUnfollow = (session, actor) => void unfollowed.push([session, actor]);
|
|
840
891
|
const ctx = createMockInboxContext(bot, "https://example.com", "bot");
|
|
841
|
-
await repository.addFollower(new URL("https://example.com/ap/actor/john/follows/bot"), new Person({
|
|
892
|
+
await repository.addFollower("bot", new URL("https://example.com/ap/actor/john/follows/bot"), new Person({
|
|
842
893
|
id: new URL("https://example.com/ap/actor/john"),
|
|
843
894
|
preferredUsername: "john"
|
|
844
895
|
}));
|
|
845
896
|
async function assertNoEffect() {
|
|
846
|
-
assert.deepStrictEqual(await repository.countFollowers(), 1);
|
|
847
|
-
const [follower] = await Array.fromAsync(repository.getFollowers());
|
|
897
|
+
assert.deepStrictEqual(await repository.countFollowers("bot"), 1);
|
|
898
|
+
const [follower] = await Array.fromAsync(repository.getFollowers("bot"));
|
|
848
899
|
assert.ok(follower instanceof Person);
|
|
849
900
|
assert.deepStrictEqual(follower.id, new URL("https://example.com/ap/actor/john"));
|
|
850
901
|
assert.deepStrictEqual(follower.preferredUsername, "john");
|
|
@@ -890,7 +941,7 @@ test("BotImpl.onUnfollowed()", async (t) => {
|
|
|
890
941
|
object: new Follow({ id: new URL("https://example.com/ap/actor/john/follows/bot") })
|
|
891
942
|
});
|
|
892
943
|
await bot.onUnfollowed(ctx, undo);
|
|
893
|
-
assert.deepStrictEqual(await repository.countFollowers(), 0);
|
|
944
|
+
assert.deepStrictEqual(await repository.countFollowers("bot"), 0);
|
|
894
945
|
assert.deepStrictEqual(ctx.sentActivities, []);
|
|
895
946
|
assert.deepStrictEqual(ctx.forwardedRecipients, []);
|
|
896
947
|
assert.deepStrictEqual(unfollowed.length, 1);
|
|
@@ -930,7 +981,7 @@ test("BotImpl.onFollowAccepted()", async (t) => {
|
|
|
930
981
|
assert.deepStrictEqual(accepted, []);
|
|
931
982
|
});
|
|
932
983
|
await t.test("with non-actor", async () => {
|
|
933
|
-
await repository.addSentFollow("2ca58e2a-a34a-43e6-81af-c4f21ffed0c5", new Follow({
|
|
984
|
+
await repository.addSentFollow("bot", "2ca58e2a-a34a-43e6-81af-c4f21ffed0c5", new Follow({
|
|
934
985
|
id: new URL("https://example.com/ap/follow/2ca58e2a-a34a-43e6-81af-c4f21ffed0c5"),
|
|
935
986
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
936
987
|
object: new Note({})
|
|
@@ -942,7 +993,7 @@ test("BotImpl.onFollowAccepted()", async (t) => {
|
|
|
942
993
|
assert.deepStrictEqual(accepted, []);
|
|
943
994
|
});
|
|
944
995
|
await t.test("with actor without URI", async () => {
|
|
945
|
-
await repository.addSentFollow("a99ff3bf-72a2-412b-83b9-cba894d38805", new Follow({
|
|
996
|
+
await repository.addSentFollow("bot", "a99ff3bf-72a2-412b-83b9-cba894d38805", new Follow({
|
|
946
997
|
id: new URL("https://example.com/ap/follow/a99ff3bf-72a2-412b-83b9-cba894d38805"),
|
|
947
998
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
948
999
|
object: new Person({ preferredUsername: "john" })
|
|
@@ -954,7 +1005,7 @@ test("BotImpl.onFollowAccepted()", async (t) => {
|
|
|
954
1005
|
assert.deepStrictEqual(accepted, []);
|
|
955
1006
|
});
|
|
956
1007
|
await t.test("with actor", async () => {
|
|
957
|
-
await repository.addSentFollow("3bca0b8e-503a-47ea-ad69-6b7c29369fbd", new Follow({
|
|
1008
|
+
await repository.addSentFollow("bot", "3bca0b8e-503a-47ea-ad69-6b7c29369fbd", new Follow({
|
|
958
1009
|
id: new URL("https://example.com/ap/follow/3bca0b8e-503a-47ea-ad69-6b7c29369fbd"),
|
|
959
1010
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
960
1011
|
object: new Person({
|
|
@@ -972,7 +1023,7 @@ test("BotImpl.onFollowAccepted()", async (t) => {
|
|
|
972
1023
|
assert.deepStrictEqual(session.context, ctx);
|
|
973
1024
|
assert.ok(actor instanceof Person);
|
|
974
1025
|
assert.deepStrictEqual(actor.id, new URL("https://example.com/ap/actor/john"));
|
|
975
|
-
const follow = await repository.getFollowee(new URL("https://example.com/ap/actor/john"));
|
|
1026
|
+
const follow = await repository.getFollowee("bot", new URL("https://example.com/ap/actor/john"));
|
|
976
1027
|
assert.ok(follow != null);
|
|
977
1028
|
assert.ok(follow instanceof Follow);
|
|
978
1029
|
assert.deepStrictEqual(follow.id, new URL("https://example.com/ap/follow/3bca0b8e-503a-47ea-ad69-6b7c29369fbd"));
|
|
@@ -1008,7 +1059,7 @@ test("BotImpl.onFollowRejected()", async (t) => {
|
|
|
1008
1059
|
assert.deepStrictEqual(rejected, []);
|
|
1009
1060
|
});
|
|
1010
1061
|
await t.test("with non-actor", async () => {
|
|
1011
|
-
await repository.addSentFollow("2ca58e2a-a34a-43e6-81af-c4f21ffed0c5", new Follow({
|
|
1062
|
+
await repository.addSentFollow("bot", "2ca58e2a-a34a-43e6-81af-c4f21ffed0c5", new Follow({
|
|
1012
1063
|
id: new URL("https://example.com/ap/follow/2ca58e2a-a34a-43e6-81af-c4f21ffed0c5"),
|
|
1013
1064
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1014
1065
|
object: new Note({})
|
|
@@ -1020,7 +1071,7 @@ test("BotImpl.onFollowRejected()", async (t) => {
|
|
|
1020
1071
|
assert.deepStrictEqual(rejected, []);
|
|
1021
1072
|
});
|
|
1022
1073
|
await t.test("with actor without URI", async () => {
|
|
1023
|
-
await repository.addSentFollow("a99ff3bf-72a2-412b-83b9-cba894d38805", new Follow({
|
|
1074
|
+
await repository.addSentFollow("bot", "a99ff3bf-72a2-412b-83b9-cba894d38805", new Follow({
|
|
1024
1075
|
id: new URL("https://example.com/ap/follow/a99ff3bf-72a2-412b-83b9-cba894d38805"),
|
|
1025
1076
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1026
1077
|
object: new Person({ preferredUsername: "john" })
|
|
@@ -1032,7 +1083,7 @@ test("BotImpl.onFollowRejected()", async (t) => {
|
|
|
1032
1083
|
assert.deepStrictEqual(rejected, []);
|
|
1033
1084
|
});
|
|
1034
1085
|
await t.test("with actor", async () => {
|
|
1035
|
-
await repository.addSentFollow("3bca0b8e-503a-47ea-ad69-6b7c29369fbd", new Follow({
|
|
1086
|
+
await repository.addSentFollow("bot", "3bca0b8e-503a-47ea-ad69-6b7c29369fbd", new Follow({
|
|
1036
1087
|
id: new URL("https://example.com/ap/follow/3bca0b8e-503a-47ea-ad69-6b7c29369fbd"),
|
|
1037
1088
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1038
1089
|
object: new Person({
|
|
@@ -1050,7 +1101,7 @@ test("BotImpl.onFollowRejected()", async (t) => {
|
|
|
1050
1101
|
assert.deepStrictEqual(session.context, ctx);
|
|
1051
1102
|
assert.ok(actor instanceof Person);
|
|
1052
1103
|
assert.deepStrictEqual(actor.id, new URL("https://example.com/ap/actor/john"));
|
|
1053
|
-
assert.deepStrictEqual(await repository.getSentFollow("3bca0b8e-503a-47ea-ad69-6b7c29369fbd"), void 0);
|
|
1104
|
+
assert.deepStrictEqual(await repository.getSentFollow("bot", "3bca0b8e-503a-47ea-ad69-6b7c29369fbd"), void 0);
|
|
1054
1105
|
});
|
|
1055
1106
|
});
|
|
1056
1107
|
test("BotImpl.onCreated()", async (t) => {
|
|
@@ -1088,7 +1139,7 @@ test("BotImpl.onCreated()", async (t) => {
|
|
|
1088
1139
|
assert.deepStrictEqual(ctx.sentActivities, []);
|
|
1089
1140
|
assert.deepStrictEqual(ctx.forwardedRecipients, []);
|
|
1090
1141
|
});
|
|
1091
|
-
await repository.addMessage("a6358f1b-c978-49d3-8065-37a1df6168de", new Create({
|
|
1142
|
+
await repository.addMessage("bot", "a6358f1b-c978-49d3-8065-37a1df6168de", new Create({
|
|
1092
1143
|
id: new URL("https://example.com/ap/create/a6358f1b-c978-49d3-8065-37a1df6168de"),
|
|
1093
1144
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1094
1145
|
to: PUBLIC_COLLECTION,
|
|
@@ -1257,7 +1308,7 @@ test("BotImpl.onAnnounced()", async () => {
|
|
|
1257
1308
|
to: PUBLIC_COLLECTION,
|
|
1258
1309
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
1259
1310
|
object: new Note({
|
|
1260
|
-
id: new URL("https://example.com/
|
|
1311
|
+
id: new URL("https://example.com/notes/1"),
|
|
1261
1312
|
attribution: new URL("https://example.com/ap/actor/bot"),
|
|
1262
1313
|
to: PUBLIC_COLLECTION,
|
|
1263
1314
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
@@ -1289,7 +1340,7 @@ test("BotImpl.onLiked()", async () => {
|
|
|
1289
1340
|
id: new URL("https://example.com/ap/actor/bot/like/1"),
|
|
1290
1341
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1291
1342
|
object: new Note({
|
|
1292
|
-
id: new URL("https://example.com/
|
|
1343
|
+
id: new URL("https://example.com/notes/1"),
|
|
1293
1344
|
attribution: new URL("https://example.com/ap/actor/bot"),
|
|
1294
1345
|
to: PUBLIC_COLLECTION,
|
|
1295
1346
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
@@ -1320,7 +1371,7 @@ test("BotImpl.onUnliked()", async () => {
|
|
|
1320
1371
|
id: new URL("https://example.com/ap/actor/bot/like/1"),
|
|
1321
1372
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1322
1373
|
object: new Note({
|
|
1323
|
-
id: new URL("https://example.com/
|
|
1374
|
+
id: new URL("https://example.com/notes/1"),
|
|
1324
1375
|
attribution: new URL("https://example.com/ap/actor/bot"),
|
|
1325
1376
|
to: PUBLIC_COLLECTION,
|
|
1326
1377
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
@@ -1361,7 +1412,7 @@ test("BotImpl.onReacted()", async () => {
|
|
|
1361
1412
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1362
1413
|
name: ":heart:",
|
|
1363
1414
|
object: new Note({
|
|
1364
|
-
id: new URL("https://example.com/
|
|
1415
|
+
id: new URL("https://example.com/notes/1"),
|
|
1365
1416
|
attribution: new URL("https://example.com/ap/actor/bot"),
|
|
1366
1417
|
to: PUBLIC_COLLECTION,
|
|
1367
1418
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
@@ -1395,7 +1446,7 @@ test("BotImpl.onReacted()", async () => {
|
|
|
1395
1446
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1396
1447
|
name: ":thumbsup:",
|
|
1397
1448
|
object: new Note({
|
|
1398
|
-
id: new URL("https://example.com/
|
|
1449
|
+
id: new URL("https://example.com/notes/1"),
|
|
1399
1450
|
attribution: new URL("https://example.com/ap/actor/bot"),
|
|
1400
1451
|
to: PUBLIC_COLLECTION,
|
|
1401
1452
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
@@ -1437,7 +1488,7 @@ test("BotImpl.onUnreacted()", async () => {
|
|
|
1437
1488
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1438
1489
|
name: ":heart:",
|
|
1439
1490
|
object: new Note({
|
|
1440
|
-
id: new URL("https://example.com/
|
|
1491
|
+
id: new URL("https://example.com/notes/1"),
|
|
1441
1492
|
attribution: new URL("https://example.com/ap/actor/bot"),
|
|
1442
1493
|
to: PUBLIC_COLLECTION,
|
|
1443
1494
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
@@ -1476,7 +1527,7 @@ test("BotImpl.onUnreacted()", async () => {
|
|
|
1476
1527
|
actor: new URL("https://example.com/ap/actor/bot"),
|
|
1477
1528
|
name: ":thumbsup:",
|
|
1478
1529
|
object: new Note({
|
|
1479
|
-
id: new URL("https://example.com/
|
|
1530
|
+
id: new URL("https://example.com/notes/1"),
|
|
1480
1531
|
attribution: new URL("https://example.com/ap/actor/bot"),
|
|
1481
1532
|
to: PUBLIC_COLLECTION,
|
|
1482
1533
|
cc: new URL("https://example.com/ap/actor/bot/followers"),
|
|
@@ -1582,12 +1633,12 @@ test("BotImpl.fetch() includes FEP-5711 inverse properties", async () => {
|
|
|
1582
1633
|
collectionWindow: 1
|
|
1583
1634
|
});
|
|
1584
1635
|
const actorId = new URL("https://example.com/ap/actor/bot");
|
|
1585
|
-
await repository.addFollower(new URL("https://example.com/actor/1#follow"), new Person({
|
|
1636
|
+
await repository.addFollower("bot", new URL("https://example.com/actor/1#follow"), new Person({
|
|
1586
1637
|
id: new URL("https://example.com/actor/1"),
|
|
1587
1638
|
preferredUsername: "john",
|
|
1588
1639
|
inbox: new URL("https://example.com/actor/1/inbox")
|
|
1589
1640
|
}));
|
|
1590
|
-
await repository.addMessage("78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
1641
|
+
await repository.addMessage("bot", "78acb1ea-4ac6-46b7-bcd4-3a8965d8126e", new Create({
|
|
1591
1642
|
id: new URL("https://example.com/ap/actor/bot/create/78acb1ea-4ac6-46b7-bcd4-3a8965d8126e"),
|
|
1592
1643
|
actor: actorId,
|
|
1593
1644
|
to: PUBLIC_COLLECTION,
|
|
@@ -1815,7 +1866,7 @@ test("BotImpl.onVote()", async (t) => {
|
|
|
1815
1866
|
}),
|
|
1816
1867
|
published: Temporal.Now.instant()
|
|
1817
1868
|
});
|
|
1818
|
-
await repository.addMessage(pollId, poll);
|
|
1869
|
+
await repository.addMessage("bot", pollId, poll);
|
|
1819
1870
|
const voter = new Person({
|
|
1820
1871
|
id: new URL("https://hollo.social/@alice"),
|
|
1821
1872
|
preferredUsername: "alice"
|
|
@@ -1858,7 +1909,7 @@ test("BotImpl.onVote()", async (t) => {
|
|
|
1858
1909
|
assert.ok(updateActivity != null, "Update activity should be found");
|
|
1859
1910
|
assert.ok(updateActivity.activity instanceof Update);
|
|
1860
1911
|
assert.deepStrictEqual(updateActivity.activity.objectId, poll.id);
|
|
1861
|
-
const updatedPoll = await repository.getMessage(pollId);
|
|
1912
|
+
const updatedPoll = await repository.getMessage("bot", pollId);
|
|
1862
1913
|
assert.ok(updatedPoll instanceof Create);
|
|
1863
1914
|
const updatedQuestion = await updatedPoll.getObject(ctx);
|
|
1864
1915
|
assert.ok(updatedQuestion instanceof Question);
|
|
@@ -1901,7 +1952,7 @@ test("BotImpl.onVote()", async (t) => {
|
|
|
1901
1952
|
}),
|
|
1902
1953
|
published: Temporal.Now.instant()
|
|
1903
1954
|
});
|
|
1904
|
-
await repository.addMessage(multiPollId, multiPoll);
|
|
1955
|
+
await repository.addMessage("bot", multiPollId, multiPoll);
|
|
1905
1956
|
ctx.sentActivities = [];
|
|
1906
1957
|
ctx.forwardedRecipients = [];
|
|
1907
1958
|
receivedVote = null;
|
|
@@ -1978,7 +2029,7 @@ test("BotImpl.onVote()", async (t) => {
|
|
|
1978
2029
|
}),
|
|
1979
2030
|
published: Temporal.Now.instant()
|
|
1980
2031
|
});
|
|
1981
|
-
await repository.addMessage(expiredPollId, expiredPoll);
|
|
2032
|
+
await repository.addMessage("bot", expiredPollId, expiredPoll);
|
|
1982
2033
|
ctx.sentActivities = [];
|
|
1983
2034
|
ctx.forwardedRecipients = [];
|
|
1984
2035
|
receivedVote = null;
|
|
@@ -2021,6 +2072,93 @@ test("BotImpl.onVote()", async (t) => {
|
|
|
2021
2072
|
assert.deepStrictEqual(receivedVote, null, "onVote should not be called for invalid option");
|
|
2022
2073
|
});
|
|
2023
2074
|
});
|
|
2075
|
+
test("BotImpl.fetch() redirects legacy object URIs", async (t) => {
|
|
2076
|
+
const bot = new BotImpl({
|
|
2077
|
+
kv: new MemoryKvStore(),
|
|
2078
|
+
username: "bot"
|
|
2079
|
+
});
|
|
2080
|
+
await t.test("redirects GET requests", async () => {
|
|
2081
|
+
const response = await bot.fetch(new Request("https://example.com/ap/follow/2ca58e2a-a34a-43e6-81af-c4f21ffed0c5"), void 0);
|
|
2082
|
+
assert.deepStrictEqual(response.status, 301);
|
|
2083
|
+
assert.deepStrictEqual(response.headers.get("Location"), "https://example.com/ap/actor/bot/follow/2ca58e2a-a34a-43e6-81af-c4f21ffed0c5");
|
|
2084
|
+
});
|
|
2085
|
+
await t.test("redirects HEAD requests", async () => {
|
|
2086
|
+
const response = await bot.fetch(new Request("https://example.com/ap/note/123", { method: "HEAD" }), void 0);
|
|
2087
|
+
assert.deepStrictEqual(response.status, 301);
|
|
2088
|
+
assert.deepStrictEqual(response.headers.get("Location"), "https://example.com/ap/actor/bot/note/123");
|
|
2089
|
+
});
|
|
2090
|
+
await t.test("preserves the query string", async () => {
|
|
2091
|
+
const response = await bot.fetch(new Request("https://example.com/ap/note/123?foo=bar"), void 0);
|
|
2092
|
+
assert.deepStrictEqual(response.status, 301);
|
|
2093
|
+
assert.deepStrictEqual(response.headers.get("Location"), "https://example.com/ap/actor/bot/note/123?foo=bar");
|
|
2094
|
+
});
|
|
2095
|
+
await t.test("does not redirect POST requests", async () => {
|
|
2096
|
+
const response = await bot.fetch(new Request("https://example.com/ap/note/123", { method: "POST" }), void 0);
|
|
2097
|
+
assert.notDeepStrictEqual(response.status, 301);
|
|
2098
|
+
});
|
|
2099
|
+
await t.test("does not redirect canonical or unrelated paths", async () => {
|
|
2100
|
+
const canonical = await bot.fetch(new Request("https://example.com/ap/actor/bot/note/123"), void 0);
|
|
2101
|
+
assert.notDeepStrictEqual(canonical.status, 301);
|
|
2102
|
+
const inbox = await bot.fetch(new Request("https://example.com/ap/inbox"), void 0);
|
|
2103
|
+
assert.notDeepStrictEqual(inbox.status, 301);
|
|
2104
|
+
});
|
|
2105
|
+
});
|
|
2106
|
+
test("BotImpl.onFollowAccepted() with canonical follow URIs", async () => {
|
|
2107
|
+
const repository = new MemoryRepository();
|
|
2108
|
+
const bot = new BotImpl({
|
|
2109
|
+
kv: new MemoryKvStore(),
|
|
2110
|
+
repository,
|
|
2111
|
+
username: "bot"
|
|
2112
|
+
});
|
|
2113
|
+
const accepted = [];
|
|
2114
|
+
bot.onAcceptFollow = (_, actor) => void accepted.push(actor);
|
|
2115
|
+
const ctx = createMockInboxContext(bot, "https://example.com", "bot");
|
|
2116
|
+
await repository.addSentFollow("bot", "9d952a10-77e6-46bd-a48a-208b47e5e2bb", new Follow({
|
|
2117
|
+
id: new URL("https://example.com/ap/actor/bot/follow/9d952a10-77e6-46bd-a48a-208b47e5e2bb"),
|
|
2118
|
+
actor: new URL("https://example.com/ap/actor/bot"),
|
|
2119
|
+
object: new Person({
|
|
2120
|
+
id: new URL("https://example.com/ap/actor/john"),
|
|
2121
|
+
preferredUsername: "john"
|
|
2122
|
+
})
|
|
2123
|
+
}));
|
|
2124
|
+
await bot.onFollowAccepted(ctx, new Accept({
|
|
2125
|
+
actor: new URL("https://example.com/ap/actor/john"),
|
|
2126
|
+
object: new URL("https://example.com/ap/actor/bot/follow/9d952a10-77e6-46bd-a48a-208b47e5e2bb")
|
|
2127
|
+
}));
|
|
2128
|
+
assert.deepStrictEqual(accepted.length, 1);
|
|
2129
|
+
assert.deepStrictEqual(accepted[0].id, new URL("https://example.com/ap/actor/john"));
|
|
2130
|
+
assert.ok(await repository.getFollowee("bot", new URL("https://example.com/ap/actor/john")) != null);
|
|
2131
|
+
});
|
|
2132
|
+
test("BotImpl.onLiked() with legacy message URIs", async () => {
|
|
2133
|
+
const repository = new MemoryRepository();
|
|
2134
|
+
const bot = new BotImpl({
|
|
2135
|
+
kv: new MemoryKvStore(),
|
|
2136
|
+
repository,
|
|
2137
|
+
username: "bot"
|
|
2138
|
+
});
|
|
2139
|
+
const likes = [];
|
|
2140
|
+
bot.onLike = (_, like) => void likes.push(like);
|
|
2141
|
+
const ctx = createMockInboxContext(bot, "https://example.com", "bot");
|
|
2142
|
+
const messageId = "01941f29-7c00-7fe8-ab0a-7b593990a3c0";
|
|
2143
|
+
await repository.addMessage("bot", messageId, new Create({
|
|
2144
|
+
id: new URL(`https://example.com/ap/actor/bot/create/${messageId}`),
|
|
2145
|
+
actor: new URL("https://example.com/ap/actor/bot"),
|
|
2146
|
+
to: PUBLIC_COLLECTION,
|
|
2147
|
+
object: new Note({
|
|
2148
|
+
id: new URL(`https://example.com/ap/actor/bot/note/${messageId}`),
|
|
2149
|
+
attribution: new URL("https://example.com/ap/actor/bot"),
|
|
2150
|
+
to: PUBLIC_COLLECTION,
|
|
2151
|
+
content: "Hello, world!"
|
|
2152
|
+
})
|
|
2153
|
+
}));
|
|
2154
|
+
await bot.onLiked(ctx, new Like({
|
|
2155
|
+
id: new URL("https://remote.example/likes/1"),
|
|
2156
|
+
actor: new URL("https://example.com/ap/actor/bot"),
|
|
2157
|
+
object: new URL(`https://example.com/ap/note/${messageId}`)
|
|
2158
|
+
}));
|
|
2159
|
+
assert.deepStrictEqual(likes.length, 1);
|
|
2160
|
+
assert.deepStrictEqual(likes[0].message.id, new URL(`https://example.com/ap/actor/bot/note/${messageId}`));
|
|
2161
|
+
});
|
|
2024
2162
|
|
|
2025
2163
|
//#endregion
|
|
2026
2164
|
//# sourceMappingURL=bot-impl.test.js.map
|