@@ -12,7 +12,7 @@ describe('Tags API', () => {
1212 { id : '1' , name : 'Tag1' } ,
1313 { id : '2' , name : 'Tag2' } ,
1414 ] ;
15- global . fetch = vi . fn ( ( ) =>
15+ globalThis . fetch = vi . fn ( ( ) =>
1616 Promise . resolve ( {
1717 ok : true ,
1818 json : ( ) => Promise . resolve ( mockResponse ) ,
@@ -23,7 +23,7 @@ describe('Tags API', () => {
2323 const result = await fetchTags ( searchString ) ;
2424
2525 expect ( result ) . toEqual ( mockResponse ) ;
26- expect ( global . fetch ) . toHaveBeenCalledWith ( './api/content/tags?search=Tag' , {
26+ expect ( globalThis . fetch ) . toHaveBeenCalledWith ( './api/content/tags?search=Tag' , {
2727 method : 'GET' ,
2828 cache : 'no-cache' ,
2929 headers : {
@@ -36,7 +36,7 @@ describe('Tags API', () => {
3636
3737 it ( 'should throw an error if fetch fails' , async ( ) => {
3838 const mockError = new Error ( 'Fetch failed' ) ;
39- global . fetch = vi . fn ( ( ) => Promise . reject ( mockError ) ) ;
39+ globalThis . fetch = vi . fn ( ( ) => Promise . reject ( mockError ) ) ;
4040
4141 const searchString = 'Tag' ;
4242
@@ -47,34 +47,37 @@ describe('Tags API', () => {
4747 describe ( 'deleteTag' , ( ) => {
4848 it ( 'should delete tag and return JSON response if successful' , async ( ) => {
4949 const mockResponse = { success : true , message : 'Tag deleted' } ;
50- global . fetch = vi . fn ( ( ) =>
50+ globalThis . fetch = vi . fn ( ( ) =>
5151 Promise . resolve ( {
5252 ok : true ,
5353 json : ( ) => Promise . resolve ( mockResponse ) ,
5454 } as Response )
5555 ) ;
5656
5757 const tagId = '1' ;
58- await deleteTag ( tagId ) ;
58+ const csrfToken = 'test-csrf' ;
59+ await deleteTag ( tagId , csrfToken ) ;
5960
60- expect ( global . fetch ) . toHaveBeenCalledWith ( './api/content/tags/1' , {
61+ expect ( globalThis . fetch ) . toHaveBeenCalledWith ( './api/content/tags/1' , {
6162 method : 'DELETE' ,
6263 cache : 'no-cache' ,
6364 headers : {
6465 'Content-Type' : 'application/json' ,
6566 } ,
67+ body : JSON . stringify ( { csrfToken : 'test-csrf' } ) ,
6668 redirect : 'follow' ,
6769 referrerPolicy : 'no-referrer' ,
6870 } ) ;
6971 } ) ;
7072
7173 it ( 'should throw an error if fetch fails' , async ( ) => {
7274 const mockError = new Error ( 'Fetch failed' ) ;
73- global . fetch = vi . fn ( ( ) => Promise . reject ( mockError ) ) ;
75+ globalThis . fetch = vi . fn ( ( ) => Promise . reject ( mockError ) ) ;
7476
7577 const tagId = '1' ;
78+ const csrfToken = 'test-csrf' ;
7679
77- await expect ( deleteTag ( tagId ) ) . rejects . toThrow ( mockError ) ;
80+ await expect ( deleteTag ( tagId , csrfToken ) ) . rejects . toThrow ( mockError ) ;
7881 } ) ;
7982 } ) ;
8083} ) ;
0 commit comments