File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ export default eventHandler(async (event) => {
5858 createdAt : existingLink . createdAt ,
5959 updatedAt : Math . floor ( Date . now ( ) / 1000 ) ,
6060 }
61+ if ( link . password === undefined ) {
62+ delete newLink . password
63+ }
6164 await putLink ( event , newLink )
6265 setResponseStatus ( event , 201 )
6366 const shortLink = buildShortLink ( event , newLink . slug )
Original file line number Diff line number Diff line change @@ -175,6 +175,22 @@ describe.sequential('/api/link/edit', () => {
175175 expect ( data ) . toHaveProperty ( 'shortLink' )
176176 } )
177177
178+ it ( 'removes password when not provided in edit' , async ( ) => {
179+ const slug = testLinkPayload . slug
180+
181+ // Set a password on the link
182+ const setPasswordResponse = await putJson ( '/api/link/edit' , { ...testLinkPayload , password : 'secret123' } )
183+ expect ( setPasswordResponse . status ) . toBe ( 201 )
184+ const setData = await setPasswordResponse . json ( ) as { link : { password ?: string } }
185+ expect ( setData . link . password ) . toBe ( 'secret123' )
186+
187+ // Edit the link without providing a password (user cleared the field)
188+ const removePasswordResponse = await putJson ( '/api/link/edit' , { url : testLinkPayload . url , slug } )
189+ expect ( removePasswordResponse . status ) . toBe ( 201 )
190+ const removeData = await removePasswordResponse . json ( ) as { link : { password ?: string } }
191+ expect ( removeData . link . password ) . toBeUndefined ( )
192+ } )
193+
178194 it ( 'returns 404 when editing non-existent link' , async ( ) => {
179195 const payload = { url : 'https://example.com' , slug : 'non-existent-slug-for-edit-12345' }
180196 const response = await putJson ( '/api/link/edit' , payload )
You can’t perform that action at this time.
0 commit comments