diff --git a/e2e/src/api/specs/asset.e2e-spec.ts b/e2e/src/api/specs/asset.e2e-spec.ts index d18dc2532c..30febc777d 100644 --- a/e2e/src/api/specs/asset.e2e-spec.ts +++ b/e2e/src/api/specs/asset.e2e-spec.ts @@ -1006,7 +1006,7 @@ describe('/asset', () => { id: expect.any(String), lat: expect.closeTo(39.115), lon: expect.closeTo(-108.400_968), - state: 'Mesa County, Colorado', + state: 'Colorado', }, { city: 'Ralston', @@ -1014,7 +1014,7 @@ describe('/asset', () => { id: expect.any(String), lat: expect.closeTo(41.2203), lon: expect.closeTo(-96.071_625), - state: 'Douglas County, Nebraska', + state: 'Nebraska', }, ]); }); @@ -1033,7 +1033,7 @@ describe('/asset', () => { id: expect.any(String), lat: expect.closeTo(39.115), lon: expect.closeTo(-108.400_968), - state: 'Mesa County, Colorado', + state: 'Colorado', }, { city: 'Ralston', @@ -1041,7 +1041,7 @@ describe('/asset', () => { id: expect.any(String), lat: expect.closeTo(41.2203), lon: expect.closeTo(-96.071_625), - state: 'Douglas County, Nebraska', + state: 'Nebraska', }, ]); }); diff --git a/e2e/src/api/specs/search.e2e-spec.ts b/e2e/src/api/specs/search.e2e-spec.ts index d3274ed729..be6268babf 100644 --- a/e2e/src/api/specs/search.e2e-spec.ts +++ b/e2e/src/api/specs/search.e2e-spec.ts @@ -469,7 +469,8 @@ describe('/search', () => { const { status, body } = await request(app) .get('/search/suggestions?type=state') .set('Authorization', `Bearer ${admin.accessToken}`); - expect(body).toEqual(states); + expect(body).toHaveLength(states.length); + expect(body).toEqual(expect.arrayContaining(states)); expect(status).toBe(200); }); diff --git a/server/src/repositories/metadata.repository.ts b/server/src/repositories/metadata.repository.ts index e7d37407d9..982368c07a 100644 --- a/server/src/repositories/metadata.repository.ts +++ b/server/src/repositories/metadata.repository.ts @@ -79,7 +79,9 @@ export class MetadataRepository implements IMetadataRepository { queryRunner: QueryRunner, lineToEntityMapper: (lineSplit: string[]) => GeodataPlacesEntity, filePath: string, + options?: { entityFilter?: (linesplit: string[]) => boolean }, ) { + const _entityFilter = options?.entityFilter ?? (() => true); if (!existsSync(filePath)) { this.logger.error(`Geodata file ${filePath} not found`); throw new Error(`Geodata file ${filePath} not found`); @@ -91,6 +93,9 @@ export class MetadataRepository implements IMetadataRepository { for await (const line of lineReader) { const lineSplit = line.split('\t'); + if (!_entityFilter(lineSplit)) { + continue; + } const geoData = lineToEntityMapper(lineSplit); bufferGeodata.push(geoData); if (bufferGeodata.length > 1000) { @@ -123,6 +128,7 @@ export class MetadataRepository implements IMetadataRepository { admin2Name: admin2Map.get(`${lineSplit[8]}.${lineSplit[10]}.${lineSplit[11]}`), }), geodataCities500Path, + { entityFilter: (lineSplit) => lineSplit[7] != 'PPLX' }, ); } @@ -167,10 +173,9 @@ export class MetadataRepository implements IMetadataRepository { this.logger.verbose(`Raw: ${JSON.stringify(response, null, 2)}`); - const { countryCode, name: city, admin1Name, admin2Name } = response; + const { countryCode, name: city, admin1Name } = response; const country = getName(countryCode, 'en') ?? null; - const stateParts = [admin2Name, admin1Name].filter((name) => !!name); - const state = stateParts.length > 0 ? stateParts.join(', ') : null; + const state = admin1Name; return { country, state, city }; }