UNPKG

html-metadata

Version:

Scrapes metadata of several different standards

155 lines (135 loc) 6.67 kB
'use strict'; /** * Tests using parsing methods only */ const assert = require( './utils/assert.js' ); const meta = require( '../index' ); // mocha defines to avoid eslint breakage /* global describe, it */ describe( 'parsing', () => { it( 'should get correct structure from decoded string', () => { const title = 'ctx_ver=Z39.88-2004&rft_id=info%3Adoi%2Fhttp%3A%2F%2Fdx.doi.org%2F10.5555%2F12345678&rfr_id=info%3Asid%2Fcrossref.org%3Asearch&rft.atitle=Toward+a+Unified+Theory+of+High-Energy+Metaphysics%3A+Silly+String+Theory&rft.jtitle=Journal+of+Psychoceramics&rft.date=2008&rft.volume=5&rft.issue=11&rft.spage=1&rft.epage=3&rft.aufirst=Josiah&rft.aulast=Carberry&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&'; const expected = { ctx_ver: 'Z39.88-2004', rft_id: 'info:doi/http://dx.doi.org/10.5555/12345678', rfr_id: 'info:sid/crossref.org:search', rft_val_fmt: 'info:ofi/fmt:kev:mtx:journal', rft: { atitle: 'Toward a Unified Theory of High-Energy Metaphysics: Silly String Theory', jtitle: 'Journal of Psychoceramics', date: '2008', volume: '5', issue: '11', spage: '1', epage: '3', aufirst: 'Josiah', aulast: 'Carberry', genre: 'article' } }; return meta.parseCOinSTitle( title ).then( ( results ) => { assert.deepEqual( results, expected ); } ); } ); it( 'should get correct structure from html encoded string', () => { const title = 'ctx_ver=Z39.88-2004&rft_id=info%3Adoi%2Fhttp%3A%2F%2Fdx.doi.org%2F10.5555%2F12345678&rfr_id=info%3Asid%2Fcrossref.org%3Asearch&rft.atitle=Toward+a+Unified+Theory+of+High-Energy+Metaphysics%3A+Silly+String+Theory&rft.jtitle=Journal+of+Psychoceramics&rft.date=2008&rft.volume=5&rft.issue=11&rft.spage=1&rft.epage=3&rft.aufirst=Josiah&rft.aulast=Carberry&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&'; const expected = { ctx_ver: 'Z39.88-2004', rft_id: 'info:doi/http://dx.doi.org/10.5555/12345678', rfr_id: 'info:sid/crossref.org:search', rft_val_fmt: 'info:ofi/fmt:kev:mtx:journal', rft: { atitle: 'Toward a Unified Theory of High-Energy Metaphysics: Silly String Theory', jtitle: 'Journal of Psychoceramics', date: '2008', volume: '5', issue: '11', spage: '1', epage: '3', aufirst: 'Josiah', aulast: 'Carberry', genre: 'article' } }; return meta.parseCOinSTitle( title ).then( ( results ) => { assert.deepEqual( results, expected ); } ); } ); it( 'should not add rft object when there are no valid keys', () => { const title = 'ctx_ver=Z39.88-2004&rft_id=info%3Adoi%2Fhttp%3A%2F%2Fdx.doi.org%2F10.5555%2F12345678&rfr_id=info%3Asid%2Fcrossref.org%3Asearch&badkey.atitle=Toward+a+Unified+Theory+of+High-Energy+Metaphysics%3A+Silly+String+Theory&badkey.jtitle=Journal+of+Psychoceramics&badkey.date=2008&badkey.volume=5&badkey.issue=11&badkey.spage=1&badkey.epage=3&badkey.aufirst=Josiah&badkey.aulast=Carberry&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&badkey.genre=article&badkey.au=Josiah+Carberry'; const expected = { ctx_ver: 'Z39.88-2004', rft_id: 'info:doi/http://dx.doi.org/10.5555/12345678', rfr_id: 'info:sid/crossref.org:search', rft_val_fmt: 'info:ofi/fmt:kev:mtx:journal' }; return meta.parseCOinSTitle( title ).then( ( results ) => { assert.deepEqual( results, expected ); } ); } ); it( 'should not replace encoded + symbol in doi', () => { const title = 'ctx_ver=Z39.88-2004&rft_id=info%3Adoi%2Fhttp%3A%2F%2Fdx.doi.org%2F10.5555%2F12%2B345678&rfr_id=info%3Asid%2Fcrossref.org%3Asearch&badkey.atitle=Toward+a+Unified+Theory+of+High-Energy+Metaphysics%3A+Silly+String+Theory&badkey.jtitle=Journal+of+Psychoceramics&badkey.date=2008&badkey.volume=5&badkey.issue=11&badkey.spage=1&badkey.epage=3&badkey.aufirst=Josiah&badkey.aulast=Carberry&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&badkey.genre=article&badkey.au=Josiah+Carberry'; const expected = { ctx_ver: 'Z39.88-2004', rft_id: 'info:doi/http://dx.doi.org/10.5555/12+345678', rfr_id: 'info:sid/crossref.org:search', rft_val_fmt: 'info:ofi/fmt:kev:mtx:journal' }; return meta.parseCOinSTitle( title ).then( ( results ) => { assert.deepEqual( results, expected ); } ); } ); it( 'should add list for au field', () => { const title = 'ctx_ver=Z39.88-2004&rft_id=info%3Adoi%2Fhttp%3A%2F%2Fdx.doi.org%2F10.5555%2F12345678&rfr_id=info%3Asid%2Fcrossref.org%3Asearch&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&rft.au=Josiah+Carberry&rft.au=Random+Name&rft.au=Name+of+an+organisation'; const expected = { ctx_ver: 'Z39.88-2004', rft_id: 'info:doi/http://dx.doi.org/10.5555/12345678', rfr_id: 'info:sid/crossref.org:search', rft_val_fmt: 'info:ofi/fmt:kev:mtx:journal', rft: { genre: 'article', au: [ 'Josiah Carberry', 'Random Name', 'Name of an organisation' ] } }; return meta.parseCOinSTitle( title ).then( ( results ) => { assert.deepEqual( results, expected ); } ); } ); it( 'should add list for issn and aucorp field', () => { const title = 'rft.genre=article&rft.issn=1234-5678&rft.issn=2222-3333&rft.aucorp=Name+of+an+organisation'; const expected = { rft: { genre: 'article', aucorp: [ 'Name of an organisation' ], issn: [ '1234-5678', '2222-3333' ] } }; return meta.parseCOinSTitle( title ).then( ( results ) => { assert.deepEqual( results, expected ); } ); } ); it( 'should ignore bad hierarchical keys', () => { const title = 'ctx_ver=Z39.88-2004&rft_id=info%3Adoi%2Fhttp%3A%2F%2Fdx.doi.org%2F10.5555%2F12345678&rfr_id=info%3Asid%2Fcrossref.org%3Asearch&badkey.atitle=Toward+a+Unified+Theory+of+High-Energy+Metaphysics%3A+Silly+String+Theory&badkey.jtitle=Journal+of+Psychoceramics&badkey.date=2008&badkey.volume=5&badkey.issue=11&badkey.spage=1&badkey.epage=3&badkey.aufirst=Josiah&badkey.aulast=Carberry&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article&badkey.au=Josiah+Carberry'; const expected = { ctx_ver: 'Z39.88-2004', rft_id: 'info:doi/http://dx.doi.org/10.5555/12345678', rfr_id: 'info:sid/crossref.org:search', rft_val_fmt: 'info:ofi/fmt:kev:mtx:journal', rft: { genre: 'article' } }; return meta.parseCOinSTitle( title ).then( ( results ) => { assert.deepEqual( results, expected ); } ); } ); } );