diff --git a/src/oai-pmh-list.js b/src/oai-pmh-list.js index 163fbb0..a7e5dd5 100644 --- a/src/oai-pmh-list.js +++ b/src/oai-pmh-list.js @@ -29,7 +29,7 @@ export async function * getOaiListItems (oaiPmh, verb, field, options) { }) const initialParsedResponse = await parseOaiPmhXml(initialResponse.body) const initialResult = initialParsedResponse[verb] - for (const item of initialResult[field]) { + for (const item of [].concat(initialResult[field])) { yield item } @@ -45,7 +45,7 @@ export async function * getOaiListItems (oaiPmh, verb, field, options) { }) const parsedResponse = await parseOaiPmhXml(response.body) result = parsedResponse[verb] - for (const item of result[field]) { + for (const item of [].concat(result[field])) { yield item } } diff --git a/src/oai-pmh.test.js b/src/oai-pmh.test.js index ab6d543..4d4148f 100644 --- a/src/oai-pmh.test.js +++ b/src/oai-pmh.test.js @@ -189,5 +189,17 @@ describe('OaiPmh', () => { { setSpec: 'stat', setName: 'Statistics' } ]) }) + + it('should list arxiv sets single result', async () => { + const oaiPmh = new OaiPmh(arxivBaseUrl) + const res = [] + for await (const set of oaiPmh.listSets()) { + res.push(set) + } + res.should.containDeep([ + { setSpec: 'cs', setName: 'Computer Science' } + ]) + res.should.have.length(1) + }) }) }) diff --git a/test/nock-fixtures/oaipmh-listsets---should-list-arxiv-sets-single-result.json b/test/nock-fixtures/oaipmh-listsets---should-list-arxiv-sets-single-result.json new file mode 100644 index 0000000..dad40b4 --- /dev/null +++ b/test/nock-fixtures/oaipmh-listsets---should-list-arxiv-sets-single-result.json @@ -0,0 +1,24 @@ +[ + { + "scope": "http://export.arxiv.org:80", + "method": "GET", + "path": "/oai2?verb=ListSets", + "body": "", + "status": 200, + "response": "\n\n2018-06-21T14:31:06Z\nhttp://export.arxiv.org/oai2\n\n\n cs\n Computer Science\n\n\n\n", + "rawHeaders": [ + "Date", + "Thu, 21 Jun 2018 14:31:05 GMT", + "Server", + "Apache", + "Vary", + "Accept-Encoding,User-Agent", + "Connection", + "close", + "Transfer-Encoding", + "chunked", + "Content-Type", + "text/xml" + ] + } +] \ No newline at end of file