From 85811a57ec0a097b9bb22b36a9614dfdb367381c Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 13 Sep 2024 15:15:56 -0400 Subject: [PATCH] clean up --- lib/resources.js | 2 -- lib/response_massager.js | 2 +- test/resources-responses.test.js | 4 ++-- test/util.test.js | 11 +++++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/resources.js b/lib/resources.js index 55c41136..d83de401 100644 --- a/lib/resources.js +++ b/lib/resources.js @@ -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) { diff --git a/lib/response_massager.js b/lib/response_massager.js index e57d2933..e7a3019e 100644 --- a/lib/response_massager.js +++ b/lib/response_massager.js @@ -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') && diff --git a/test/resources-responses.test.js b/test/resources-responses.test.js index 6655079b..f54ef2d4 100644 --- a/test/resources-responses.test.js +++ b/test/resources-responses.test.js @@ -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 @@ -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() diff --git a/test/util.test.js b/test/util.test.js index 9732f572..bfdb244c 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -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 () {