Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue when site returns single result #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
]
}
]