From cd68be1c3897cf0cf21922986d9d71b8c72fde35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Zakrzewski?= <41862803+stanislaw-zakrzewski@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:21:58 +0200 Subject: [PATCH] Remove hard coded covid hotfixes (#10) * Final cleanup * Fix location code * Fix tests * fix cypress tests * fix missing type * Fix make superuser file --- data-serving/data-service/src/controllers/case.ts | 13 ++++++++----- dev/README.md | 2 +- dev/make_superuser.sh | 7 ++++--- .../ui/cypress/e2e/components/AppTest.spec.ts | 14 +++++++------- .../ui/cypress/e2e/components/BulkCaseForm.spec.ts | 4 ++-- .../ui/cypress/e2e/components/Curator.spec.ts | 2 +- .../e2e/components/LinelistTableTest.spec.ts | 10 +++++----- .../ui/cypress/e2e/components/NewCaseForm.spec.ts | 2 +- .../curator-service/ui/src/api/models/Day0Case.ts | 1 + .../curator-service/ui/src/components/CaseForm.tsx | 3 ++- .../components/new-case-form-fields/Location.tsx | 5 +++-- 11 files changed, 35 insertions(+), 28 deletions(-) diff --git a/data-serving/data-service/src/controllers/case.ts b/data-serving/data-service/src/controllers/case.ts index d46230afe..9feb146b7 100644 --- a/data-serving/data-service/src/controllers/case.ts +++ b/data-serving/data-service/src/controllers/case.ts @@ -398,11 +398,14 @@ export class CasesController { if (numCases === 1) { result = await c.save(); } else { - const cases = Array.from( - { length: numCases }, - () => new Day0Case(req.body), - ); - result = { cases: await Day0Case.insertMany(cases) }; + const newCases: CaseDocument[] = []; + for (let i = 0; i < numCases; i++) { + const multiCaseInstance = new Day0Case( + await caseFromDTO(receivedCase), + ); + newCases.push(await multiCaseInstance.save()); + } + result = { cases: newCases }; } } diff --git a/dev/README.md b/dev/README.md index ab9becdf7..fbdefd7ba 100644 --- a/dev/README.md +++ b/dev/README.md @@ -66,7 +66,7 @@ token, or if you'd like to use a different GMail account for mailing notificatio Give your user all the permissions to access the portal and make CRUD updates. ```shell -./dev/make_superuser.sh $YOUR_GOOGLE_EMAIL +./dev/make_superuser.sh $DATABASE_NAME $YOUR_GOOGLE_EMAIL ``` Note that **the user must be logged-in into the portal before you can issue this command**. To run it against a different instance/database, set `$GDH_DATABASE` to the appropriate connection string. diff --git a/dev/make_superuser.sh b/dev/make_superuser.sh index 034780ca6..2e53d722a 100755 --- a/dev/make_superuser.sh +++ b/dev/make_superuser.sh @@ -7,8 +7,9 @@ pushd `pwd` # We have to run docker-compose from this directory for it to pick up the .env file. cd `dirname "$0"` -# Tell us what database to use — default is covid19 but you can override it for other instances -DB="${GDH_DATABASE:-$MONGO_DB_NAME}" -docker-compose -f docker-compose.yml -f docker-compose.dev.yml exec mongo mongo "${DB}" --eval "var email='$1'; var roles=['admin', 'curator'];" /verification/scripts/roles.js +# Pass database name as the first parameter +DB="${GDH_DATABASE:-$1}" +# Pass email of user to grant an admin role as second parameter +docker-compose -f docker-compose.yml -f docker-compose.dev.yml exec mongo mongo "${DB}" --eval "var email='$2'; var roles=['admin', 'curator'];" /verification/scripts/roles.js # Restore directory. popd \ No newline at end of file diff --git a/verification/curator-service/ui/cypress/e2e/components/AppTest.spec.ts b/verification/curator-service/ui/cypress/e2e/components/AppTest.spec.ts index 37abc5458..510efa7cb 100644 --- a/verification/curator-service/ui/cypress/e2e/components/AppTest.spec.ts +++ b/verification/curator-service/ui/cypress/e2e/components/AppTest.spec.ts @@ -6,43 +6,43 @@ describe('App', function () { beforeEach(() => { cy.task('clearSourcesDB', {}); cy.seedLocation({ - country: 'DEU', + country: 'DE', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Germany', geoResolution: 'Country', }); cy.seedLocation({ - country: 'FRA', + country: 'FR', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'France', geoResolution: 'Country', }); cy.seedLocation({ - country: 'ESP', + country: 'ES', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Spain', geoResolution: 'Country', }); cy.seedLocation({ - country: 'ITA', + country: 'IT', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Italy', geoResolution: 'Country', }); cy.seedLocation({ - country: 'POL', + country: 'PL', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Poland', geoResolution: 'Country', }); cy.seedLocation({ - country: 'RUS', + country: 'RU', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Russia', geoResolution: 'Country', }); cy.seedLocation({ - country: 'PER', + country: 'PE', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Peru', geoResolution: 'Country', diff --git a/verification/curator-service/ui/cypress/e2e/components/BulkCaseForm.spec.ts b/verification/curator-service/ui/cypress/e2e/components/BulkCaseForm.spec.ts index ed959ef59..f7a5d9fef 100644 --- a/verification/curator-service/ui/cypress/e2e/components/BulkCaseForm.spec.ts +++ b/verification/curator-service/ui/cypress/e2e/components/BulkCaseForm.spec.ts @@ -5,13 +5,13 @@ describe('Bulk upload form', function () { cy.task('clearCasesDB', {}); cy.login(); cy.seedLocation({ - country: 'FRA', + country: 'FR', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'France', geoResolution: 'Country', }); cy.seedLocation({ - country: 'CAN', + country: 'CA', geometry: { latitude: 51.1784, longitude: 115.5708 }, name: 'Canada', geoResolution: 'Country', diff --git a/verification/curator-service/ui/cypress/e2e/components/Curator.spec.ts b/verification/curator-service/ui/cypress/e2e/components/Curator.spec.ts index 4c34390e2..f1bed985b 100644 --- a/verification/curator-service/ui/cypress/e2e/components/Curator.spec.ts +++ b/verification/curator-service/ui/cypress/e2e/components/Curator.spec.ts @@ -77,7 +77,7 @@ describe('Curator', function () { cy.get('li[data-value="N"]').click(); // LOCATION - cy.get('div[data-testid="location.geocodeLocation"]').type('France'); + cy.get('div[data-testid="location.geocodeLocation"]').type('France', { delay: 0}); cy.wait('@geolocationFranceSuggest'); cy.contains('France').click(); /* Change France to something else to check we can edit geocode results. diff --git a/verification/curator-service/ui/cypress/e2e/components/LinelistTableTest.spec.ts b/verification/curator-service/ui/cypress/e2e/components/LinelistTableTest.spec.ts index e159a9beb..085c58d11 100644 --- a/verification/curator-service/ui/cypress/e2e/components/LinelistTableTest.spec.ts +++ b/verification/curator-service/ui/cypress/e2e/components/LinelistTableTest.spec.ts @@ -11,31 +11,31 @@ describe('Linelist table', function () { roles: ['admin', 'curator'], }); cy.seedLocation({ - country: 'FRA', + country: 'FR', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'France', geoResolution: 'Country', }); cy.seedLocation({ - country: 'DEU', + country: 'DE', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Germany', geoResolution: 'Country', }); cy.seedLocation({ - country: 'ESP', + country: 'ES', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Spain', geoResolution: 'Country', }); cy.seedLocation({ - country: 'GBR', + country: 'GB', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'United Kingdom', geoResolution: 'Country', }); cy.seedLocation({ - country: 'ARG', + country: 'AR', geometry: { latitude: 51.5072, longitude: -0.1275 }, name: 'Argentina', geoResolution: 'Country', diff --git a/verification/curator-service/ui/cypress/e2e/components/NewCaseForm.spec.ts b/verification/curator-service/ui/cypress/e2e/components/NewCaseForm.spec.ts index cdec5911a..faf28d950 100644 --- a/verification/curator-service/ui/cypress/e2e/components/NewCaseForm.spec.ts +++ b/verification/curator-service/ui/cypress/e2e/components/NewCaseForm.spec.ts @@ -11,7 +11,7 @@ describe('New case form', function () { fixture: 'geolocation_france_suggest.json', }).as('geolocationFranceSuggest'); cy.seedLocation({ - country: 'FRA', + country: 'FR', geometry: { latitude: 45.75889, longitude: 4.84139 }, name: 'France', geoResolution: 'Country', diff --git a/verification/curator-service/ui/src/api/models/Day0Case.ts b/verification/curator-service/ui/src/api/models/Day0Case.ts index 47c641578..767d1f32f 100644 --- a/verification/curator-service/ui/src/api/models/Day0Case.ts +++ b/verification/curator-service/ui/src/api/models/Day0Case.ts @@ -51,6 +51,7 @@ export interface Demographics { export interface GeocodeLocation { country: string; + countryISO3: string; administrativeAreaLevel1: string; administrativeAreaLevel2: string; administrativeAreaLevel3: string; diff --git a/verification/curator-service/ui/src/components/CaseForm.tsx b/verification/curator-service/ui/src/components/CaseForm.tsx index f1610de1f..9815bbb96 100644 --- a/verification/curator-service/ui/src/components/CaseForm.tsx +++ b/verification/curator-service/ui/src/components/CaseForm.tsx @@ -169,6 +169,7 @@ const initialValuesFromCase = ( ...c.location, geocodeLocation: { country: c.location.countryISO3, + countryISO3: c.location.countryISO3, administrativeAreaLevel1: '', administrativeAreaLevel2: '', administrativeAreaLevel3: '', @@ -596,7 +597,7 @@ export default function CaseForm(props: Props): JSX.Element { isChecked: isChecked({ requiredValues: [ values.caseReference - .sourceUrl, + ?.sourceUrl, ], }), hasError: hasErrors( diff --git a/verification/curator-service/ui/src/components/new-case-form-fields/Location.tsx b/verification/curator-service/ui/src/components/new-case-form-fields/Location.tsx index f5a12680d..e9b0d83d9 100644 --- a/verification/curator-service/ui/src/components/new-case-form-fields/Location.tsx +++ b/verification/curator-service/ui/src/components/new-case-form-fields/Location.tsx @@ -5,7 +5,7 @@ import { FastField, useFormikContext } from 'formik'; import makeStyles from '@mui/styles/makeStyles'; import { Day0CaseFormValues } from '../../api/models/Day0Case'; import { useEffect } from 'react'; -import { getAlpha3Codes, getName } from 'i18n-iso-countries'; +import { getAlpha3Codes, getName, alpha2ToAlpha3 } from 'i18n-iso-countries'; const styles = makeStyles(() => ({ root: { @@ -40,7 +40,8 @@ export default function Location(): JSX.Element { setFieldValue( 'location.countryISO3', - values.location.geocodeLocation.country, + values.location.geocodeLocation.countryISO3 || + alpha2ToAlpha3(values.location.geocodeLocation.country), ); setFieldValue('location.country', countryName); setFieldValue(