Skip to content

Commit

Permalink
Remove hard coded covid hotfixes (#10)
Browse files Browse the repository at this point in the history
* Final cleanup

* Fix location code

* Fix tests

* fix cypress tests

* fix missing type

* Fix make superuser file
  • Loading branch information
stanislaw-zakrzewski authored Jul 14, 2023
1 parent f2c1b88 commit cd68be1
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 28 deletions.
13 changes: 8 additions & 5 deletions data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}

Expand Down
2 changes: 1 addition & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions dev/make_superuser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions verification/curator-service/ui/src/api/models/Day0Case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface Demographics {

export interface GeocodeLocation {
country: string;
countryISO3: string;
administrativeAreaLevel1: string;
administrativeAreaLevel2: string;
administrativeAreaLevel3: string;
Expand Down
3 changes: 2 additions & 1 deletion verification/curator-service/ui/src/components/CaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const initialValuesFromCase = (
...c.location,
geocodeLocation: {
country: c.location.countryISO3,
countryISO3: c.location.countryISO3,
administrativeAreaLevel1: '',
administrativeAreaLevel2: '',
administrativeAreaLevel3: '',
Expand Down Expand Up @@ -596,7 +597,7 @@ export default function CaseForm(props: Props): JSX.Element {
isChecked: isChecked({
requiredValues: [
values.caseReference
.sourceUrl,
?.sourceUrl,
],
}),
hasError: hasErrors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit cd68be1

Please sign in to comment.