Skip to content

Commit

Permalink
chore(tests): utilise un snapshot pour tester le résultat de la biblio
Browse files Browse the repository at this point in the history
Aussi, transforme le résultat en texte plutôt qu'en tableau. C'est plus cohérent avec le résultat attendu.
  • Loading branch information
thom4parisot committed Oct 10, 2024
1 parent bacae48 commit b370e2c
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 9 deletions.
2 changes: 1 addition & 1 deletion front/src/components/Write/bibliographe/ZoteroPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function ZoteroPanel ({ articleId, zoteroLink: initialZoteroLink,
setSaving(true)
try {
const result = await fetchBibliographyFromCollectionHref({ token, collectionHref })
onChange(result.join('\n'))
onChange(result)
} catch (err) {
console.error(`Something went wrong while fetching bibliography from Zotero: ${collectionHref}`, err)
} finally {
Expand Down
129 changes: 129 additions & 0 deletions front/src/helpers/__snapshots__/zotero/group-collection.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@

@book{grossetie_test1_nodate,
title = {test1},
publisher = {Moi},
author = {Grossetie, Guillaume},
}

@misc{grossetie_hello_nodate,
title = {Hello},
shorttitle = {Hi},
author = {Grossetie, Guillaume},
}

@misc{grossetie_test_nodate,
type = {yuzutech.fr},
title = {test},
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},
}
4 changes: 2 additions & 2 deletions front/src/helpers/zotero.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export async function fetchUserCollections ({ userID, key }) {
/**
* @param collectionHref
* @param key Zotero API key
* @returns {Promise<string[]>}
* @returns {Promise<string>}
*/
export const fetchBibliographyFromCollectionHref = async ({ collectionHref, token: key = null, }) => {
return fetchAllBibTeX(new URL(collectionHref + '/items'), key)
return (await fetchAllBibTeX(new URL(collectionHref + '/items'), key)).join('\n')
}
10 changes: 4 additions & 6 deletions front/src/helpers/zotero.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { describe, test, expect } from 'vitest'
import { fetchBibliographyFromCollectionHref } from './zotero'

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

return fetchBibliographyFromCollectionHref({
const bib = await fetchBibliographyFromCollectionHref({
collectionHref: `https://api.zotero.org/groups/${zoteroId}`,
}).then((bib) => {
expect(bib[0]).toMatch('@misc{grossetie_hello_nodate')
expect(bib[0]).not.toMatch('@book{grossetie_hello_nodate')
expect(bib[1]).toMatch('@book{noauthor_test10_nodate')
})

return expect(bib).toMatchFileSnapshot('__snapshots__/zotero/group-collection.bib')
})
})

0 comments on commit b370e2c

Please sign in to comment.