Skip to content

Commit

Permalink
test: mock les réponses à l'API Zotero
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot committed Oct 21, 2024
1 parent b4c0d71 commit 76d41cc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 112 deletions.
110 changes: 0 additions & 110 deletions front/src/helpers/__snapshots__/zotero/group-collection.bib
Original file line number Diff line number Diff line change
Expand Up @@ -17,113 +17,3 @@ @misc{grossetie_test_nodate
journal = {How to},
author = {GROSSETIE, guillaume},
}

@unpublished{noauthor_notitle_nodate,
}

@misc{noauthor_notitle_nodate-1,
}

@misc{noauthor_notitle_nodate-2,
}

@book{noauthor_test19_nodate,
title = {test19},
}

@book{noauthor_test26_nodate,
title = {test26},
}

@book{noauthor_test25_nodate,
title = {test25},
}

@book{noauthor_test24_nodate,
title = {test24},
}

@book{noauthor_test23_nodate,
title = {test23},
}

@book{noauthor_test22_nodate,
title = {test22},
}

@book{noauthor_test21_nodate,
title = {test21},
}

@book{noauthor_test20_nodate,
title = {test20},
}

@book{noauthor_test9_nodate,
title = {test9},
}

@book{noauthor_test8_nodate,
title = {test8},
}

@book{noauthor_test5_nodate,
title = {test5},
}

@book{noauthor_test7_nodate,
title = {test7},
}

@book{noauthor_test6_nodate,
title = {test6},
}

@book{noauthor_test4_nodate,
title = {test4},
}

@book{noauthor_test16_nodate,
title = {test16},
}

@book{noauthor_test15_nodate,
title = {test15},
}

@book{noauthor_test14_nodate,
title = {test14},
}

@book{noauthor_test12_nodate,
title = {test12},
}

@book{noauthor_test11_nodate,
title = {test11},
}


@book{noauthor_test3_nodate,
title = {test3},
}

@book{noauthor_test2_nodate,
title = {test2},
}

@book{noauthor_test18_nodate,
title = {test18},
}

@book{noauthor_test17_nodate,
title = {test17},
}

@book{noauthor_test13_nodate,
title = {test13},
}

@book{noauthor_test10_nodate,
title = {test10},
}
35 changes: 33 additions & 2 deletions front/src/helpers/zotero.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
import { describe, test, expect } from 'vitest'
import { describe, test, expect, vi } from 'vitest'
import { fetchBibliographyFromCollectionHref } from './zotero'

describe('fetchBibliographyFromCollection', () => {
fetch
.mockResolvedValueOnce({
headers: new Headers({ Link: '<https://api.zotero.org/page/2>; rel="next"' }),
text: vi.fn().mockResolvedValue(`
@book{grossetie_test1_nodate,
title = {test1},
publisher = {Moi},
author = {Grossetie, Guillaume},
}
@misc{grossetie_hello_nodate,
title = {Hello},
shorttitle = {Hi},
author = {Grossetie, Guillaume},
}`)
})
.mockResolvedValueOnce({
headers: new Headers({ Link: '<https://api.zotero.org/page/3>; rel="next"' }),
text: vi.fn().mockResolvedValue('')
})
.mockResolvedValueOnce({
headers:new Headers({}),
text: vi.fn().mockResolvedValue(`
@misc{grossetie_test_nodate,
type = {yuzutech.fr},
title = {test},
journal = {How to},
author = {GROSSETIE, guillaume},
}`)
})


test('fetches a paginated collection of more than 25 elements', async () => {
const zoteroId = '2478772/collections/UGF4W4PZ'

const bib = await fetchBibliographyFromCollectionHref({
collectionHref: `https://api.zotero.org/groups/${zoteroId}`,
})
Expand Down
3 changes: 3 additions & 0 deletions front/tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import '@testing-library/jest-dom/vitest'

vi.mock('react-router-dom')

// mock Fetch requests
globalThis.fetch = vi.fn()

afterEach(() => cleanup())

0 comments on commit 76d41cc

Please sign in to comment.