Merge branch 'update-pipeline' into 'master'

Update pipeline and add integration tests

See merge request adm3981141/fids!2
This commit is contained in:
Santiago Lo Coco 2023-11-01 13:56:01 +00:00
commit 8c0e301e6d
55 changed files with 2220 additions and 1037 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ node_modules
notification-domain/
TODO.txt
*.sh
coverage/

View File

@ -28,8 +28,8 @@ preparation:
- echo "USER_MANAGER_PROD_IMAGE_NAME=${IMAGE_BASE}/user-manager:prod-${BUILD_ID}" >> context.env
- echo "USER_MANAGER_TEST_IMAGE_NAME=${IMAGE_BASE}/user-manager:test-${BUILD_ID}" >> context.env
- echo "SUBSCRIPTION_PROD_IMAGE_NAME=${IMAGE_BASE}/screens-client:prod-${BUILD_ID}" >> context.env
- echo "SUBSCRIPTION_TEST_IMAGE_NAME=${IMAGE_BASE}/screens-client:test-${BUILD_ID}" >> context.env
- echo "SUBSCRIPTION_PROD_IMAGE_NAME=${IMAGE_BASE}/subs-manager:prod-${BUILD_ID}" >> context.env
- echo "SUBSCRIPTION_TEST_IMAGE_NAME=${IMAGE_BASE}/subs-manager:test-${BUILD_ID}" >> context.env
- echo "SCREEN_CLIENT_PROD_IMAGE_NAME=${IMAGE_BASE}/screens-client:prod-${BUILD_ID}" >> context.env
- echo "SCREEN_CLIENT_TEST_IMAGE_NAME=${IMAGE_BASE}/screens-client:test-${BUILD_ID}" >> context.env
@ -285,35 +285,64 @@ test-gateway:
- job: build-gateway
artifacts: true
test-integration:
test-browser-client:
stage: test
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
tags:
- dev
script:
- export $(cat context.env | xargs)
- docker login -u $CI_REGISTRY_USER --password $CI_JOB_TOKEN $CI_REGISTRY
- export API_IMAGE=$FLIGHTS_INFO_TEST_IMAGE_NAME
- export TEST_TARGET=INTEGRATION
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export API_IMAGE=$GATEWAY_TEST_IMAGE_NAME
- export TEST_TARGET=INTEGRATION
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export API_IMAGE=$USER_MANAGER_TEST_IMAGE_NAME
- export TEST_TARGET=INTEGRATION
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export CLIENT_IMAGE=$BROWSER_CLIENT_TEST_IMAGE_NAME
- docker compose -f browser-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f browser-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f browser-domain/docker-compose.yml --env-file $ENV_DEV_FILE up --abort-on-container-exit
- docker cp fids_browser_client:/app/coverage/cobertura-coverage.xml .
- docker cp fids_browser_client:/app/junit.xml .
artifacts:
when: always
paths:
- cobertura-coverage.xml
reports:
junit: junit.xml
coverage_report:
coverage_format: cobertura
path: cobertura-coverage.xml
needs:
- job: test-flights-api
- job: test-auth-api
- job: preparation
- job: build-browser-client
artifacts: true
test-screen-client:
stage: test
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
tags:
- dev
script:
- export $(cat context.env | xargs)
- docker login -u $CI_REGISTRY_USER --password $CI_JOB_TOKEN $CI_REGISTRY
- export CLIENT_IMAGE=$SCREEN_CLIENT_TEST_IMAGE_NAME
- docker compose -f screen-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f screen-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f screen-domain/docker-compose.yml --env-file $ENV_DEV_FILE up --abort-on-container-exit
- docker cp fids_screens_client:/app/coverage/cobertura-coverage.xml .
- docker cp fids_screens_client:/app/junit.xml .
artifacts:
when: always
paths:
- cobertura-coverage.xml
reports:
junit: junit.xml
coverage_report:
coverage_format: cobertura
path: cobertura-coverage.xml
needs:
- job: preparation
- job: build-screen-client
artifacts: true
test-browser-integration:
@ -324,13 +353,38 @@ test-browser-integration:
- export $(cat context.env | xargs)
- docker login -u $CI_REGISTRY_USER --password $CI_JOB_TOKEN $CI_REGISTRY
- export TEST_TARGET=INTEGRATION
- export API_IMAGE=$FLIGHTS_INFO_TEST_IMAGE_NAME
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export API_IMAGE=$GATEWAY_TEST_IMAGE_NAME
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export API_IMAGE=$USER_MANAGER_TEST_IMAGE_NAME
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE exec usermanager-api python manage.py recreate_db
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE exec usermanager-api python manage.py seed_db
- export API_IMAGE=$SUBSCRIPTION_TEST_IMAGE_NAME
- docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export CLIENT_IMAGE=$BROWSER_CLIENT_TEST_IMAGE_NAME
- docker compose -f browser-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f browser-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f browser-domain/docker-compose.yml --env-file $ENV_DEV_FILE up --abort-on-container-exit
needs:
- job: test-integration
- job: build-browser-client
- job: test-flights-api
- job: test-auth-api
- job: test-browser-client
- job: preparation
artifacts: true
@ -342,13 +396,38 @@ test-screen-integration:
- export $(cat context.env | xargs)
- docker login -u $CI_REGISTRY_USER --password $CI_JOB_TOKEN $CI_REGISTRY
- export TEST_TARGET=INTEGRATION
- export API_IMAGE=$FLIGHTS_INFO_TEST_IMAGE_NAME
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f flights-domain/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export API_IMAGE=$GATEWAY_TEST_IMAGE_NAME
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f gateway/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export API_IMAGE=$USER_MANAGER_TEST_IMAGE_NAME
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE exec usermanager-api python manage.py recreate_db
- docker compose -f auth-domain/docker-compose.yml --env-file $ENV_DEV_FILE exec usermanager-api python manage.py seed_db
- export API_IMAGE=$SUBSCRIPTION_TEST_IMAGE_NAME
- docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f subscription-domain/docker-compose.yml --env-file $ENV_DEV_FILE up -d
- export CLIENT_IMAGE=$SCREEN_CLIENT_TEST_IMAGE_NAME
- docker compose -f screen-domain/docker-compose.yml --env-file $ENV_DEV_FILE down
- docker compose -f screen-domain/docker-compose.yml --env-file $ENV_DEV_FILE pull
- docker compose -f screen-domain/docker-compose.yml --env-file $ENV_DEV_FILE up --abort-on-container-exit
needs:
- job: test-integration
- job: build-screen-client
- job: test-flights-api
- job: test-auth-api
- job: test-screen-client
- job: preparation
artifacts: true

View File

@ -7,4 +7,5 @@ services:
restart: always
environment:
- API_HOST=api
- TEST_TARGET=${TEST_TARGET}
network_mode: host

View File

@ -2,4 +2,5 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "jsdom",
coverageReporters: ["html", "text", "text-summary", "cobertura"],
};

View File

@ -28,6 +28,8 @@
"@types/react-dom": "^18.0.11",
"jest": "^28.0.0",
"jest-environment-jsdom": "^28.0.0",
"jest-junit": "^16.0.0",
"supertest": "^6.3.3",
"ts-jest": "^28.0.0",
"typescript": "^4.9.5"
}
@ -5703,6 +5705,12 @@
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg=="
},
"node_modules/component-emitter": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
"dev": true
},
"node_modules/compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
@ -5809,6 +5817,12 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
},
"node_modules/cookiejar": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz",
"integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==",
"dev": true
},
"node_modules/copy-to-clipboard": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/copy-to-clipboard/-/copy-to-clipboard-3.3.3.tgz",
@ -6498,6 +6512,16 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
},
"node_modules/dezalgo": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz",
"integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==",
"dev": true,
"dependencies": {
"asap": "^2.0.0",
"wrappy": "1"
}
},
"node_modules/didyoumean": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
@ -7716,6 +7740,12 @@
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
"integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw=="
},
"node_modules/fast-safe-stringify": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==",
"dev": true
},
"node_modules/fastq": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz",
@ -8099,6 +8129,21 @@
"node": ">= 6"
}
},
"node_modules/formidable": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz",
"integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==",
"dev": true,
"dependencies": {
"dezalgo": "^1.0.4",
"hexoid": "^1.0.0",
"once": "^1.4.0",
"qs": "^6.11.0"
},
"funding": {
"url": "https://ko-fi.com/tunnckoCore/commissions"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -8499,6 +8544,15 @@
"he": "bin/he"
}
},
"node_modules/hexoid": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz",
"integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/hoopy": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz",
@ -10331,6 +10385,33 @@
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
},
"node_modules/jest-junit": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-16.0.0.tgz",
"integrity": "sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ==",
"dev": true,
"dependencies": {
"mkdirp": "^1.0.4",
"strip-ansi": "^6.0.1",
"uuid": "^8.3.2",
"xml": "^1.0.1"
},
"engines": {
"node": ">=10.12.0"
}
},
"node_modules/jest-junit/node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true,
"bin": {
"mkdirp": "bin/cmd.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/jest-leak-detector": {
"version": "28.1.3",
"resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-28.1.3.tgz",
@ -16922,6 +17003,85 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/superagent": {
"version": "8.1.2",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz",
"integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==",
"dev": true,
"dependencies": {
"component-emitter": "^1.3.0",
"cookiejar": "^2.1.4",
"debug": "^4.3.4",
"fast-safe-stringify": "^2.1.1",
"form-data": "^4.0.0",
"formidable": "^2.1.2",
"methods": "^1.1.2",
"mime": "2.6.0",
"qs": "^6.11.0",
"semver": "^7.3.8"
},
"engines": {
"node": ">=6.4.0 <13 || >=14"
}
},
"node_modules/superagent/node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/superagent/node_modules/mime": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
"integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==",
"dev": true,
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/superagent/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/superagent/node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
},
"node_modules/supertest": {
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/supertest/-/supertest-6.3.3.tgz",
"integrity": "sha512-EMCG6G8gDu5qEqRQ3JjjPs6+FYT1a7Hv5ApHvtSghmOFJYtsU5S+pSb6Y2EUeCEY3CmEL3mmQ8YWlPOzQomabA==",
"dev": true,
"dependencies": {
"methods": "^1.1.2",
"superagent": "^8.0.5"
},
"engines": {
"node": ">=6.4.0"
}
},
"node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
@ -18575,6 +18735,12 @@
}
}
},
"node_modules/xml": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
"integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==",
"dev": true
},
"node_modules/xml-name-validator": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz",
@ -22672,6 +22838,12 @@
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg=="
},
"component-emitter": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
"dev": true
},
"compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
@ -22762,6 +22934,12 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
},
"cookiejar": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz",
"integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==",
"dev": true
},
"copy-to-clipboard": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/copy-to-clipboard/-/copy-to-clipboard-3.3.3.tgz",
@ -23243,6 +23421,16 @@
}
}
},
"dezalgo": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz",
"integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==",
"dev": true,
"requires": {
"asap": "^2.0.0",
"wrappy": "1"
}
},
"didyoumean": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
@ -24155,6 +24343,12 @@
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
"integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw=="
},
"fast-safe-stringify": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==",
"dev": true
},
"fastq": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz",
@ -24432,6 +24626,18 @@
"mime-types": "^2.1.12"
}
},
"formidable": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz",
"integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==",
"dev": true,
"requires": {
"dezalgo": "^1.0.4",
"hexoid": "^1.0.0",
"once": "^1.4.0",
"qs": "^6.11.0"
}
},
"forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -24703,6 +24909,12 @@
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="
},
"hexoid": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz",
"integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==",
"dev": true
},
"hoopy": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz",
@ -26050,6 +26262,26 @@
}
}
},
"jest-junit": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-16.0.0.tgz",
"integrity": "sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ==",
"dev": true,
"requires": {
"mkdirp": "^1.0.4",
"strip-ansi": "^6.0.1",
"uuid": "^8.3.2",
"xml": "^1.0.1"
},
"dependencies": {
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true
}
}
},
"jest-leak-detector": {
"version": "28.1.3",
"resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-28.1.3.tgz",
@ -30698,6 +30930,66 @@
}
}
},
"superagent": {
"version": "8.1.2",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz",
"integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==",
"dev": true,
"requires": {
"component-emitter": "^1.3.0",
"cookiejar": "^2.1.4",
"debug": "^4.3.4",
"fast-safe-stringify": "^2.1.1",
"form-data": "^4.0.0",
"formidable": "^2.1.2",
"methods": "^1.1.2",
"mime": "2.6.0",
"qs": "^6.11.0",
"semver": "^7.3.8"
},
"dependencies": {
"lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"requires": {
"yallist": "^4.0.0"
}
},
"mime": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
"integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==",
"dev": true
},
"semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
},
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}
}
},
"supertest": {
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/supertest/-/supertest-6.3.3.tgz",
"integrity": "sha512-EMCG6G8gDu5qEqRQ3JjjPs6+FYT1a7Hv5ApHvtSghmOFJYtsU5S+pSb6Y2EUeCEY3CmEL3mmQ8YWlPOzQomabA==",
"dev": true,
"requires": {
"methods": "^1.1.2",
"superagent": "^8.0.5"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
@ -31940,6 +32232,12 @@
"integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==",
"requires": {}
},
"xml": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
"integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==",
"dev": true
},
"xml-name-validator": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz",

View File

@ -1,5 +1,5 @@
{
"name": "sample-client-users",
"name": "browser-client",
"version": "0.1.0",
"private": true,
"dependencies": {
@ -16,11 +16,9 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest --coverage --collectCoverageFrom=\"./src/**\"",
"test:integration": "jest integration",
"eject": "react-scripts eject",
"docker:build": "docker build -t client-users .",
"docker:run": " docker run --rm -it -p 8080:80 client-users"
"test": "jest --testPathPattern=test.tsx --coverage --collectCoverageFrom=\"./src/**\" --reporters=default --reporters=jest-junit",
"test:integration": "jest integration --testPathPattern=src/tests/integration",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
@ -50,6 +48,8 @@
"@types/react-dom": "^18.0.11",
"jest": "^28.0.0",
"jest-environment-jsdom": "^28.0.0",
"jest-junit": "^16.0.0",
"supertest": "^6.3.3",
"ts-jest": "^28.0.0",
"typescript": "^4.9.5"
}

View File

@ -5,8 +5,6 @@ import "./FlightForm.css";
import { createFlight } from "../../Api";
export const CreateFlight = () => {
const urlParams = new URLSearchParams(window.location.search);
const origin = urlParams.get('origin');
const navigate = useNavigate();
const [error, setError] = useState<string | null>(null);
const [flight, setFlight] = useState<Flight>();

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React from "react";
import { Card } from "./Card/Card";
import { useFetchZones } from "../../hooks/useFetchZones";
import { Flight } from "../../Types";
@ -23,7 +23,7 @@ export const Home: React.FC<Props> = (props) => {
return (
<div className="Box">
{isAirline ? <button onClick={() => { console.log("ANA"); navigate("/create-flight") }}>CREATE FLIGHT</button> : <></>}
{isAirline ? <button onClick={() => { navigate("/create-flight") }}>CREATE FLIGHT</button> : <></>}
<h2>Flights</h2>
<div className="Items">
{(props.flights ? props.flights : zones).map((u) => {

View File

@ -10,11 +10,6 @@ export const LogIn = () => {
return (
<div className="Box Small">
<div className="Section">
<img
alt="logo"
className="Image"
src="https://www.seekpng.com/png/full/353-3537757_logo-itba.png"
/>
<div className="Section">
<Input
placeholder="User"

View File

@ -13,11 +13,6 @@ export const SignUp = () => {
return (
<div className="Box Small">
<div className="Section">
<img
alt="logo"
className="Image"
src="https://www.seekpng.com/png/full/353-3537757_logo-itba.png"
/>
<div className="Section">
<Input
type="email"

View File

@ -0,0 +1,77 @@
const request = require('supertest');
const app = 'http://127.0.0.1:5000'
const authCredentials = {
email: 'info@lufthansa.com',
password: 'password1234',
};
describe('Flight API Endpoints', () => {
let authToken;
beforeAll(async () => {
const loginResponse = await request(app)
.post('/auth/login')
.send(authCredentials);
expect(loginResponse.statusCode).toBe(200);
expect(loginResponse.body).toHaveProperty('access_token');
authToken = loginResponse.body.access_token;
});
it('should create a new flight', async () => {
const newFlight = {
"flight_code": "ABC127",
"status": "En ruta",
"origin": "Frankfurt",
"destination": "Ciudad A",
"departure_time": "2023-10-29 09:57 PM",
"arrival_time": "2023-10-30 12:00 PM",
"gate": "A2"
};
const response = await request(app)
.post('/flights')
.send(newFlight)
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('id');
createdFlightId = response.body.id;
});
it('should retrieve the created flight by ID', async () => {
const response = await request(app)
.get(`/flights/${createdFlightId}`)
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('id', createdFlightId);
});
it('should update a flight by ID', async () => {
const flightUpdate = {
"status": "Delayed"
};
const response = await request(app)
.patch(`/flights/${createdFlightId}`)
.send(flightUpdate)
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('id');
expect(response.body.status).toBe('Delayed');
});
it('should retrieve filtered flights', async () => {
const response = await request(app)
.get('/flights')
.query({ origin: 'Frankfurt' })
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toBeInstanceOf(Array);
expect(response.body[0].id).toBe(createdFlightId)
});
});

View File

@ -1,8 +1,7 @@
#!/bin/bash
curl -X DELETE api:5000/ping
curl -X POST api:5000/ping
# npm test
echo "NPM TEST"
if [ "${TEST_TARGET:-}" = "INTEGRATION" ]; then
npm run test:integration
else
npm run test
fi

View File

@ -1,3 +1,4 @@
from sqlalchemy import Date
from sqlalchemy.orm import Session
from sqlalchemy.sql import func
@ -48,9 +49,29 @@ def get_flights_by_origin(db: Session, origin: str):
return db.query(Flight).filter(Flight.origin == origin).all()
def get_flights_update(db: Session, origin: str, lastUpdate: str):
def get_flights_by_destination(db: Session, destination: str):
return db.query(Flight).filter(Flight.destination == destination).all()
def get_flights_update_origin(db: Session, origin: str, lastUpdate: str):
return (
db.query(Flight)
.filter((Flight.origin == origin) & (Flight.last_updated >= lastUpdate))
.filter(
(Flight.origin == origin)
& (Flight.last_updated >= lastUpdate)
& (Flight.departure_time.cast(Date) >= func.current_date())
)
.all()
)
def get_flights_update_destination(db: Session, destination: str, lastUpdate: str):
return (
db.query(Flight)
.filter(
(Flight.destination == destination)
& (Flight.last_updated >= lastUpdate)
& (Flight.arrival_time.cast(Date) >= func.current_date())
)
.all()
)

View File

@ -51,13 +51,20 @@ async def update_flight(
@router.get("", response_model=list[Flight])
def get_flights(
origin: Optional[str] = None,
destination: Optional[str] = None,
lastUpdated: Optional[str] = None,
db: Session = Depends(get_db),
):
if origin and lastUpdated:
flights = flight_crud.get_flights_update(db, origin, lastUpdated)
flights = flight_crud.get_flights_update_origin(db, origin, lastUpdated)
elif destination and lastUpdated:
flights = flight_crud.get_flights_update_destination(
db, destination, lastUpdated
)
elif origin:
flights = flight_crud.get_flights_by_origin(db, origin)
flights = flight_crud.get_flights_by_origin(db=db, origin=origin)
elif destination:
flights = flight_crud.get_flights_by_destination(db=db, destination=destination)
else:
flights = flight_crud.get_flights(db=db)

View File

@ -51,10 +51,12 @@ async def update_flight(
@router.get("", response_model=list[Flight])
async def get_flights(origin: Optional[str] = None, lastUpdated: Optional[str] = None):
async def get_flights(origin: Optional[str] = None, destination: Optional[str] = None, lastUpdated: Optional[str] = None):
query = {}
if origin:
query["origin"] = origin
if destination:
query["destination"] = destination
if lastUpdated:
query["lastUpdated"] = lastUpdated
(response, status, _) = await request(f"{API_FLIGHTS}", "GET", query=query)

9
run.sh
View File

@ -145,13 +145,13 @@ elif [ -n "$domain" ] && [ -z "$down" ]; then
fi
;;
'screen')
docker build screen-domain -f screen-domain/Dockerfile.prod --build-arg "REACT_APP_ORIGIN=$REACT_APP_ORIGIN" -t $USER/screen-client:prod
export CLIENT_IMAGE=$USER/screen-client:prod
docker build screen-domain -f screen-domain/Dockerfile.test --build-arg "REACT_APP_ORIGIN=$REACT_APP_ORIGIN" -t $USER/screen-client:test
export CLIENT_IMAGE=$USER/screen-client:test
docker compose -f screen-domain/docker-compose.yml up -d
;;
'browser')
docker build browser-domain -f browser-domain/Dockerfile.prod -t $USER/browser-client:prod
export CLIENT_IMAGE=$USER/browser-client:prod
docker build browser-domain -f browser-domain/Dockerfile.test -t $USER/browser-client:test
export CLIENT_IMAGE=$USER/browser-client:test
docker compose -f browser-domain/docker-compose.yml up -d
;;
'elk')
@ -183,6 +183,7 @@ else
export SUBSCRIPTION_MANAGER=subscription-domain/subscription-manager
docker build $SUBSCRIPTION_MANAGER -f $SUBSCRIPTION_MANAGER/Dockerfile.prod -t $USER/subs-manager:prod
export REACT_APP_ORIGIN=Frankfurt
docker build screen-domain -f screen-domain/Dockerfile.prod --build-arg "REACT_APP_ORIGIN=$REACT_APP_ORIGIN" -t $USER/screen-client:prod
docker build browser-domain -f browser-domain/Dockerfile.prod -t $USER/browser-client:prod

View File

@ -1,7 +1,7 @@
FROM node:17.9.1 AS app
WORKDIR /app
COPY package.json /app/package.json
RUN npm -v && ls -al
COPY package.json .
COPY package-lock.json .
RUN npm install
COPY . .

View File

@ -7,4 +7,5 @@ services:
restart: always
environment:
- API_HOST=api
- TEST_TARGET=${TEST_TARGET}
network_mode: host

View File

@ -2,4 +2,5 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "jsdom",
coverageReporters: ["html", "text", "text-summary", "cobertura"],
};

View File

@ -15,6 +15,7 @@
"react-router": "^6.10.0",
"react-router-dom": "^6.10.0",
"react-scripts": "5.0.1",
"react-super-responsive-table": "^5.2.2",
"web-vitals": "^2.1.4"
},
"devDependencies": {
@ -27,6 +28,8 @@
"@types/react-dom": "^18.0.11",
"jest": "^28.0.0",
"jest-environment-jsdom": "^28.0.0",
"jest-junit": "^16.0.0",
"supertest": "^6.3.3",
"ts-jest": "^28.0.0",
"typescript": "^4.9.5"
}
@ -5702,6 +5705,12 @@
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg=="
},
"node_modules/component-emitter": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
"dev": true
},
"node_modules/compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
@ -5808,6 +5817,12 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
},
"node_modules/cookiejar": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz",
"integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==",
"dev": true
},
"node_modules/copy-to-clipboard": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/copy-to-clipboard/-/copy-to-clipboard-3.3.3.tgz",
@ -6497,6 +6512,16 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
},
"node_modules/dezalgo": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz",
"integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==",
"dev": true,
"dependencies": {
"asap": "^2.0.0",
"wrappy": "1"
}
},
"node_modules/didyoumean": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
@ -7715,6 +7740,12 @@
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
"integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw=="
},
"node_modules/fast-safe-stringify": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==",
"dev": true
},
"node_modules/fastq": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz",
@ -8098,6 +8129,21 @@
"node": ">= 6"
}
},
"node_modules/formidable": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz",
"integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==",
"dev": true,
"dependencies": {
"dezalgo": "^1.0.4",
"hexoid": "^1.0.0",
"once": "^1.4.0",
"qs": "^6.11.0"
},
"funding": {
"url": "https://ko-fi.com/tunnckoCore/commissions"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -8498,6 +8544,15 @@
"he": "bin/he"
}
},
"node_modules/hexoid": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz",
"integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==",
"dev": true,
"engines": {
"node": ">=8"
}
},
"node_modules/hoopy": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz",
@ -10330,6 +10385,33 @@
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
},
"node_modules/jest-junit": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-16.0.0.tgz",
"integrity": "sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ==",
"dev": true,
"dependencies": {
"mkdirp": "^1.0.4",
"strip-ansi": "^6.0.1",
"uuid": "^8.3.2",
"xml": "^1.0.1"
},
"engines": {
"node": ">=10.12.0"
}
},
"node_modules/jest-junit/node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true,
"bin": {
"mkdirp": "bin/cmd.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/jest-leak-detector": {
"version": "28.1.3",
"resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-28.1.3.tgz",
@ -15749,6 +15831,19 @@
"node": ">=10"
}
},
"node_modules/react-super-responsive-table": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/react-super-responsive-table/-/react-super-responsive-table-5.2.2.tgz",
"integrity": "sha512-LDsGq8X3TBn0AMv5gX/0wFeWoFMMmiZXNTD1kIMMWz3WflPMHUZOSHXXlG5EOO2u3WSNcVl7MLIk83maS/Xj0g==",
"engines": {
"node": ">=12"
},
"peerDependencies": {
"prop-types": ">= 15",
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
}
},
"node_modules/read-cache": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz",
@ -16916,6 +17011,85 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/superagent": {
"version": "8.1.2",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz",
"integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==",
"dev": true,
"dependencies": {
"component-emitter": "^1.3.0",
"cookiejar": "^2.1.4",
"debug": "^4.3.4",
"fast-safe-stringify": "^2.1.1",
"form-data": "^4.0.0",
"formidable": "^2.1.2",
"methods": "^1.1.2",
"mime": "2.6.0",
"qs": "^6.11.0",
"semver": "^7.3.8"
},
"engines": {
"node": ">=6.4.0 <13 || >=14"
}
},
"node_modules/superagent/node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/superagent/node_modules/mime": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
"integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==",
"dev": true,
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/superagent/node_modules/semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/superagent/node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
},
"node_modules/supertest": {
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/supertest/-/supertest-6.3.3.tgz",
"integrity": "sha512-EMCG6G8gDu5qEqRQ3JjjPs6+FYT1a7Hv5ApHvtSghmOFJYtsU5S+pSb6Y2EUeCEY3CmEL3mmQ8YWlPOzQomabA==",
"dev": true,
"dependencies": {
"methods": "^1.1.2",
"superagent": "^8.0.5"
},
"engines": {
"node": ">=6.4.0"
}
},
"node_modules/supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
@ -18569,6 +18743,12 @@
}
}
},
"node_modules/xml": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
"integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==",
"dev": true
},
"node_modules/xml-name-validator": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz",
@ -22666,6 +22846,12 @@
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg=="
},
"component-emitter": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==",
"dev": true
},
"compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
@ -22756,6 +22942,12 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
},
"cookiejar": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz",
"integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==",
"dev": true
},
"copy-to-clipboard": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/copy-to-clipboard/-/copy-to-clipboard-3.3.3.tgz",
@ -23237,6 +23429,16 @@
}
}
},
"dezalgo": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz",
"integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==",
"dev": true,
"requires": {
"asap": "^2.0.0",
"wrappy": "1"
}
},
"didyoumean": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
@ -24149,6 +24351,12 @@
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
"integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw=="
},
"fast-safe-stringify": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
"integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==",
"dev": true
},
"fastq": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz",
@ -24426,6 +24634,18 @@
"mime-types": "^2.1.12"
}
},
"formidable": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz",
"integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==",
"dev": true,
"requires": {
"dezalgo": "^1.0.4",
"hexoid": "^1.0.0",
"once": "^1.4.0",
"qs": "^6.11.0"
}
},
"forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -24697,6 +24917,12 @@
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="
},
"hexoid": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz",
"integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==",
"dev": true
},
"hoopy": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/hoopy/-/hoopy-0.1.4.tgz",
@ -26044,6 +26270,26 @@
}
}
},
"jest-junit": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-16.0.0.tgz",
"integrity": "sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ==",
"dev": true,
"requires": {
"mkdirp": "^1.0.4",
"strip-ansi": "^6.0.1",
"uuid": "^8.3.2",
"xml": "^1.0.1"
},
"dependencies": {
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true
}
}
},
"jest-leak-detector": {
"version": "28.1.3",
"resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-28.1.3.tgz",
@ -29825,6 +30071,12 @@
}
}
},
"react-super-responsive-table": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/react-super-responsive-table/-/react-super-responsive-table-5.2.2.tgz",
"integrity": "sha512-LDsGq8X3TBn0AMv5gX/0wFeWoFMMmiZXNTD1kIMMWz3WflPMHUZOSHXXlG5EOO2u3WSNcVl7MLIk83maS/Xj0g==",
"requires": {}
},
"read-cache": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz",
@ -30687,6 +30939,66 @@
}
}
},
"superagent": {
"version": "8.1.2",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz",
"integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==",
"dev": true,
"requires": {
"component-emitter": "^1.3.0",
"cookiejar": "^2.1.4",
"debug": "^4.3.4",
"fast-safe-stringify": "^2.1.1",
"form-data": "^4.0.0",
"formidable": "^2.1.2",
"methods": "^1.1.2",
"mime": "2.6.0",
"qs": "^6.11.0",
"semver": "^7.3.8"
},
"dependencies": {
"lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"requires": {
"yallist": "^4.0.0"
}
},
"mime": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
"integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==",
"dev": true
},
"semver": {
"version": "7.5.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz",
"integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
},
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}
}
},
"supertest": {
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/supertest/-/supertest-6.3.3.tgz",
"integrity": "sha512-EMCG6G8gDu5qEqRQ3JjjPs6+FYT1a7Hv5ApHvtSghmOFJYtsU5S+pSb6Y2EUeCEY3CmEL3mmQ8YWlPOzQomabA==",
"dev": true,
"requires": {
"methods": "^1.1.2",
"superagent": "^8.0.5"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
@ -31929,6 +32241,12 @@
"integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==",
"requires": {}
},
"xml": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
"integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==",
"dev": true
},
"xml-name-validator": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz",

View File

@ -1,5 +1,5 @@
{
"name": "sample-client-users",
"name": "screen-client",
"version": "0.1.0",
"private": true,
"dependencies": {
@ -10,16 +10,15 @@
"react-router": "^6.10.0",
"react-router-dom": "^6.10.0",
"react-scripts": "5.0.1",
"react-super-responsive-table": "^5.2.2",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest --coverage --collectCoverageFrom=\"./src/**\"",
"test:integration": "jest integration",
"eject": "react-scripts eject",
"docker:build": "docker build -t client-users .",
"docker:run": " docker run --rm -it -p 8080:80 client-users"
"test": "jest --testPathPattern=test.tsx --coverage --collectCoverageFrom=\"./src/**\" --reporters=default --reporters=jest-junit",
"test:integration": "jest integration --testPathPattern=src/tests/integration",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
@ -49,6 +48,8 @@
"@types/react-dom": "^18.0.11",
"jest": "^28.0.0",
"jest-environment-jsdom": "^28.0.0",
"jest-junit": "^16.0.0",
"supertest": "^6.3.3",
"ts-jest": "^28.0.0",
"typescript": "^4.9.5"
}

View File

@ -1,5 +1,5 @@
import { Axios, AxiosError } from "axios";
import { Credentials, User, Flight } from "./Types";
import { Flight } from "./Types";
const instance = new Axios({
baseURL: process.env.REACT_APP_ENDPOINT ? process.env.REACT_APP_ENDPOINT : "http://127.0.0.1:5000/",
@ -29,8 +29,9 @@ export const ping = () => {
return instance.get("health");
};
export const fetchZones = (origin: string | undefined, lastUpdate: string | null): Promise<Flight[]> => {
export const fetchZones = (origin: string | undefined, destination: string | undefined, lastUpdate: string | null): Promise<Flight[]> => {
return instance.get("flights" +
(origin ? "?origin=" + origin : "") +
(destination ? "?destination=" + destination : "") +
(lastUpdate ? (origin ? "&lastUpdated=" : "?lastUpdated=") + lastUpdate : ""))
};

View File

@ -1,18 +1,17 @@
import React, { useEffect } from "react";
import { useIsConnected } from "./hooks/useIsConnected";
import { Route, Routes } from "react-router";
import { Departure } from "./components/Home/Departure";
import { Arrival } from "./components/Home/Arrival";
import { Home } from "./components/Home/Home";
import { Button } from "antd";
import { initDB } from "./db";
function App() {
const connection = useIsConnected();
initDB();
return (
<div className="App">
<Routes>
<Route path="/home" element={<Home />} />
<Route path="/departure" element={<Departure />} />
<Route path="/arrival" element={<Arrival />} />
<Route path="/" element={<Home />} />
</Routes>
<div className="FloatingStatus">{connection}</div>

View File

@ -0,0 +1,65 @@
import React, { useEffect, useState } from "react";
import { Card } from "./Card/Card";
import { Flight } from "../../Types";
import './Home.css'
import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table';
import 'react-super-responsive-table/dist/SuperResponsiveTableStyle.css';
import { useFetchDestination } from "../../hooks/useFetchDestination";
interface Props {
flights?: Flight[];
}
export const Arrival: React.FC<Props> = (props) => {
let destination = process.env.REACT_APP_ORIGIN;
const { zones, error } = useFetchDestination(destination);
const [startIndex, setStartIndex] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
if (zones.length <= 10) {
return;
}
setStartIndex((prevIndex) => (prevIndex + 10) >= zones.length ? 0 : (prevIndex + 10));
}, 5000);
return () => clearInterval(interval);
}, [zones]);
return (
<div >
<h2>Arrival</h2>
<div className="Items">
<Table>
<Thead>
<Tr>
<Th>Code</Th>
<Th>Origin</Th>
<Th>Time</Th>
<Th>Gate</Th>
<Th>Status</Th>
</Tr>
</Thead>
<Tbody>
{zones.length > 0 && (
<>
{zones.slice(startIndex, startIndex + 10).map((flight) => (
<Tr key={flight.id} className={flight.status === 'Delayed' ? 'delayed-flight' : ''}>
<Td>{flight.flight_code}</Td>
<Td>{flight.origin}</Td>
<Td>{flight.arrival_time}</Td>
<Td>{flight.gate}</Td>
<Td>{flight.status}</Td>
</Tr>
))}
</>
)}
</Tbody>
</Table>
{error ? <div className="Disconnected">{error}</div> : <></>}
</div>
</div>
);
};

View File

@ -1,30 +1,8 @@
/* .flight-card {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px;
border: 1px solid #ddd;
border-radius: 8px;
margin-bottom: 16px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
background-color: #fff;
transition: box-shadow 0.3s ease;
&:hover {
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}
.flight-details {
display: flex;
align-items: center;
}
} */
.flight-card {
display: flex;
flex-direction: column; /* Display as a column instead of a row */
flex-direction: column;
justify-content: space-between;
align-items: flex-start; /* Align items to the start of the column */
align-items: flex-start;
padding: 16px;
border: 1px solid #ddd;
border-radius: 8px;
@ -39,7 +17,7 @@
.flight-details {
display: flex;
flex-direction: column; /* Display details as a column */
margin-top: 16px; /* Add some space between the two rows */
flex-direction: column;
margin-top: 16px;
}
}

View File

@ -1,46 +1,8 @@
// import React from "react";
// import { Avatar, Button } from "antd";
// interface FlightProps {
// flight_code: string;
// status: string;
// origin: string;
// destination: string;
// departure_time: string;
// arrival_time: string;
// gate: string;
// }
// interface CardProps {
// flight: FlightProps;
// }
// export const Card: React.FC<CardProps> = ({
// flight: { flight_code, status, origin, destination, departure_time, arrival_time, gate },
// }) => {
// console.log(flight_code)
// return (
// <div className="Card">
// <Avatar size="large">{flight_code.slice(0, 1).toUpperCase()}</Avatar>
// <div>
// <div>Name: {flight_code}</div>
// <div>Status: {status}</div>
// <div>Origin: {origin}</div>
// <div>Destination: {destination}</div>
// <div>Departure Time: {departure_time}</div>
// <div>Arrival Time: {arrival_time}</div>
// <div>Gate: {gate}</div>
// </div>
// 📍
// </div>
// );
// };
import React from "react";
import { Avatar, Space, Typography, Tag } from "antd";
import { RightOutlined, ClockCircleOutlined, SwapOutlined, EnvironmentOutlined, CalendarOutlined } from "@ant-design/icons";
import "./Card.css"; // Import a CSS file for styling, you can create this file with your styles
import "./Card.css";
interface FlightProps {
flight_code: string;

View File

@ -0,0 +1,82 @@
import React, { useEffect, useState } from "react";
import { Card } from "./Card/Card";
import { useFetchOrigin } from "../../hooks/useFetchOrigin";
import { Flight } from "../../Types";
import './Home.css'
import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table';
import 'react-super-responsive-table/dist/SuperResponsiveTableStyle.css';
interface Props {
flights?: Flight[];
}
export const Departure: React.FC<Props> = (props) => {
let origin = process.env.REACT_APP_ORIGIN;
const { zones, error } = useFetchOrigin(origin);
const [startIndex, setStartIndex] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
if (zones.length <= 10) {
return;
}
setStartIndex((prevIndex) => (prevIndex + 10) >= zones.length ? 0 : (prevIndex + 10));
}, 5000);
return () => clearInterval(interval);
}, [zones]);
return (
<div >
<h2>Departure</h2>
<div className="Items">
<Table>
<Thead>
<Tr>
<Th>Code</Th>
<Th>Time</Th>
<Th>Destination</Th>
<Th>Gate</Th>
<Th>Status</Th>
</Tr>
</Thead>
<Tbody>
{zones.length > 0 && (
<>
{zones.slice(startIndex, startIndex + 10).map((flight) => (
<Tr key={flight.id} className={flight.status === 'Delayed' ? 'delayed-flight' : ''}>
<Td>{flight.flight_code}</Td>
<Td>{flight.departure_time}</Td>
<Td>{flight.destination}</Td>
<Td>{flight.gate}</Td>
<Td>{flight.status}</Td>
</Tr>
// );
))}
{startIndex + 10 >= zones.length && (
<>
{Array.from({ length: startIndex + 10 - zones.length }).map((_, index) => {
return (
<Tr>
<Td></Td>
<Td></Td>
<Td></Td>
<Td></Td>
<Td></Td>
</Tr>
)
})}
</>
)
}
</>
)}
</Tbody>
</Table>
{error ? <div className="Disconnected">{error}</div> : <></>}
</div>
</div>
);
};

View File

@ -0,0 +1,43 @@
body {
font-family: 'Arial', sans-serif;
background-color: #f0f0f0;
}
.App {
text-align: center;
margin-top: 20px;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
background-color: #fff;
}
th,
td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
th {
background-color: #4CAF50;
color: #fff;
}
tbody tr:hover {
background-color: #f5f5f5;
}
tfoot {
background-color: #4CAF50;
color: #fff;
}
.delayed-flight {
background-color: #ffcccc;
color: #ff0000;
}

View File

@ -8,7 +8,7 @@ jest.mock("react-router-dom", () => ({
import "../../matchMedia.mock";
import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import { Home } from "./Home";
// import { Home } from "./Departure";
describe("Home View Test", () => {
test("Display initial, name and icon", async () => {

View File

@ -1,27 +1,24 @@
import React from "react";
import { Card } from "./Card/Card";
import { useFetchZones } from "../../hooks/useFetchZones";
import { Flight } from "../../Types";
import './Home.css'
import { useNavigate } from "react-router";
import './Page.css'
interface Props {
flights?: Flight[];
}
export const Home: React.FC<Props> = (props) => {
// const urlParams = new URLSearchParams(window.location.search);
// const origin = urlParams.get('origin');
// const { zones, error } = useFetchZones(origin);
const { zones, error } = useFetchZones();
const navigate = useNavigate();
const submitHandler = (path: string) => {
navigate(path);
};
return (
<div className="Box">
<h2>Flights</h2>
<div className="Items">
{(props.flights ? props.flights : zones).map((u) => {
return <Card key={u.id} flight={u} />;
})}
{error ? <div className="Disconnected">{error}</div> : <></>}
</div>
<div>
<button onClick={() => submitHandler("/departure")}>Departure</button>
<button onClick={() => submitHandler("/arrival")}>Arrival</button>
</div>
);
};

View File

@ -0,0 +1,33 @@
body {
font-family: 'Arial', sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
div {
text-align: center;
}
button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 10px;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #45a049;
}

View File

@ -3,11 +3,8 @@ let db: IDBDatabase;
let version = 1;
export enum Stores {
Flight = 'flights',
}
interface EventTarget {
result: any
Departure = 'departure',
Arrival = 'arrival'
}
export const initDB = (): Promise<boolean | IDBDatabase> => {
@ -18,8 +15,11 @@ export const initDB = (): Promise<boolean|IDBDatabase> => {
let req = (e.target as IDBOpenDBRequest)
db = req.result;
if (!db.objectStoreNames.contains(Stores.Flight)) {
db.createObjectStore(Stores.Flight, { keyPath: 'id' });
if (!db.objectStoreNames.contains(Stores.Arrival)) {
db.createObjectStore(Stores.Arrival, { keyPath: 'id' });
}
if (!db.objectStoreNames.contains(Stores.Departure)) {
db.createObjectStore(Stores.Departure, { keyPath: 'id' });
}
};
@ -38,55 +38,32 @@ export const initDB = (): Promise<boolean|IDBDatabase> => {
export const addData = <T>(storeName: string, data: T): Promise<T | string | null> => {
return new Promise((resolve) => {
request = indexedDB.open('myDB', version);
request.onsuccess = (e) => {
let req = (e.target as IDBOpenDBRequest)
db = req.result;
const tx = db.transaction(storeName, 'readwrite');
const store = tx.objectStore(storeName);
store.add(data);
resolve(data);
};
request.onerror = () => {
const error = request.error?.message
if (error) {
resolve(error);
} else {
resolve('Unknown error');
}
};
});
};
export const deleteData = (storeName: string, key: number): Promise<boolean> => {
return new Promise((resolve) => {
request = indexedDB.open('myDB', version);
request.onsuccess = (e) => {
let req = (e.target as IDBOpenDBRequest)
db = req.result;
const tx = db.transaction(storeName, 'readwrite');
const store = tx.objectStore(storeName);
const res = store.delete(key);
console.log("removing" + key)
res.onsuccess = () => {
console.log("success")
resolve(true);
};
res.onerror = () => {
console.log("error")
resolve(false);
}
};
});
};
export const updateData = <T>(storeName: string, key: number, data: T): Promise<T | string | null> => {
return new Promise((resolve) => {
request = indexedDB.open('myDB', version);
request.onsuccess = (e) => {
let req = (e.target as IDBOpenDBRequest)
db = req.result;
const tx = db.transaction(storeName, 'readwrite');
const store = tx.objectStore(storeName);
const res = store.get(key);
@ -98,27 +75,17 @@ export const updateData = <T>(storeName: string, key: number, data: T): Promise<
res.onerror = () => {
resolve(null);
}
};
});
};
export const getStoreData = <T>(storeName: Stores): Promise<T[] | null> => {
return new Promise((resolve) => {
request = indexedDB.open('myDB');
request.onsuccess = (e) => {
let req = (e.target as IDBOpenDBRequest)
if (!req.result) {
resolve(null);
}
db = req.result;
const tx = db.transaction(storeName, 'readonly');
const store = tx.objectStore(storeName);
const res = store.getAll();
res.onsuccess = () => {
resolve(res.result);
};
};
});
};

View File

@ -0,0 +1,135 @@
import { useEffect } from "react";
import { useState } from "react";
import { Flight } from "../Types";
import { fetchZones } from "../Api";
import { Stores, addData, deleteData, getStoreData, updateData, initDB } from '../db';
export const useFetchDestination = (destination: string | undefined) => {
const [error, setError] = useState<string | null>(null);
const [zones, setZones] = useState<Flight[]>([]);
const isToday = (someDate: Date) => {
let today = new Date();
return someDate.getDate() == today.getDate() &&
someDate.getMonth() == today.getMonth() &&
someDate.getFullYear() == today.getFullYear()
}
useEffect(() => {
const intervalId = setInterval(() => {
let today = localStorage.getItem('date')
if (today && !isToday(new Date(today))) {
getStoreData<Flight>(Stores.Arrival)
.then((data) => {
if (data) {
data.map((u) => {
deleteData(Stores.Arrival, u.id)
})
}
})
localStorage.setItem('date', new Date().toString())
}
}, 36000)
return () => clearInterval(intervalId);
}, [])
useEffect(() => {
setError(null);
let newUpdate = new Date().toISOString()
localStorage.setItem('date', new Date().toString())
initDB().then((x) => {
console.log(x)
getStoreData<Flight>(Stores.Arrival)
.then((data) => {
console.log(data)
if (data && data.length > 0) {
data.sort((a, b) => new Date(a.departure_time).getTime() - new Date(b.departure_time).getTime())
setZones(data)
} else {
fetchZones(undefined, destination, null)
.then((data) => {
localStorage.setItem('lastUpdated', newUpdate)
let toAdd: Flight[] = []
data.map((u) => {
if (u.status != 'Deleted') {
addData(Stores.Arrival, u)
toAdd.push(u)
}
})
toAdd.sort((a, b) => new Date(a.departure_time).getTime() - new Date(b.departure_time).getTime())
setZones(toAdd);
})
.catch((error) => { });
}
})
}
)
}, [origin]);
useEffect(() => {
const intervalId = setInterval(() => {
let lastUpdate = localStorage.getItem('lastUpdated')
let newUpdate = new Date().toISOString()
fetchZones(undefined, destination, lastUpdate)
.then((data) => {
localStorage.setItem('lastUpdated', newUpdate)
let toAdd: Flight[] = []
let toRemove: Flight[] = []
zones.forEach((c, i) => {
let index = data.findIndex(x => x.id === c.id)
if (index >= 0) {
console.log(data[index].departure_time + 'nuevo')
if (data[index].status == 'Deleted' || new Date(data[index].departure_time) < new Date()) {
console.log("sacamos")
toRemove.push(data[index])
deleteData(Stores.Arrival, c.id)
} else {
toAdd.push(data[index]);
updateData(Stores.Arrival, c.id, data[index])
}
} else {
console.log(new Date(c.departure_time))
if (c.status == 'Deleted' || new Date(c.departure_time) < new Date()) {
console.log("sacamos?")
toRemove.push(c);
deleteData(Stores.Arrival, c.id)
} else {
toAdd.push(c);
}
}
});
let filtered = data.filter(o =>
!toAdd.some(b => { return o.id === b.id }) && !toRemove.some(b => { return o.id === b.id }) && !(new Date(o.departure_time) < new Date())
)
const newArray = toAdd.concat(filtered);
console.log(filtered)
console.log(newArray)
filtered.forEach(c => {
addData(Stores.Arrival, c)
})
newArray.sort((a, b) => new Date(a.departure_time).getTime() - new Date(b.departure_time).getTime())
setZones(newArray);
})
.catch((error) => {
if (!!error.isAxiosError && !error.response) {
//
}
});
}, 5000)
return () => clearInterval(intervalId);
}, [origin, zones])
return { zones, error };
};

View File

@ -0,0 +1,135 @@
import { useEffect } from "react";
import { useState } from "react";
import { Flight } from "../Types";
import { fetchZones } from "../Api";
import { Stores, addData, deleteData, getStoreData, updateData, initDB } from '../db';
export const useFetchOrigin = (origin: string | undefined) => {
const [error, setError] = useState<string | null>(null);
const [zones, setZones] = useState<Flight[]>([]);
const isToday = (someDate: Date) => {
let today = new Date();
return someDate.getDate() == today.getDate() &&
someDate.getMonth() == today.getMonth() &&
someDate.getFullYear() == today.getFullYear()
}
useEffect(() => {
const intervalId = setInterval(() => {
let today = localStorage.getItem('date')
if (today && !isToday(new Date(today))) {
getStoreData<Flight>(Stores.Departure)
.then((data) => {
if (data) {
data.map((u) => {
deleteData(Stores.Departure, u.id)
})
}
})
localStorage.setItem('date', new Date().toString())
}
}, 36000)
return () => clearInterval(intervalId);
}, [])
useEffect(() => {
setError(null);
let newUpdate = new Date().toISOString()
localStorage.setItem('date', new Date().toString())
initDB().then((x) => {
console.log(x)
getStoreData<Flight>(Stores.Departure)
.then((data) => {
console.log(data)
if (data && data.length > 0) {
data.sort((a, b) => new Date(a.origin).getTime() - new Date(b.origin).getTime())
setZones(data)
} else {
fetchZones(origin, undefined, null)
.then((data) => {
localStorage.setItem('lastUpdated', newUpdate)
let toAdd: Flight[] = []
data.map((u) => {
if (u.status != 'Deleted') {
addData(Stores.Departure, u)
toAdd.push(u)
}
})
toAdd.sort((a, b) => new Date(a.origin).getTime() - new Date(b.origin).getTime())
setZones(toAdd);
})
.catch((error) => { });
}
})
}
)
}, [origin]);
useEffect(() => {
const intervalId = setInterval(() => {
let lastUpdate = localStorage.getItem('lastUpdated')
let newUpdate = new Date().toISOString()
fetchZones(origin, undefined, lastUpdate)
.then((data) => {
localStorage.setItem('lastUpdated', newUpdate)
let toAdd: Flight[] = []
let toRemove: Flight[] = []
zones.forEach((c, i) => {
let index = data.findIndex(x => x.id === c.id)
if (index >= 0) {
console.log(data[index].departure_time + 'nuevo')
if (data[index].status == 'Deleted' || new Date(data[index].departure_time) < new Date()) {
console.log("sacamos")
toRemove.push(data[index])
deleteData(Stores.Departure, c.id)
} else {
toAdd.push(data[index]);
updateData(Stores.Departure, c.id, data[index])
}
} else {
console.log(new Date(c.departure_time))
if (c.status == 'Deleted' || new Date(c.departure_time) < new Date()) {
console.log("sacamos?")
toRemove.push(c);
deleteData(Stores.Departure, c.id)
} else {
toAdd.push(c);
}
}
});
let filtered = data.filter(o =>
!toAdd.some(b => { return o.id === b.id }) && !toRemove.some(b => { return o.id === b.id }) && !(new Date(o.departure_time) < new Date())
)
const newArray = toAdd.concat(filtered);
console.log(filtered)
console.log(newArray)
filtered.forEach(c => {
addData(Stores.Departure, c)
})
newArray.sort((a, b) => new Date(a.origin).getTime() - new Date(b.origin).getTime())
setZones(newArray);
})
.catch((error) => {
if (!!error.isAxiosError && !error.response) {
//
}
});
}, 5000)
return () => clearInterval(intervalId);
}, [origin, zones])
return { zones, error };
};

View File

@ -1,90 +0,0 @@
import React, { useEffect } from "react";
import { useState } from "react";
import { User, Flight } from "../Types";
import { fetchZones } from "../Api";
import { Stores, addData, deleteData, getStoreData, updateData, initDB } from '../db';
export const useFetchZones = () => {
const [error, setError] = useState<string | null>(null);
const [zones, setZones] = useState<Flight[]>([]);
let origin = process.env.REACT_APP_ORIGIN;
useEffect(() => {
setError(null);
let newUpdate = new Date().toISOString()
getStoreData<Flight>(Stores.Flight)
.then((data) => {
console.log(data)
if (data && data.length > 0) {
setZones(data)
} else {
fetchZones(origin, null)
.then((data) => {
localStorage.setItem('lastUpdated', newUpdate)
let toAdd: Flight[] = []
data.map((u) => {
if (u.status != 'Deleted') {
addData(Stores.Flight, u)
toAdd.push(u)
}
})
setZones(toAdd);
})
.catch((error) => {});
}
})
}, [origin]);
useEffect(() => {
const intervalId = setInterval(() => {
let lastUpdate = localStorage.getItem('lastUpdated')
let newUpdate = new Date().toISOString()
fetchZones(origin, lastUpdate)
.then((data) => {
localStorage.setItem('lastUpdated', newUpdate)
let toAdd: Flight[] = []
let toRemove: Flight[] = []
zones.forEach((c, i) => {
let index = data.findIndex(x => x.id === c.id)
if (index >= 0) {
console.log(data[index].status)
if (data[index].status == 'Deleted') {
console.log("sacamos")
toRemove.push(data[index])
deleteData(Stores.Flight, c.id)
} else {
toAdd.push(data[index]);
updateData(Stores.Flight, c.id, data[index])
}
} else {
if (c.status == 'Deleted') {
toRemove.push(c);
} else {
toAdd.push(c);
}
}
});
console.log(toAdd)
console.log(toRemove)
let filtered = data.filter(o => !toAdd.some(b => { return o.id === b.id}) && !toRemove.some(b => { return o.id === b.id}))
const newArray = toAdd.concat(filtered);
filtered.forEach(c => {
addData(Stores.Flight, c)
})
setZones(newArray);
})
.catch((error) => {});
}, 5000)
return () => clearInterval(intervalId);
}, [origin, zones])
return { zones, error };
};

View File

@ -3,9 +3,10 @@ import { useState } from "react";
import { ping } from "../Api";
export const useIsConnected = () => {
const [connected, setConnected] = useState(false);
const [connected, setConnected] = useState(true);
useEffect(() => {
const interval = setInterval(() => {
ping()
.then(() => {
setConnected(true);
@ -13,6 +14,9 @@ export const useIsConnected = () => {
.catch(() => {
setConnected(false);
});
}, 5000);
return () => clearInterval(interval);
}, []);
return (

View File

@ -0,0 +1,77 @@
const request = require('supertest');
const app = 'http://127.0.0.1:5000'
const authCredentials = {
email: 'info@lufthansa.com',
password: 'password1234',
};
describe('Flight API Endpoints', () => {
let authToken;
beforeAll(async () => {
const loginResponse = await request(app)
.post('/auth/login')
.send(authCredentials);
expect(loginResponse.statusCode).toBe(200);
expect(loginResponse.body).toHaveProperty('access_token');
authToken = loginResponse.body.access_token;
});
it('should create a new flight', async () => {
const newFlight = {
"flight_code": "ABC127",
"status": "En ruta",
"origin": "Frankfurt",
"destination": "Ciudad A",
"departure_time": "2023-10-29 09:57 PM",
"arrival_time": "2023-10-30 12:00 PM",
"gate": "A2"
};
const response = await request(app)
.post('/flights')
.send(newFlight)
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('id');
createdFlightId = response.body.id;
});
it('should retrieve the created flight by ID', async () => {
const response = await request(app)
.get(`/flights/${createdFlightId}`)
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('id', createdFlightId);
});
it('should update a flight by ID', async () => {
const flightUpdate = {
"status": "Delayed"
};
const response = await request(app)
.patch(`/flights/${createdFlightId}`)
.send(flightUpdate)
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('id');
expect(response.body.status).toBe('Delayed');
});
it('should retrieve filtered flights', async () => {
const response = await request(app)
.get('/flights')
.query({ origin: 'Frankfurt' })
.set('Authorization', `Bearer ${authToken}`);
expect(response.statusCode).toBe(200);
expect(response.body).toBeInstanceOf(Array);
expect(response.body[0].id).toBe(createdFlightId)
});
});

View File

@ -1,8 +1,7 @@
#!/bin/bash
curl -X DELETE api:5000/ping
curl -X POST api:5000/ping
# npm test
echo "NPM TEST"
if [ "${TEST_TARGET:-}" = "INTEGRATION" ]; then
npm run test:integration
else
npm run test
fi