Skip to content

Commit 7feceb6

Browse files
authored
Merge pull request #640 from NYPL/main
main -> qa remove contributor from aggs
2 parents f35c983 + fd51149 commit 7feceb6

File tree

7 files changed

+144
-21
lines changed

7 files changed

+144
-21
lines changed

.github/workflows/test-and-deploy.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,33 @@ jobs:
1515
run: npm ci
1616
- name: Unit Tests
1717
run: npm test
18-
deploy-qa:
18+
integration-test-qa:
1919
permissions:
2020
id-token: write
2121
contents: read
2222
runs-on: ubuntu-latest
2323
needs: tests
2424
if: github.ref == 'refs/heads/qa'
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Set Node version
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version-file: '.nvmrc'
31+
- name: Install dependencies
32+
run: npm ci
33+
- name: Start service
34+
run: ENV=qa npm start &
35+
- name: Run tests
36+
run: npm run test-integration
37+
deploy-qa:
38+
permissions:
39+
id-token: write
40+
contents: read
41+
runs-on: ubuntu-latest
42+
needs:
43+
- tests
44+
if: github.ref == 'refs/heads/qa'
2545
steps:
2646
- name: Checkout repo
2747
uses: actions/checkout@v3
@@ -31,7 +51,6 @@ jobs:
3151
with:
3252
role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole
3353
aws-region: us-east-1
34-
3554
- name: Log in to ECR
3655
id: login-ecr
3756
uses: aws-actions/amazon-ecr-login@v1
@@ -60,7 +79,9 @@ jobs:
6079
id-token: write
6180
contents: read
6281
runs-on: ubuntu-latest
63-
needs: tests
82+
needs:
83+
- tests
84+
- inte
6485
if: github.ref == 'refs/heads/qa2'
6586
steps:
6687
- name: Checkout repo

lib/elasticsearch/config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ const AGGREGATIONS_SPEC = {
124124
buildingLocation: { terms: { field: 'buildingLocationIds' } },
125125
subjectLiteral: { terms: { field: 'subjectLiteral.raw' } },
126126
language: { terms: { field: 'language_packed' } },
127-
contributorLiteral: { terms: { field: 'contributorLiteral.raw' } },
128-
creatorLiteral: { terms: { field: 'creatorLiteral.raw' } },
129127
collection: { terms: { field: 'collectionIds' } }
130128
}
131129

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"scripts": {
3535
"test": "./node_modules/.bin/standard --env mocha && NODE_ENV=test ./node_modules/.bin/mocha test --exit",
36+
"test-integration": "./node_modules/.bin/mocha test/integration",
3637
"start": "node server.js",
3738
"deploy-development": "git checkout development && git pull origin development && eb deploy discovery-api-dev --profile nypl-sandbox",
3839
"deploy-qa": "git checkout qa && git pull origin qa && eb deploy discovery-api-qa --profile nypl-digital-dev",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require('dotenv').config('config/qa.env')
2+
const axios = require('axios')
3+
const { expectations, ptypes } = require('./delivery-locations-constants')
4+
5+
const checkLocationsForPtype = async (ptype) => {
6+
const problems = []
7+
const match = []
8+
await Promise.all(Object.values(expectations).map(async (expectation) => {
9+
const deliveryLocationsFromApi = await getDeliveryLocations(expectation.barcode, ptypes[ptype])
10+
let totalMatch = true
11+
const registerProblem = (problem) => {
12+
problems.push({ barcode: expectation.barcode, deliveryLocationsFromApi, ...problem })
13+
totalMatch = false
14+
}
15+
const checkForValue = (expectedValue, action) => {
16+
const includedValueIncluded = deliveryLocationsFromApi.some((label) => label.includes(expectedValue))
17+
const match = action === 'include' ? includedValueIncluded : !includedValueIncluded
18+
if (!match) {
19+
registerProblem({ [`expectedTo${action}`]: expectedValue })
20+
}
21+
}
22+
expectation[ptype].includes.forEach((expectedValue) => checkForValue(expectedValue, 'include'))
23+
expectation[ptype].excludes.forEach((expectedValue) => checkForValue(expectedValue, 'exclude'))
24+
if (totalMatch) match.push({ barcode: expectation.barcode, deliveryLocationsFromApi, expectedToInclude: expectation[ptype].includes, expectedToExclude: expectation[ptype].excludes })
25+
}))
26+
return { match, problems }
27+
}
28+
29+
const getDeliveryLocations = async (barcode, patronId) => {
30+
const { data: { itemListElement: deliveryLocationsPerRecord } } = await axios.get(`http://localhost:8082/api/v0.1/request/deliveryLocationsByBarcode?barcodes[]=${barcode}&patronId=${patronId}`)
31+
// per record
32+
return deliveryLocationsPerRecord[0]
33+
.deliveryLocation.map(loc => loc.prefLabel.toLowerCase())
34+
}
35+
36+
const theThing = async () => {
37+
const results = await Promise.all(Object.keys(ptypes).map((checkLocationsForPtype)))
38+
Object.keys(ptypes).forEach((ptype, i) => {
39+
const resultsForPtype = results[i]
40+
if (resultsForPtype.problems.length) {
41+
console.error(`Error with ${ptype} ptype delivery results, `, resultsForPtype.problems)
42+
} else console.log(`All delivery location checks for ${ptype} patron type successful`)
43+
})
44+
}
45+
46+
theThing()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const lpa = 'performing'
2+
const schomburg = 'schomburg'
3+
const sasb = 'schwarzman'
4+
const scholar = 'scholar'
5+
const ptypes = {
6+
scholar: '5427701',
7+
general: '67427431'
8+
}
9+
const expectations = {
10+
princeton: {
11+
barcode: '32101067443802',
12+
scholar: { includes: [lpa, schomburg, sasb, scholar], excludes: [] },
13+
general: { includes: [lpa, schomburg, sasb], excludes: [scholar] }
14+
},
15+
harvard: {
16+
barcode: '32044135801371',
17+
scholar: { includes: [lpa, schomburg, sasb, scholar], excludes: [] },
18+
general: { includes: [lpa, schomburg, sasb], excludes: [scholar] }
19+
},
20+
// // recap customer code MR only to LPA
21+
columbia: {
22+
barcode: 'MR75708230',
23+
scholar: { includes: [lpa], excludes: [scholar] },
24+
general: { includes: [lpa], excludes: [scholar] }
25+
},
26+
nyplOffsite: {
27+
barcode: '33433073236758',
28+
scholar: { includes: [lpa, schomburg, sasb, scholar], excludes: [] },
29+
general: { includes: [lpa, schomburg, sasb], excludes: [scholar] }
30+
},
31+
lpa: {
32+
barcode: '33433085319774',
33+
scholar: { includes: [lpa], excludes: [scholar, schomburg, sasb] },
34+
general: { includes: [lpa], excludes: [scholar, schomburg, sasb] }
35+
},
36+
schomburg: {
37+
barcode: '33433119354979',
38+
scholar: { includes: [schomburg], excludes: [scholar, sasb, lpa] },
39+
general: { includes: [schomburg], excludes: [scholar, sasb, lpa] }
40+
},
41+
// nyplM1: {
42+
// barcode: null,
43+
// scholar: { includes: [sasb], excludes: [scholar, lpa, schomburg] },
44+
// general: { includes: [sasb], excludes: [scholar, lpa, schomburg] }
45+
// },
46+
nyplM2: {
47+
barcode: '33333069027734',
48+
scholar: { includes: [sasb, scholar], excludes: [lpa, schomburg] },
49+
general: { includes: [sasb], excludes: [scholar, lpa, schomburg] }
50+
}
51+
}
52+
53+
module.exports = {
54+
expectations,
55+
ptypes
56+
}

test/resources.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe('Resources query', function () {
250250
q: 'toast',
251251
filters: {
252252
subjectLiteral: ['S1'],
253-
contributorLiteral: ['C1', 'C2']
253+
collection: ['C1', 'C2']
254254
}
255255
})
256256
const queries = resourcesPrivMethods.aggregationQueriesForParams(params)
@@ -260,27 +260,27 @@ describe('Resources query', function () {
260260
expect(Object.keys(queries[0].aggregations)).to.have.lengthOf(numAggregations - 2)
261261
expect(queries[0].query.bool.filter).to.be.a('array')
262262
// Expect the subjectLiteral filter:
263-
expect(queries[0].query.bool.filter[0].term['subjectLiteral.raw'] === 'S1')
264-
// .. And the contributorLiteral filters:
265-
expect(queries[0]).to.nested.include({ 'query.bool.filter[1].bool.should[0].bool.should[0].term.contributorLiteral\\.keywordLowercased': 'C1' })
266-
expect(queries[0]).to.nested.include({ 'query.bool.filter[1].bool.should[1].bool.should[0].term.contributorLiteral\\.keywordLowercased': 'C2' })
263+
expect(queries[0].query.bool.filter[1].term['subjectLiteral.raw'] === 'S1')
264+
// .. And the collection filters:
265+
expect(queries[0]).to.nested.include({ 'query.bool.filter[0].bool.should[0].term.collectionIds': 'C1' })
266+
expect(queries[0]).to.nested.include({ 'query.bool.filter[0].bool.should[1].term.collectionIds': 'C2' })
267267

268-
// Expect second aggregation for subjectLiteral:
268+
// Expect second aggregation for collection:
269269
expect(Object.keys(queries[1].aggregations)).to.have.lengthOf(1)
270-
expect(queries[1]).to.nested.include({ 'aggregations.subjectLiteral.terms.field': 'subjectLiteral.raw' })
271-
// Expect this agg to filter on the other active filter, contributorLiteral:
272-
expect(queries[1]).to.nested.include({ 'query.bool.filter[0].bool.should[0].bool.should[0].term.contributorLiteral\\.keywordLowercased': 'C1' })
273-
expect(queries[1]).to.nested.include({ 'query.bool.filter[0].bool.should[1].bool.should[0].term.contributorLiteral\\.keywordLowercased': 'C2' })
270+
expect(queries[1]).to.nested.include({ 'aggregations.collection.terms.field': 'collectionIds' })
271+
// Expect this agg to filter on the other active filter, subjectLiteral:
274272
expect(queries[1].query.bool.filter).to.have.lengthOf(1)
275-
expect(queries[1].query.bool.filter[0].bool.should).to.have.lengthOf(2)
276273

277-
// Expect last aggregation for contributorLiteral:
274+
expect(queries[1].query.bool.filter[0].term['subjectLiteral.raw'] === 'S1')
275+
276+
// Expect last aggregation for subjectLiteral:
278277
expect(Object.keys(queries[2].aggregations)).to.have.lengthOf(1)
279-
expect(queries[2]).to.nested.include({ 'aggregations.contributorLiteral.terms.field': 'contributorLiteral.raw' })
280-
// Expect this agg to filter on the other active filter, subjectLiteral:
278+
expect(queries[2]).to.nested.include({ 'aggregations.subjectLiteral.terms.field': 'subjectLiteral.raw' })
279+
// Expect this agg to filter on the other active filter, collection:
280+
expect(queries[2]).to.nested.include({ 'query.bool.filter[0].bool.should[0].term.collectionIds': 'C1' })
281+
expect(queries[2]).to.nested.include({ 'query.bool.filter[0].bool.should[1].term.collectionIds': 'C2' })
281282
expect(queries[2].query.bool.filter).to.have.lengthOf(1)
282-
283-
expect(queries[2].query.bool.filter[0].term['subjectLiteral.raw'] === 'S1')
283+
expect(queries[2].query.bool.filter[0].bool.should).to.have.lengthOf(2)
284284
})
285285
})
286286

0 commit comments

Comments
 (0)