Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Sep 13, 2024
1 parent 9dce2e5 commit 85811a5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ module.exports = function (app, _private = null) {
return app.esClient.search(body)
.then((resp) => {
resp = resp.body
const fs = require('fs')
fs.writeFileSync('spaghetti.txt', JSON.stringify(resp))

// Mindfully throw errors for known issues:
if (!resp || !resp.hits) {
Expand Down
2 changes: 1 addition & 1 deletion lib/response_massager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ResponseMassager {

massagedResponse (request, options = {}) {
let response = this.elasticSearchResponse
const queryKeys = Object.keys(request?.params || {})
const queryKeys = Object.keys(request?.query || {})
const itemFilterQuery = queryKeys
.filter((param) => param.startsWith('item_')).length > 0
const returnAllItems = queryKeys?.includes('all_items') &&
Expand Down
4 changes: 2 additions & 2 deletions test/resources-responses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Test Resources responses', function () {
done()
})
})
it.only('returns bib with items sorted by date', (done) => {
it('returns bib with items sorted by date', (done) => {
const url = global.TEST_BASE_URL + '/api/v0.1/discovery/resources/b10833141?all_items=true'
request.get(url, (err, res, body) => {
if (err) throw err
Expand All @@ -63,7 +63,7 @@ describe('Test Resources responses', function () {
// are not returned from ES at the beginning of the items array, but
// should end up sorted there by the response massager.
expect(firstTenItems.every(isCheckinCardItem))
expect(doc.items[0].enumerationChronology[0]).to.equal('v. 97 (May 10-July 26, 2021)')
expect(doc.items[0].enumerationChronology[0]).to.equal('Vol. 100 No. 35 (Oct. 28, 2024)')
const lastIndex = doc.items.length - 1
expect(doc.items[lastIndex].enumerationChronology[0]).to.equal('Aug. 9-Oct. 25 (1930)')
done()
Expand Down
11 changes: 9 additions & 2 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ const util = require('../lib/util')

describe('Util', function () {
describe('sortOnPropWithUndefinedLast', () => {
it('sorts badly formatted dates last', () => {
it('sorts badly formatted enumerationChronologies that result in undefined enumerationChronology_sort last', () => {
const sortedItemEnums = mangledEnumerationChronologyItems
.sort(util.sortOnPropWithUndefinedLast('enumerationChronology_sort'))
.map((item) => item.enumerationChronology)
expect(sortedItemEnums).to.deep.equal()
expect(sortedItemEnums).to.deep.equal([
['Feb 7 2007 - Feb 13 2007'],
['Feb 8 2002 - Feb 14 2002'],
['Sept. 1-15, 1979'],
['Sept. 1-24, 1957'],
['Aug 1 216 - Aug 10 216'],
['Feb. 1-14, 19828']
])
})
})
describe('backslashes', function () {
Expand Down

0 comments on commit 85811a5

Please sign in to comment.