don't add new friend requests to inbox

This commit is contained in:
Christian Fehmer 2025-07-02 11:39:31 +02:00
parent fdbc26cdc9
commit f1e38226fe
No known key found for this signature in database
GPG key ID: FE53784A69964062
2 changed files with 6 additions and 35 deletions

View file

@ -58,13 +58,11 @@ describe("FriendsController", () => {
getFriendsMock.mockResolvedValue([]);
//WHEN
const { body } = await mockApp
await mockApp
.get("/friends/requests")
.query({ status: "accepted" })
.set("Authorization", `Bearer ${uid}`);
//.expect(200);
console.log(body);
.set("Authorization", `Bearer ${uid}`)
.expect(200);
//THEN
expect(getFriendsMock).toHaveBeenCalledWith(uid, ["accepted"]);
@ -109,16 +107,12 @@ describe("FriendsController", () => {
describe("create friend request", () => {
const getUserByNameMock = vi.spyOn(UserDal, "getUserByName");
const getPartialUserMock = vi.spyOn(UserDal, "getPartialUser");
const addToInboxMock = vi.spyOn(UserDal, "addToInbox");
const createUserMock = vi.spyOn(FriendsDal, "create");
beforeEach(() => {
[
getUserByNameMock,
getPartialUserMock,
addToInboxMock,
createUserMock,
].forEach((it) => it.mockReset());
[getUserByNameMock, getPartialUserMock, createUserMock].forEach((it) =>
it.mockReset()
);
});
it("should create", async () => {
@ -164,16 +158,6 @@ describe("FriendsController", () => {
"name",
]);
expect(createUserMock).toHaveBeenCalledWith(me, myFriend, 100);
expect(addToInboxMock).toBeCalledWith(
myFriend.uid,
[
expect.objectContaining({
body: "Bob wants to be your friend. You can accept/deny this request in [FRIEND_SETTINGS]",
subject: "Friend request",
}),
],
expect.anything()
);
});
it("should fail if user and friend are the same", async () => {

View file

@ -8,12 +8,10 @@ import {
} from "@monkeytype/contracts/friends";
import { MonkeyRequest } from "../types";
import { MonkeyResponse } from "../../utils/monkey-response";
import * as FriendsDal from "../../dal/friends";
import * as UserDal from "../../dal/user";
import { replaceObjectId, replaceObjectIds } from "../../utils/misc";
import MonkeyError from "../../utils/error";
import { buildMonkeyMail } from "../../utils/monkey-mail";
import { omit } from "lodash";
import { FriendRequest } from "@monkeytype/contracts/schemas/friends";
@ -53,17 +51,6 @@ export async function createRequest(
"key"
);
//notify user
const mail = buildMonkeyMail({
subject: "Friend request",
body: `${initiator.name} wants to be your friend. You can accept/deny this request in [FRIEND_SETTINGS]`,
});
await UserDal.addToInbox(
friend.uid,
[mail],
req.ctx.configuration.users.inbox
);
return new MonkeyResponse("Friend created", result);
}