mirror of
				https://github.com/monkeytypegame/monkeytype.git
				synced 2025-11-01 03:39:15 +08:00 
			
		
		
		
	don't add new friend requests to inbox
This commit is contained in:
		
							parent
							
								
									fdbc26cdc9
								
							
						
					
					
						commit
						f1e38226fe
					
				
					 2 changed files with 6 additions and 35 deletions
				
			
		|  | @ -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 () => { | ||||
|  |  | |||
|  | @ -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); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue