Skip to content

Commit

Permalink
fix issue when site returns single result
Browse files Browse the repository at this point in the history
	Fixes #28
  • Loading branch information
VirtueMe committed Mar 4, 2020
1 parent f37a009 commit bb7229d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/oai-pmh-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/oai-pmh.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"scope": "http://export.arxiv.org:80",
"method": "GET",
"path": "/oai2?verb=ListSets",
"body": "",
"status": 200,
"response": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">\n<responseDate>2018-06-21T14:31:06Z</responseDate>\n<request verb=\"ListSets\">http://export.arxiv.org/oai2</request>\n<ListSets>\n<set>\n <setSpec>cs</setSpec>\n <setName>Computer Science</setName>\n</set>\n</ListSets>\n</OAI-PMH>\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"
]
}
]

0 comments on commit bb7229d

Please sign in to comment.