diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 00000000..f9d5f765 --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,30 @@ +name: integration-test + +on: + pull_request: + branches: + - production + +jobs: + integration-test: + permissions: + id-token: write + contents: read + runs-on: ubuntu-latest + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole + aws-region: us-east-1 + - uses: actions/checkout@v3 + - name: Set Node version + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + - name: npm install + run: npm i + - name: Run integration tests + env: + ENV: 'qa' + run: node test/integration/delivery-locations-by-barcode.test.js diff --git a/config/production.env b/config/production.env index 2635bc6a..925f463f 100644 --- a/config/production.env +++ b/config/production.env @@ -1,5 +1,5 @@ ENCRYPTED_ELASTICSEARCH_URI=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAJYwgZMGCSqGSIb3DQEHBqCBhTCBggIBADB9BgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDFWw8ECX9Pz81z0kvAIBEIBQGec9PCpwuvEgLH6imhqP6tx1fj8Vlf2ZipnUy06jzmpE262Qvk9LPAq7sIYPVkTCZctwilwcU9oC6yxasVoUlK87la77v03CeZsPIDwciFY= -ENCRYPTED_RESOURCES_INDEX=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAHcwdQYJKoZIhvcNAQcGoGgwZgIBADBhBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDLHxxMobbmmkVc76dQIBEIA0aZV7enzAKvaDMt7lJik1Ps8J6wikj4dJTL6YzjIlpRh8Dsl7tYgpEgsTNVqA7JRhErUT9w== +ENCRYPTED_RESOURCES_INDEX=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAHcwdQYJKoZ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QcBMB4GCWCGSAFlAwQBLjARBAyWz91LOP2YP5fg0q0CARCAQ9inO9SV1M8R0Pkkx84r7UdwlU1FxfXvIjk/z6Qs81KBAVELhby2iD5LawQyDrR9tjhuMbotS6QnydwwMR/p8+qJXHI= -NYPL_CORE_VERSION=v2.35 +NYPL_CORE_VERSION=v2.37 LOG_LEVEL=info FEATURES=on-site-edd diff --git a/config/qa.env b/config/qa.env index 627e25b8..a1b87a36 100644 --- a/config/qa.env +++ b/config/qa.env @@ -12,7 +12,7 @@ NYPL_OAUTH_URL=https://isso.nypl.org/ ENCRYPTED_NYPL_OAUTH_ID=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDMLKVUQA58B6vprNcAIBEIAoaz0lI9EL2M9NyTuEwT8JDmPBt6aXfMiFs027DEuwsCN0wS0qWeFL1g== ENCRYPTED_NYPL_OAUTH_SECRET=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAIcwgYQGCSqGSIb3DQEHBqB3MHUCAQAwcAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAyWz91LOP2YP5fg0q0CARCAQ9inO9SV1M8R0Pkkx84r7UdwlU1FxfXvIjk/z6Qs81KBAVELhby2iD5LawQyDrR9tjhuMbotS6QnydwwMR/p8+qJXHI= -NYPL_CORE_VERSION=v2.35 +NYPL_CORE_VERSION=v2.37 LOG_LEVEL=debug FEATURES=on-site-edd diff --git a/lib/available_delivery_location_types.js b/lib/available_delivery_location_types.js index 16cf7bd6..1f3835ec 100644 --- a/lib/available_delivery_location_types.js +++ b/lib/available_delivery_location_types.js @@ -8,7 +8,6 @@ class AvailableDeliveryLocationTypes { if (!patronID) return null const patronType = await this._getPatronTypeOf(patronID) - if (this._isUnfamiliarPatronType(patronType)) { return null } diff --git a/lib/models/Item.js b/lib/models/Item.js index 2a868f29..f1e990ec 100644 --- a/lib/models/Item.js +++ b/lib/models/Item.js @@ -114,7 +114,6 @@ Item.withDeliveryLocationsByBarcode = async function (item, scholarRoom) { const model = new Item(item) item.eddRequestable = !!model.eddRequestable const filteredDeliveryLocationsWithScholarRoom = locationUtils.filterLocations(model.deliveryLocation, scholarRoom) - item.deliveryLocation = locationUtils.formatLocations(filteredDeliveryLocationsWithScholarRoom) return item } diff --git a/lib/models/Location.js b/lib/models/Location.js index b73ab0f0..56a50be3 100644 --- a/lib/models/Location.js +++ b/lib/models/Location.js @@ -24,18 +24,7 @@ class Location { case 'm2-customer-code': return this.deliveryLocationsByM2CustomerCode default: - return this.deliveryLocationByHoldingLocation - } - } - - get deliveryLocationByHoldingLocation () { - if (this.nyplCoreLocation?.sierraDeliveryLocations?.length) { - // It's mapped, but the sierraDeliveryLocation entities only have `code` and `label` - // Do a second lookup to populate `deliveryLocationTypes` - return this.nyplCoreLocation.sierraDeliveryLocations.map((deliveryLocation) => { - deliveryLocation.deliveryLocationTypes = this.nyplCoreLocation.deliveryLocationTypes - return deliveryLocation - }) + return this.nyplCoreLocation?.sierraDeliveryLocations } } diff --git a/lib/resources.js b/lib/resources.js index 3c9cccf6..f49d8735 100644 --- a/lib/resources.js +++ b/lib/resources.js @@ -336,7 +336,6 @@ module.exports = function (app, _private = null) { // The resolved values of Promise.all are strictly ordered based on original array of promises const items = resp[0] const scholarRoom = resp[1] - // Use HTC API and nypl-core mappings to ammend ES response with deliveryLocations: return Promise.all(items.map(async (item) => Item.withDeliveryLocationsByBarcode(item, scholarRoom))) .catch((e) => { diff --git a/test/integration/delivery-locations-by-barcode.test.js b/test/integration/delivery-locations-by-barcode.test.js index 2302b12b..23245370 100644 --- a/test/integration/delivery-locations-by-barcode.test.js +++ b/test/integration/delivery-locations-by-barcode.test.js @@ -1,17 +1,25 @@ -require('dotenv').config('config/qa.env') -const axios = require('axios') +const { loadConfig } = require('../../lib/load-config') const { expectations, ptypes } = require('./delivery-locations-constants') +const { makeNyplDataApiClient } = require('../../lib/data-api-client') const checkLocationsForPtype = async (ptype) => { const problems = [] const match = [] - await Promise.all(Object.values(expectations).map(async (expectation) => { - const deliveryLocationsFromApi = await getDeliveryLocations(expectation.barcode, ptypes[ptype]) + + await Promise.all(Object.entries(expectations).map(async ([holdingLocation, expectation], i) => { + let deliveryLocationsFromApi let totalMatch = true const registerProblem = (problem) => { - problems.push({ barcode: expectation.barcode, deliveryLocationsFromApi, ...problem }) + problems.push({ holdingLocation, barcode: expectation.barcode, deliveryLocationsFromApi, ...problem }) totalMatch = false } + try { + deliveryLocationsFromApi = await getDeliveryLocations(expectation.barcode, ptypes[ptype]) + } catch (e) { + registerProblem({ lookUpFailed: true }) + return + } + const checkForValue = (expectedValue, action) => { const includedValueIncluded = deliveryLocationsFromApi.some((label) => label.includes(expectedValue)) const match = action === 'include' ? includedValueIncluded : !includedValueIncluded @@ -27,20 +35,30 @@ const checkLocationsForPtype = async (ptype) => { } const getDeliveryLocations = async (barcode, patronId) => { - const { data: { itemListElement: deliveryLocationsPerRecord } } = await axios.get(`http://localhost:8082/api/v0.1/request/deliveryLocationsByBarcode?barcodes[]=${barcode}&patronId=${patronId}`) - // per record - return deliveryLocationsPerRecord[0] - .deliveryLocation.map(loc => loc.prefLabel.toLowerCase()) + try { + const { itemListElement: itemData } = await makeNyplDataApiClient().get(`request/deliveryLocationsByBarcode?barcodes[]=${barcode}&patronId=${patronId}`) + // per record + return itemData[0] + .deliveryLocation.map(loc => loc.prefLabel.toLowerCase()) + } catch (e) { + console.error(e) + } } const theThing = async () => { + await loadConfig() const results = await Promise.all(Object.keys(ptypes).map((checkLocationsForPtype))) - Object.keys(ptypes).forEach((ptype, i) => { + const resultsHaveProblems = Object.keys(ptypes).some((ptype, i) => { const resultsForPtype = results[i] if (resultsForPtype.problems.length) { console.error(`Error with ${ptype} ptype delivery results, `, resultsForPtype.problems) - } else console.log(`All delivery location checks for ${ptype} patron type successful`) + return true + } else { + console.log(`All delivery location checks for ${ptype} patron type successful`) + return false + } }) + if (resultsHaveProblems) throw new Error('Delivery location checks failed.') } theThing() diff --git a/test/integration/delivery-locations-constants.js b/test/integration/delivery-locations-constants.js index b46d812c..bf079333 100644 --- a/test/integration/delivery-locations-constants.js +++ b/test/integration/delivery-locations-constants.js @@ -38,11 +38,11 @@ const expectations = { scholar: { includes: [schomburg], excludes: [scholar, sasb, lpa] }, general: { includes: [schomburg], excludes: [scholar, sasb, lpa] } }, - // nyplM1: { - // barcode: null, - // scholar: { includes: [sasb], excludes: [scholar, lpa, schomburg] }, - // general: { includes: [sasb], excludes: [scholar, lpa, schomburg] } - // }, + nyplM1: { + barcode: '33433084847221', + scholar: { includes: [sasb], excludes: [scholar, lpa, schomburg] }, + general: { includes: [sasb], excludes: [scholar, lpa, schomburg] } + }, nyplM2: { barcode: '33333069027734', scholar: { includes: [sasb, scholar], excludes: [lpa, schomburg] },