mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(database): ♻️ Move Notifications to their own ORM abstractions
This commit is contained in:
parent
14ace17ad4
commit
e732a3df03
16 changed files with 440 additions and 401 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { beforeEach, describe, expect, jest, mock, test } from "bun:test";
|
||||
import { SignatureValidator } from "@versia/federation";
|
||||
import type { Entity, Note as VersiaNote } from "@versia/federation/types";
|
||||
import { Note, Relationship, User, db } from "@versia/kit/db";
|
||||
import { Note, Notification, Relationship, User } from "@versia/kit/db";
|
||||
import type { Context } from "hono";
|
||||
import { ValidationError } from "zod-validation-error";
|
||||
import { config } from "~/packages/config-manager/index.ts";
|
||||
|
|
@ -34,6 +34,10 @@ mock.module("@versia/kit/db", () => ({
|
|||
Like: {
|
||||
fromSql: jest.fn(),
|
||||
},
|
||||
Notification: {
|
||||
fromSql: jest.fn(),
|
||||
insert: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
mock.module("@versia/federation", () => ({
|
||||
|
|
@ -235,6 +239,7 @@ describe("InboxProcessor", () => {
|
|||
Relationship.fromOwnerAndSubject = jest
|
||||
.fn()
|
||||
.mockResolvedValue(mockRelationship);
|
||||
Notification.insert = jest.fn();
|
||||
mockContext.text = jest.fn().mockReturnValue({ status: 200 });
|
||||
|
||||
// biome-ignore lint/complexity/useLiteralKeys: Private variable
|
||||
|
|
@ -249,7 +254,6 @@ describe("InboxProcessor", () => {
|
|||
notifying: true,
|
||||
languages: [],
|
||||
});
|
||||
expect(db.insert).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("returns 404 when author not found", async () => {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,15 @@ import type {
|
|||
Note as VersiaNote,
|
||||
User as VersiaUser,
|
||||
} from "@versia/federation/types";
|
||||
import { Instance, Like, Note, Relationship, User, db } from "@versia/kit/db";
|
||||
import { Likes, Notes, Notifications } from "@versia/kit/tables";
|
||||
import {
|
||||
Instance,
|
||||
Like,
|
||||
Note,
|
||||
Notification,
|
||||
Relationship,
|
||||
User,
|
||||
} from "@versia/kit/db";
|
||||
import { Likes, Notes } from "@versia/kit/tables";
|
||||
import type { SocketAddress } from "bun";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { Context, TypedResponse } from "hono";
|
||||
|
|
@ -312,7 +319,7 @@ export class InboxProcessor {
|
|||
languages: [],
|
||||
});
|
||||
|
||||
await db.insert(Notifications).values({
|
||||
await Notification.insert({
|
||||
accountId: author.id,
|
||||
type: followee.data.isLocked ? "follow_request" : "follow",
|
||||
notifiedId: followee.id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue