Skip to content

Commit

Permalink
Set up mock ESI for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Oct 26, 2024
1 parent 5e39f87 commit 6cc2599
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 53 deletions.
40 changes: 0 additions & 40 deletions compose.ci.yaml

This file was deleted.

21 changes: 18 additions & 3 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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:
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -35,6 +39,7 @@ import { UserPreferencesModule } from "./user/user-preferences/user-preferences.
BootstrapModule,
CloneBayModule.forRoot({
afterLoginUrl: CLIENT_URL,
...getCloneBayMockingOptions(),
}),
CloneBayResolversModule,
CloneBaySsoModule,
Expand All @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions server/src/test-utils/mock-esi-config.ts
Original file line number Diff line number Diff line change
@@ -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<EveAuthModuleOptions> = {};

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<CloneBayModuleOptions> = {};

if (process.env.ESI_BASE_URL) {
opt.esiBaseUrl = process.env.ESI_BASE_URL;
}

return opt;
};
191 changes: 191 additions & 0 deletions testing/mock-esi/mockoon.config.json
Original file line number Diff line number Diff line change
@@ -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": []
}

0 comments on commit 6cc2599

Please sign in to comment.