@@ -77,6 +77,21 @@ describe("TeamService", () => {
7777 expect ( foundTeam ! . owner . id ) . toEqual ( user . id ) ;
7878 } ) ;
7979
80+ it ( "clears the users team request" , async ( ) => {
81+ expect . assertions ( 1 ) ;
82+
83+ const team = await teamRepo . save ( makeTeam ( "Team 1" ) ) ;
84+
85+ const user = await userRepo . save ( {
86+ ...makeUser ( "member@test.com" ) ,
87+ teamRequest : team ,
88+ } ) ;
89+ await teamService . createTeam ( makeTeam ( ) , user ) ;
90+
91+ const updatedUser = await userRepo . findOne ( { where : { id : user . id } } ) ;
92+ expect ( updatedUser ! . teamRequest ) . toBeNull ( ) ;
93+ } ) ;
94+
8095 it ( "assigns the newly created team to the user" , async ( ) => {
8196 expect . assertions ( 1 ) ;
8297
@@ -106,7 +121,7 @@ describe("TeamService", () => {
106121 } ) ;
107122
108123 describe ( "acceptUserToTeam" , ( ) => {
109- it ( "throws when the requester is neither owner nor admin" , async ( ) => {
124+ it ( "throws when the accepting user is neither owner nor admin" , async ( ) => {
110125 expect . assertions ( 1 ) ;
111126
112127 const owner = await userRepo . save ( makeUser ( "owner@test.com" ) ) ;
@@ -126,6 +141,24 @@ describe("TeamService", () => {
126141 ) . rejects . toThrow ( "You are not the owner of this team" ) ;
127142 } ) ;
128143
144+ it ( "throws when the requester is owner of another team" , async ( ) => {
145+ expect . assertions ( 1 ) ;
146+
147+ const team1Owner = await userRepo . save ( makeUser ( "owner@test.com" ) ) ;
148+ const team1 = await teamService . createTeam ( makeTeam ( ) , team1Owner ) ;
149+
150+ const team2Owner = await userRepo . save ( makeUser ( "req@test.com" ) ) ;
151+ const team2 = await teamService . createTeam ( makeTeam ( ) , team2Owner ) ;
152+
153+ await userRepo . save ( { ...team2Owner , team : team2 , teamRequest : team1 } ) ;
154+
155+ await expect (
156+ teamService . acceptUserToTeam ( team1 . id , team2Owner . id , team1Owner ) ,
157+ ) . rejects . toThrow (
158+ "The user needs to select a new owner for their old team first" ,
159+ ) ;
160+ } ) ;
161+
129162 it ( "allows the team owner to accept a join request" , async ( ) => {
130163 expect . assertions ( 2 ) ;
131164
0 commit comments