Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
2dcd506
delete: remove mapcolonies template tests
NivGreenstein May 6, 2024
be68188
fix: added await to getApp
NivGreenstein May 6, 2024
6ffad54
feat: exporting getTiles query params
NivGreenstein May 6, 2024
86b5a54
feat: created requestSender for tiles tests
NivGreenstein May 6, 2024
51b2785
feat: created tiles integration tests
NivGreenstein May 6, 2024
256443b
chore: GetItemsQueryParams interface created and exported
NivGreenstein May 6, 2024
60459e6
feat: integration tests created for items
NivGreenstein May 6, 2024
75e9c34
chroe: created GetRoutesQueryParams and exported interface
NivGreenstein May 6, 2024
bbb3ad6
feat: created requestSender for route testing
NivGreenstein May 6, 2024
fc9245d
feat: created route integration testing
NivGreenstein May 6, 2024
f0b63d5
added empty response test
NivGreenstein May 6, 2024
444acb5
changed tile
May 7, 2024
d2f887b
fixed test case
May 7, 2024
f2d92db
updated default password
May 8, 2024
e4d12a1
added config to tests enviorment
May 8, 2024
7271dbb
created dev scripts with mock data
May 8, 2024
8e4320e
fix: changed parameters according to the new mock data
May 8, 2024
4fb40b5
feat(package.json): added dev:scripts script
May 8, 2024
d609b89
fix(tsconfig): added resolveJsonModule: true
May 8, 2024
be1a615
fix(openapi3): changed oneOf to anyOf
May 8, 2024
197a910
fix: updated password
May 8, 2024
6c4af89
fixed zone
May 8, 2024
8f71971
feat: exported query params interfaces
May 8, 2024
0ffc2c7
feat: added types and testTimeout increased to 15000
May 8, 2024
f22552b
fix: updated openapi3 to return the right type
May 8, 2024
40332d9
added dataSource.ts for typeorm migration
May 8, 2024
6605d29
feat: added latLon integration testing
May 8, 2024
ce1efde
feat: added typeorm migration scripts
May 8, 2024
5ac81d3
fix: fixed test cases for missing required properties and invalid ones
NivGreenstein May 9, 2024
e87b598
fix: updated returned schema on /lookup/latLonToTile
NivGreenstein May 9, 2024
6cbebe4
fix: ignoring .DS_Store file when developing on macos
NivGreenstein May 9, 2024
95c5b9a
feat: created mock data script for tile_lat_lon
May 9, 2024
486d1ac
fix: changed schema name
May 9, 2024
569c8f7
feat: updated dev scripts to init import data to postgresql
May 9, 2024
3d2e5dc
fix: increaded timeout and added types
May 9, 2024
384ef1b
feat: added tests for lat-lon to tile
May 9, 2024
a2b28e5
feat: added test tile to lat-lon
May 9, 2024
2b3e856
fix: updated description
May 9, 2024
ec86020
feat: added test cases for status code 400
May 9, 2024
499f856
fix: fixed description
May 9, 2024
834b191
fix: changed response objects to correct ones
May 9, 2024
e972cc5
fix: increased test timeout
May 9, 2024
0818189
fix: fixed returned schema to correct one
May 9, 2024
729e3e1
fix: removed comment
May 9, 2024
1730143
fix: changed type to correct one
May 9, 2024
01ddcf0
chore: changed test from having for-loop to jest's test.each loop so …
May 12, 2024
ef277ba
feat: created new FeatureCollection type
May 12, 2024
bc3d3b4
fix(item.ts): updated type to extend @types/geojson Feature
May 12, 2024
cb54e19
fix(route.ts): updated type to extend @types/geojson Feature
May 12, 2024
16752f7
fix(tile.ts): updated type to extend @types/geojson Feature
May 12, 2024
02047cd
fix: updated formatResponse returned object to FeatureCollection
May 12, 2024
3be5025
fix(itemManager): updated returned type
May 12, 2024
20b7549
delete(latLonManager): removed unused import
May 12, 2024
6388265
fix(routeManager): updated returned type
May 12, 2024
13daf1f
fix(tileManager): updated returned type
May 12, 2024
de2a512
delete: removed boilerplate code
May 12, 2024
83c6c29
feat: created mock data for formatResponse unit testing
May 12, 2024
102f551
feat: created formatResponse unit testing
May 12, 2024
aa9a405
fix: fixed if statement
May 12, 2024
63fc5f9
fix(item): removed properties. now we accept every key as a property
May 12, 2024
4adaf78
fix(route): removed properties. now we accept every key as a property
May 12, 2024
4b4d853
fix(tile): removed properties. now we accept every key as a property
May 12, 2024
75f1a8a
fix(itemManager): added optional chain as property now could be null
May 12, 2024
7c417b0
fix(latLonManager): added optional chain as property now could be null
May 12, 2024
0eb518a
fix(tileManager): added optional chain as property now could be null
May 12, 2024
3a44952
fix(routeManager): added optional chain as property now could be null
May 12, 2024
4765db5
fix: fixed functions types
May 12, 2024
f94cb57
fix(latLonController): fixed returned type
May 12, 2024
203cc97
fix: added "type" key to returned tilesSchema
May 12, 2024
51ced62
feat: added test cases
May 12, 2024
c3168c2
fix: changed test to properly check the assignment of arr[i] = 0 and …
May 12, 2024
34df5a3
delete: removed console.log
May 12, 2024
915b970
WIP : commited only to be deleted later
May 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,6 @@ dist
# Jest
jest_html_reporters.html
reports

# for MacOS Developers
.DS_Store
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "test1234",
"password": "postgres",
"enableSslAuth": false,
"sslPaths": {
"ca": "",
Expand Down
33 changes: 32 additions & 1 deletion config/test.json
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
{}
{
"db": {
"elastic": {
"node": "http://localhost:9200",
"auth": {
"username": "elastic",
"password": "changeme"
},
"requestTimeout": 60000,
"properties": {
"controlIndex": "geocoder_control_tests",
"nlpIndex": "geocoder_control_tests",
"size": 3
}
},
"postgresql": {
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "postgres",
"enableSslAuth": false,
"sslPaths": {
"ca": "",
"key": "",
"cert": ""
},
"database": "postgres",
"schema": "geocoder_test"
}
}
}
13 changes: 13 additions & 0 deletions dataSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import config from 'config';
import { DataSource } from 'typeorm';
import { createConnectionOptions } from './src/common/postgresql';
import { PostgresDbConfig } from './src/common/interfaces';

const connectionOptions = config.get<PostgresDbConfig>('db.postgresql');

export const appDataSource = new DataSource({
...createConnectionOptions(connectionOptions),
entities: ['src/**/DAL/*.ts'],
migrationsTableName: 'migrations_table',
migrations: ['db/migrations/*.ts'],
});
145 changes: 145 additions & 0 deletions devScripts/elasticsearchData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
[
{
"_id": "CONTROL.ITEMS",
"_score": 1,
"_source": {
"type": "Feature",
"id": 27,
"geometry": {
"coordinates": [
[
[98.96871358832425, 18.77187541003238],
[98.96711613001014, 18.772012912146167],
[98.9668257091372, 18.77957500633211],
[98.96517988589727, 18.783516234000658],
[98.96305002071, 18.786174113473763],
[98.96222710028087, 18.786036643850125],
[98.9615009529004, 18.784478609414165],
[98.96096850521184, 18.78324114944766],
[98.96058105300438, 18.74932410944021],
[98.96029062202649, 18.747169677704846],
[98.9619364723165, 18.74666541646775],
[98.96479250629358, 18.7514784826093],
[98.96401797557468, 18.75193687161918],
[98.96614791571238, 18.754412116891245],
[98.96639000300826, 18.75940841151673],
[98.96779381973744, 18.759133392649602],
[98.96798745662056, 18.76018763174328],
[98.96789063809456, 18.761746062357858],
[98.96905242991687, 18.763487833908357],
[98.96871358832425, 18.77187541003238]
]
],
"type": "Polygon"
},
"properties": {
"OBJECTID": 27,
"F_CODE": 2300,
"F_ATT": 602,
"VIEW_SCALE_50K_CONTROL": 604,
"NAME": null,
"GFID": "{93C8C8E2-6AAB-4A84-BBF0-5B10E6F90938}",
"OBJECT_COMMAND_NAME": "4805",
"SUB_TILE_NAME": null,
"TILE_NAME": "DEF",
"TILE_ID": "36, 7300, 3560",
"SUB_TILE_ID": "36",
"SHAPE.AREA": 2.65,
"SHAPE.LEN": 0.0044192097656775,
"LAYER_NAME": "CONTROL.ITEMS",
"ENTITY_HEB": "airport",
"TYPE": "ITEM"
}
}
},
{
"_id": "CONTROL.SUB_TILES",
"_score": 1,
"_source": {
"type": "Feature",
"id": 13668,
"geometry": {
"coordinates": [
[
[27.149158174343427, 35.63159611670335],
[27.149274355343437, 35.64061707270338],
[27.138786228343463, 35.640716597703374],
[27.13867103934342, 35.631695606703374],
[27.149158174343427, 35.63159611670335]
]
],
"type": "Polygon"
},
"properties": {
"OBJECTID": 13668,
"SUB_TILE_ID": "65",
"TILE_NAME": "GRC",
"NAME": "somePlace",
"ZON": 35,
"LAYER_NAME": "CONTROL.SUB_TILES",
"TYPE": "SUB_TILE"
}
}
},
{
"_id": "CONTROL.ROUTES",
"_score": 1,
"_source": {
"type": "Feature",
"id": 2,
"geometry": {
"coordinates": [
[13.448493352142947, 52.31016611400918],
[13.447219581381603, 52.313370282889224],
[13.448088381125075, 52.31631514453963],
[13.450458681234068, 52.31867376333767],
[13.451112278530388, 52.32227665244022],
[13.449728938644029, 52.32463678850752],
[13.445021899434977, 52.32863442881066],
[13.444723882330948, 52.340023400115086],
[13.446229682887974, 52.34532799609971]
],
"type": "LineString"
},
"properties": {
"OBJECTID": 2,
"OBJECT_COMMAND_NAME": "route96",
"FIRST_GFID": null,
"SHAPE_Length": 4.1,
"F_CODE": 8754,
"F_ATT": 951,
"LAYER_NAME": "CONTROL.ROUTES",
"ENTITY_HEB": "route96",
"TYPE": "ROUTE"
}
}
},
{
"_id": "CONTROL.TILES",
"_score": 1,
"_source": {
"type": "Feature",
"id": 52,
"geometry": {
"coordinates": [
[
[12.539507865186607, 41.851751203650096],
[12.536787075186538, 41.94185043165008],
[12.42879133518656, 41.93952837265009],
[12.431625055186686, 41.84943698365008],
[12.539507865186607, 41.851751203650096]
]
],
"type": "Polygon"
},
"properties": {
"OBJECTID": 52,
"ZONE": "37",
"TILE_NAME": "RIT",
"TILE_ID": null,
"LAYER_NAME": "CONTROL.TILES",
"TYPE": "TILE"
}
}
}
]
20 changes: 20 additions & 0 deletions devScripts/importDataToElastic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { Client } from '@elastic/elasticsearch';
import config from '../config/test.json';
import data from './elasticsearchData.json';

const main = async (): Promise<void> => {
const client = new Client({ node: config.db.elastic.node as string });

for (const item of data) {
await client.index({
index: config.db.elastic.properties.controlIndex as string,
id: item._id as string,
body: item._source,
});
}
};

export default main;
45 changes: 45 additions & 0 deletions devScripts/importToPostgres.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { DataSource } from 'typeorm';
import { createConnectionOptions } from '../src/common/postgresql';
import config from '../config/test.json';
import { PostgresDbConfig } from '../src/common/interfaces';

export default async function createDatabaseClient(): Promise<void> {
const connectionOptions = config.db.postgresql as PostgresDbConfig;
const connection = new DataSource({
...createConnectionOptions(connectionOptions),
});

await connection.initialize();

await connection.query(`
CREATE TABLE IF NOT EXISTS ${config.db.postgresql.schema}.tile_lat_lon
(
pk integer NOT NULL,
tile_name text COLLATE pg_catalog."default",
zone text COLLATE pg_catalog."default",
min_x text COLLATE pg_catalog."default",
min_y text COLLATE pg_catalog."default",
ext_min_x integer,
ext_min_y integer,
ext_max_x integer,
ext_max_y integer,
CONSTRAINT tile_lat_lon_pkey PRIMARY KEY (pk)
)
`);

await connection.query(`
INSERT INTO ${config.db.postgresql.schema}.tile_lat_lon(
pk, tile_name, zone, min_x, min_y, ext_min_x, ext_min_y, ext_max_x, ext_max_y)
VALUES (1, 'BRN', '33', '360000', '5820000', 360000, 5820000, 370000, 5830000);
`);

await connection.query(`
INSERT INTO ${config.db.postgresql.schema}.tile_lat_lon(
pk, tile_name, zone, min_x, min_y, ext_min_x, ext_min_y, ext_max_x, ext_max_y)
VALUES (2, 'BMN', '32', '480000', '5880000', 480000, 5880000, 490000, 5890000);
`);

console.log('PGSQL: Table created and data inserted');

await connection.destroy();
}
10 changes: 10 additions & 0 deletions devScripts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import importDataToElastic from './importDataToElastic';
import importToPostgres from './importToPostgres';

importDataToElastic()
.then(() => console.log('Success import data to elastic'))
.catch(console.error);

importToPostgres()
.then(() => console.log('Success import data to postgres'))
.catch(console.error);
14 changes: 11 additions & 3 deletions openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ paths:
content:
application/json:
schema:
oneOf:
anyOf:
- $ref: "#/components/schemas/tilesSchema"
- $ref: "#/components/schemas/routesSchema"
- $ref: "#/components/schemas/itemsSchema"
Expand Down Expand Up @@ -226,7 +226,7 @@ paths:
content:
application/json:
schema:
oneOf:
anyOf:
- $ref: "#/components/schemas/routesSchema"
- $ref: "#/components/schemas/itemsSchema"
400:
Expand Down Expand Up @@ -396,7 +396,12 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/tilesSchema"
type: object
properties:
lat:
type: number
lon:
type: number
400:
"$ref": "#/components/responses/BadRequest"
401:
Expand Down Expand Up @@ -499,6 +504,9 @@ components:
items:
type: "object"
properties:
type:
type: "string"
enum: ["Feature"]
geometry:
$ref: "#/components/schemas/Geometry"
properties:
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
"start:dev": "npm run build && cd dist && node --enable-source-maps ./index.js",
"assets:copy": "copyfiles -f ./config/* ./dist/config && copyfiles -f ./openapi3.yaml ./dist/ && copyfiles ./package.json dist",
"clean": "rimraf dist",
"install": "npx husky install"
"install": "npx husky install",
"dev:scripts": "npx ts-node ./devScripts/index.ts",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js -d dataSource.ts",
"migration:create": "npm run typeorm migration:generate",
"migration:run": "npm run typeorm migration:run",
"migration:revert": "npm run typeorm migration:revert"
},
"directories": {
"test": "tests"
Expand Down
5 changes: 5 additions & 0 deletions src/common/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ClientOptions } from '@elastic/elasticsearch';
import { DataSourceOptions } from 'typeorm';
import { Feature, FeatureCollection as GeoJSONFeatureCollection } from 'geojson';

export interface IConfig {
get: <T>(setting: string) => T;
Expand Down Expand Up @@ -31,3 +32,7 @@ export interface Geometry {
type: string;
coordinates: number[][][];
}

export interface FeatureCollection<T extends Feature> extends GeoJSONFeatureCollection {
features: T[];
}
16 changes: 6 additions & 10 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@ import { Tile } from '../tile/models/tile';
import { Route } from '../route/models/route';
import { FIELDS } from './constants';
import { utmProjection, wgs84Projection } from './projections';
import { FeatureCollection } from './interfaces';

export const formatResponse = <T extends Item | Tile | Route>(
elasticResponse: estypes.SearchResponse<T>
): {
type: string;
features: (T | undefined)[];
} => ({
export const formatResponse = <T extends Item | Tile | Route>(elasticResponse: estypes.SearchResponse<T>): FeatureCollection<T> => ({
type: 'FeatureCollection',
features: [
...elasticResponse.hits.hits.map((item) => {
...(elasticResponse.hits.hits.map((item) => {
const source = item._source;
if (source) {
if (source?.properties) {
Object.keys(source.properties).forEach((key) => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (source.properties[key as keyof typeof source.properties] == null) {
if (source.properties !== null && source.properties[key as keyof typeof source.properties] == null) {
delete source.properties[key as keyof typeof source.properties];
}
});
}
return source;
}),
}) as T[]),
],
});

Expand Down
Loading