mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 22:09:16 +01:00
feat(federation): ✨ Implement Share federation support
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 0s
Build Docker Images / lint (push) Failing after 6s
Build Docker Images / check (push) Failing after 7s
Build Docker Images / tests (push) Failing after 6s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / build (push) Failing after 0s
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 0s
Nix Build / check (push) Failing after 0s
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 0s
Build Docker Images / lint (push) Failing after 6s
Build Docker Images / check (push) Failing after 7s
Build Docker Images / tests (push) Failing after 6s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / build (push) Failing after 0s
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 0s
Nix Build / check (push) Failing after 0s
This commit is contained in:
parent
ec69fc2ac0
commit
cd12ccd6c1
12 changed files with 533 additions and 85 deletions
|
|
@ -6,7 +6,7 @@ import {
|
|||
enableRealRequests,
|
||||
mock,
|
||||
} from "bun-bagel";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { Instance } from "~/classes/database/instance";
|
||||
import { Note } from "~/classes/database/note";
|
||||
import { User } from "~/classes/database/user";
|
||||
|
|
@ -19,6 +19,7 @@ import { fakeRequest } from "~/tests/utils";
|
|||
const instanceUrl = new URL("https://versia.example.com");
|
||||
const noteId = randomUUIDv7();
|
||||
const userId = randomUUIDv7();
|
||||
const shareId = randomUUIDv7();
|
||||
const userKeys = await User.generateKeys();
|
||||
const privateKey = await crypto.subtle.importKey(
|
||||
"pkcs8",
|
||||
|
|
@ -167,4 +168,57 @@ describe("Inbox Tests", () => {
|
|||
|
||||
expect(note).not.toBeNull();
|
||||
});
|
||||
|
||||
test("should correctly process Share", async () => {
|
||||
const exampleRequest = new VersiaEntities.Share({
|
||||
id: shareId,
|
||||
created_at: "2025-04-18T10:32:01.427Z",
|
||||
uri: new URL(`/shares/${shareId}`, instanceUrl).href,
|
||||
type: "pub.versia:share/Share",
|
||||
author: new URL(`/users/${userId}`, instanceUrl).href,
|
||||
shared: new URL(`/notes/${noteId}`, instanceUrl).href,
|
||||
});
|
||||
|
||||
const signedRequest = await sign(
|
||||
privateKey,
|
||||
new URL(exampleRequest.data.author),
|
||||
new Request(inboxUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"User-Agent": "Versia/1.0.0",
|
||||
},
|
||||
body: JSON.stringify(exampleRequest.toJSON()),
|
||||
}),
|
||||
);
|
||||
|
||||
const response = await fakeRequest(inboxUrl, {
|
||||
method: "POST",
|
||||
headers: signedRequest.headers,
|
||||
body: signedRequest.body,
|
||||
});
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const dbNote = await Note.fromSql(
|
||||
eq(Notes.uri, new URL(`/notes/${noteId}`, instanceUrl).href),
|
||||
);
|
||||
|
||||
if (!dbNote) {
|
||||
throw new Error("DBNote not found");
|
||||
}
|
||||
|
||||
// Check if share was created in the database
|
||||
const share = await Note.fromSql(
|
||||
and(
|
||||
eq(Notes.reblogId, dbNote.id),
|
||||
eq(Notes.authorId, dbNote.data.authorId),
|
||||
),
|
||||
);
|
||||
|
||||
expect(share).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue