diff --git a/compose.ci.yaml b/compose.ci.yaml deleted file mode 100644 index 63100579..00000000 --- a/compose.ci.yaml +++ /dev/null @@ -1,40 +0,0 @@ -services: - server: - build: . - container_name: holenav-server-ci - networks: - - ci - environment: - - NODE_ENV=test - - PORT=3001 - - MONGO_URL=mongodb://mongo/ci - - CLIENT_URL=http://web:5173 - - JWT_SECRET=asdasd - - ENABLE_DEVTOOLS=true - - SSO_CLIENT_ID=asd - - SSO_SECRET_KEY=asd - - SSO_CALLBACK_URL=asd - - SESSION_SECRET=dsqefw - depends_on: - - mongo - - web: - extends: - file: compose.common.yaml - service: web-base - container_name: holenav-web-ci - networks: - - ci - environment: - - VITE_BACKEND_URL=http://server:3001 - - mongo: - extends: - file: compose.common.yaml - service: mongo-base - container_name: holenav-mongo-ci - networks: - - ci - -networks: - ci: diff --git a/compose.yaml b/compose.yaml index c884c0dc..0123a9d1 100644 --- a/compose.yaml +++ b/compose.yaml @@ -30,6 +30,7 @@ services: - NODE_ENV=development - MONGO_URL=mongodb://mongo/holenav - CLIENT_URL=http://localhost:3000 + - SSO_CALLBACK_URL=http://localhost:3001/sso/callback env_file: - .env.development depends_on: @@ -41,14 +42,19 @@ services: service: server-base container_name: holenav-server-test ports: - - 4001:3001 + - 4001:4001 environment: - - NODE_ENV=test + - PORT=4001 + - NODE_ENV=development - MONGO_URL=mongodb://mongo/holenav-test - CLIENT_URL=http://localhost:4000 - SSO_CLIENT_ID=asd - SSO_SECRET_KEY=asd - - SSO_CALLBACK_URL=asd + - SSO_CALLBACK_URL=http://localhost:4001/sso/callback + - TOKEN_URL=http://mock-esi:4200/oauth/token + - VERIFY_URL=http://mock-esi:4200/oauth/verify + - ESI_BASE_URL=http://mock-esi:4200 + - AUTHORIZATION_URL=http://localhost:4001/sso/callback?code=asd depends_on: - mongo @@ -63,5 +69,14 @@ services: volume: nocopy: true + mock-esi: + image: mockoon/cli + container_name: beancounter-mock-esi + ports: + - 4200:4200 + volumes: + - ./testing/mock-esi:/data + command: "--port 4200 --data /data/mockoon.config.json" + volumes: mongo-data: diff --git a/package.json b/package.json index 4837f8b5..91f57668 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ }, "scripts": { "start": "docker compose up -d mongo server web && npm run logs", - "start:test": "docker compose up -d mongo server-test web-test", - "stop": "docker compose down && docker compose -f compose.ci.yaml down", + "start:test": "docker compose up -d mongo mock-esi server-test web-test", + "stop": "docker compose down", "logs": "docker compose logs -f server web", "logs:all": "docker compose logs -f", "test": "npm run lint && npm run test:server", diff --git a/server/package-lock.json b/server/package-lock.json index c58c557d..1e657ed9 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -14,7 +14,7 @@ "@eve-data/systems": "^3.1.0", "@eve-data/wormholes": "^0.0.8", "@joonashak/nestjs-clone-bay": "^0.0.12", - "@joonashak/nestjs-eve-auth": "^0.3.1", + "@joonashak/nestjs-eve-auth": "^0.3.2", "@nestjs/apollo": "^12.0.7", "@nestjs/axios": "^3.0.2", "@nestjs/cache-manager": "^2.2.2", @@ -1980,9 +1980,9 @@ } }, "node_modules/@joonashak/nestjs-eve-auth": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@joonashak/nestjs-eve-auth/-/nestjs-eve-auth-0.3.1.tgz", - "integrity": "sha512-/UwA4rHqA4ioAOKumg3n54Oi3z+Fgo+5PgOIcfBIdNm4P2uOsC+a9aK+pktbU7kUJBr567IHt/+NlPli8WKX/g==", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@joonashak/nestjs-eve-auth/-/nestjs-eve-auth-0.3.2.tgz", + "integrity": "sha512-mHM6R/ZnC7qaQO9XtdS9I7X16gkOnfcHkDELLFVjAay8egC0tauEeFSWev5Xnwzx/EHFqOGCIda6gVWysbUIIQ==", "dependencies": { "@nestjs/passport": "^10.0.0", "@nestjs/platform-express": "^10.0.0", @@ -11760,9 +11760,9 @@ } }, "@joonashak/nestjs-eve-auth": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@joonashak/nestjs-eve-auth/-/nestjs-eve-auth-0.3.1.tgz", - "integrity": "sha512-/UwA4rHqA4ioAOKumg3n54Oi3z+Fgo+5PgOIcfBIdNm4P2uOsC+a9aK+pktbU7kUJBr567IHt/+NlPli8WKX/g==", + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@joonashak/nestjs-eve-auth/-/nestjs-eve-auth-0.3.2.tgz", + "integrity": "sha512-mHM6R/ZnC7qaQO9XtdS9I7X16gkOnfcHkDELLFVjAay8egC0tauEeFSWev5Xnwzx/EHFqOGCIda6gVWysbUIIQ==", "requires": { "@nestjs/passport": "^10.0.0", "@nestjs/platform-express": "^10.0.0", diff --git a/server/package.json b/server/package.json index 57c759ac..006b6b4f 100644 --- a/server/package.json +++ b/server/package.json @@ -27,7 +27,7 @@ "@eve-data/systems": "^3.1.0", "@eve-data/wormholes": "^0.0.8", "@joonashak/nestjs-clone-bay": "^0.0.12", - "@joonashak/nestjs-eve-auth": "^0.3.1", + "@joonashak/nestjs-eve-auth": "^0.3.2", "@nestjs/apollo": "^12.0.7", "@nestjs/axios": "^3.0.2", "@nestjs/cache-manager": "^2.2.2", diff --git a/server/src/app.module.ts b/server/src/app.module.ts index bf1cd35c..794b94f9 100644 --- a/server/src/app.module.ts +++ b/server/src/app.module.ts @@ -26,6 +26,10 @@ import { EsiModule } from "./esi/esi.module"; import { FrontendModule } from "./frontend/frontend.module"; import graphQlModuleConfig from "./graphql-module-config"; import { ScheduledTasksModule } from "./scheduled-tasks/scheduled-tasks.module"; +import { + getCloneBayMockingOptions, + getEveAuthMockingOptions, +} from "./test-utils/mock-esi-config"; import { UserPreferencesModule } from "./user/user-preferences/user-preferences.module"; @Module({ @@ -35,6 +39,7 @@ import { UserPreferencesModule } from "./user/user-preferences/user-preferences. BootstrapModule, CloneBayModule.forRoot({ afterLoginUrl: CLIENT_URL, + ...getCloneBayMockingOptions(), }), CloneBayResolversModule, CloneBaySsoModule, @@ -46,6 +51,7 @@ import { UserPreferencesModule } from "./user/user-preferences/user-preferences. secretKey: SSO_SECRET_KEY, callbackUrl: SSO_CALLBACK_URL, scopes: ["esi-search.search_structures.v1"], + ...getEveAuthMockingOptions(), }), FolderAccessControlModule, FrontendModule, diff --git a/server/src/test-utils/mock-esi-config.ts b/server/src/test-utils/mock-esi-config.ts new file mode 100644 index 00000000..79a9c1b3 --- /dev/null +++ b/server/src/test-utils/mock-esi-config.ts @@ -0,0 +1,36 @@ +import { CloneBayModuleOptions } from "@joonashak/nestjs-clone-bay"; +import { EveAuthModuleOptions } from "@joonashak/nestjs-eve-auth"; + +export const getEveAuthMockingOptions = () => { + if (process.env.NODE_ENV !== "development") { + return {}; + } + + const opt: Partial = {}; + + if (process.env.AUTHORIZATION_URL) { + opt.authorizationUrl = process.env.AUTHORIZATION_URL; + } + if (process.env.TOKEN_URL) { + opt.tokenUrl = process.env.TOKEN_URL; + } + if (process.env.VERIFY_URL) { + opt.verifyUrl = process.env.VERIFY_URL; + } + + return opt; +}; + +export const getCloneBayMockingOptions = () => { + if (process.env.NODE_ENV !== "development") { + return {}; + } + + const opt: Partial = {}; + + if (process.env.ESI_BASE_URL) { + opt.esiBaseUrl = process.env.ESI_BASE_URL; + } + + return opt; +}; diff --git a/testing/mock-esi/mockoon.config.json b/testing/mock-esi/mockoon.config.json new file mode 100644 index 00000000..3ba014cd --- /dev/null +++ b/testing/mock-esi/mockoon.config.json @@ -0,0 +1,191 @@ +{ + "uuid": "97bab060-ed70-4238-91bc-f9519288a746", + "lastMigration": 32, + "name": "mock-esi (holenav)", + "endpointPrefix": "", + "latency": 0, + "port": 4200, + "hostname": "", + "folders": [], + "routes": [ + { + "uuid": "1ddf6a4f-187e-4804-b2bc-74ba23b85838", + "type": "http", + "documentation": "", + "method": "post", + "endpoint": "oauth/token", + "responses": [ + { + "uuid": "71296b32-cb5a-49a5-b9d8-c8b918d9ef8d", + "body": "{\n \"access_token\": \"asd\",\n \"refresh_token\": \"dsa\"\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null + }, + { + "uuid": "c995e088-b71e-4f91-8c47-efacde74e92c", + "type": "http", + "documentation": "", + "method": "get", + "endpoint": "oauth/verify", + "responses": [ + { + "uuid": "1df8ba17-db4a-457f-8f78-64341eb8faf3", + "body": "{\n \"CharacterID\": 123,\n \"CharacterName\": \"E2E\",\n \"ExpiresOn\": \"\",\n \"Scopes\": \"\",\n \"TokenType\": \"\",\n \"CharacterOwnerHash\": \"\",\n \"IntellectualProperty\": \"\"\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null + }, + { + "uuid": "a542a678-423c-47d3-b507-82db476a545e", + "type": "http", + "documentation": "", + "method": "get", + "endpoint": "v5/characters/123", + "responses": [ + { + "uuid": "27827ed9-291c-40be-af9e-ed11535fc805", + "body": "{\n \"birthday\": \"asd\",\n \"bloodline_id\": 123,\n \"corporation_id\": 123,\n \"gender\": \"male\",\n \"name\": \"E2E Character\",\n \"race_id\": 123\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null + }, + { + "uuid": "5b5fd662-d5c0-4a1f-9aaa-d2109d3bb40d", + "type": "http", + "documentation": "", + "method": "get", + "endpoint": "v5/corporations/123", + "responses": [ + { + "uuid": "90fadb5a-6b55-42f2-883b-55c0de7bbe49", + "body": "{\n \"ceo_id\": 123,\n \"creator_id\": 123,\n \"member_count\": 1,\n \"name\": \"E2E Corporation\",\n \"tax_rate\": 0,\n \"ticker\": \"TEST\"\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null + } + ], + "rootChildren": [ + { + "type": "route", + "uuid": "1ddf6a4f-187e-4804-b2bc-74ba23b85838" + }, + { + "type": "route", + "uuid": "c995e088-b71e-4f91-8c47-efacde74e92c" + }, + { + "type": "route", + "uuid": "a542a678-423c-47d3-b507-82db476a545e" + }, + { + "type": "route", + "uuid": "5b5fd662-d5c0-4a1f-9aaa-d2109d3bb40d" + } + ], + "proxyMode": false, + "proxyHost": "", + "proxyRemovePrefix": false, + "tlsOptions": { + "enabled": false, + "type": "CERT", + "pfxPath": "", + "certPath": "", + "keyPath": "", + "caPath": "", + "passphrase": "" + }, + "cors": true, + "headers": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*" + }, + { + "key": "Access-Control-Allow-Methods", + "value": "GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS" + }, + { + "key": "Access-Control-Allow-Headers", + "value": "Content-Type, Origin, Accept, Authorization, Content-Length, X-Requested-With" + } + ], + "proxyReqHeaders": [ + { + "key": "", + "value": "" + } + ], + "proxyResHeaders": [ + { + "key": "", + "value": "" + } + ], + "data": [], + "callbacks": [] +} \ No newline at end of file