-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(apps): Adopt Nest monorepo structure to allow module sharing (…
…#1078) * refactor(apps): adopt Nest monorepo structure for code sharing between apps * refactor(apps): point clean script to apps/dist * refactor(apps): remove redundant paths from tsconfig * refactor(apps): generalise tsconfig and jest moduleNameMapper * refactor(apps): remove redundant compilerOptions * refactor(apps): reinstate paths mapping in compilerOptions so IDE doesn't complain * chore(apps): bump typeorm * chore(apps): add testcontainers devDependency - accidentally dropped from merging main into branch * refactor(apps): update package-lock.json * refactor(apps): remove website from lerna packages * refactor(apps): change apps library prefix * refactor(apps): move IDEA ide .run config into .idea * refactor(apps): remove unnecessary start commands
- Loading branch information
Showing
28 changed files
with
2,334 additions
and
1,436 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
205 changes: 205 additions & 0 deletions
205
apps/libs/actuator/__tests__/ActuatorController.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import { Test } from '@nestjs/testing' | ||
import { HealthIndicatorResult } from '@nestjs/terminus' | ||
import { ActuatorController, ActuatorModule, ActuatorProbes, ProbeIndicator } from '../src' | ||
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify' | ||
import { Module } from '@nestjs/common' | ||
|
||
describe('ActuatorController - Healthy service', () => { | ||
/** | ||
* Simulate a service that has dead simple health indicators | ||
*/ | ||
class HealthyServiceProbe extends ProbeIndicator { | ||
async liveness (): Promise<HealthIndicatorResult> { | ||
return this.withAlive('healthyService', { livenessDetail: 100 }) | ||
} | ||
|
||
async readiness (): Promise<HealthIndicatorResult> { | ||
return this.withAlive('healthyService', { readinessDetail: 200 }) | ||
} | ||
} | ||
|
||
/** | ||
* Some module whose health needs to be probed. | ||
* onApplicationBootstrap hook gives us the appropriate app lifecycle stage | ||
* to register the probe. | ||
*/ | ||
@Module({ providers: [HealthyServiceProbe] }) | ||
class HealthyServiceActuatorModule { | ||
constructor ( | ||
private readonly probes: ActuatorProbes, | ||
private readonly probe: HealthyServiceProbe) { | ||
} | ||
|
||
async onApplicationBootstrap (): Promise<void> { | ||
this.probes.add(this.probe) | ||
} | ||
} | ||
|
||
let app: NestFastifyApplication | ||
|
||
beforeAll(async () => { | ||
const moduleRef = await Test.createTestingModule({ | ||
imports: [ | ||
HealthyServiceActuatorModule, | ||
ActuatorModule | ||
], | ||
providers: [HealthyServiceProbe], | ||
controllers: [ActuatorController] | ||
}).compile() | ||
|
||
app = moduleRef.createNestApplication<NestFastifyApplication>(new FastifyAdapter({ logger: false })) | ||
await app.init() | ||
}) | ||
|
||
afterAll(async () => { | ||
await app.close() | ||
}) | ||
|
||
it('/_actuator/probes/liveness healthy', async () => { | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/_actuator/probes/liveness' | ||
}) | ||
|
||
expect(response.json()).toStrictEqual({ | ||
details: { | ||
healthyService: { | ||
livenessDetail: 100, | ||
status: 'up' | ||
} | ||
}, | ||
error: {}, | ||
info: { | ||
healthyService: { | ||
livenessDetail: 100, | ||
status: 'up' | ||
} | ||
}, | ||
status: 'ok' | ||
}) | ||
}) | ||
|
||
it('/_actuator/probes/readiness healthy', async () => { | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/_actuator/probes/readiness' | ||
}) | ||
|
||
expect(response.json()).toStrictEqual({ | ||
details: { | ||
healthyService: { | ||
readinessDetail: 200, | ||
status: 'up' | ||
} | ||
}, | ||
error: {}, | ||
info: { | ||
healthyService: { | ||
readinessDetail: 200, | ||
status: 'up' | ||
} | ||
}, | ||
status: 'ok' | ||
}) | ||
}) | ||
}) | ||
|
||
describe('ActuatorController - Unhealthy service', () => { | ||
/** | ||
* Simulate a service that has dead simple health indicators | ||
*/ | ||
class UnhealthyServiceProbe extends ProbeIndicator { | ||
async liveness (): Promise<HealthIndicatorResult> { | ||
return this.withDead('unhealthyService', 'some causative message', { livenessDetail: 0 }) | ||
} | ||
|
||
async readiness (): Promise<HealthIndicatorResult> { | ||
return this.withDead('unhealthyService', 'some causative message', { readinessDetail: 1 }) | ||
} | ||
} | ||
|
||
/** | ||
* Some module whose health needs to be probed. | ||
* onApplicationBootstrap hook gives us the appropriate app lifecycle stage | ||
* to register the probe. | ||
*/ | ||
@Module({ providers: [UnhealthyServiceProbe] }) | ||
class UnhealthyServiceActuatorModule { | ||
constructor ( | ||
private readonly probes: ActuatorProbes, | ||
private readonly probe: UnhealthyServiceProbe) { | ||
} | ||
|
||
async onApplicationBootstrap (): Promise<void> { | ||
this.probes.add(this.probe) | ||
} | ||
} | ||
|
||
let app: NestFastifyApplication | ||
|
||
beforeAll(async () => { | ||
const moduleRef = await Test.createTestingModule({ | ||
imports: [ | ||
UnhealthyServiceActuatorModule, | ||
ActuatorModule | ||
], | ||
providers: [UnhealthyServiceProbe], | ||
controllers: [ActuatorController] | ||
}).compile() | ||
|
||
app = moduleRef.createNestApplication<NestFastifyApplication>(new FastifyAdapter({ logger: false })) | ||
await app.init() | ||
}) | ||
|
||
afterAll(async () => { | ||
await app.close() | ||
}) | ||
|
||
it('/_actuator/probes/liveness unhealthy', async () => { | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/_actuator/probes/liveness' | ||
}) | ||
|
||
expect(response.json()).toStrictEqual({ | ||
details: { | ||
unhealthyService: { | ||
livenessDetail: 0, | ||
status: 'down' | ||
} | ||
}, | ||
error: { | ||
unhealthyService: { | ||
livenessDetail: 0, | ||
status: 'down' | ||
} | ||
}, | ||
info: {}, | ||
status: 'error' | ||
}) | ||
}) | ||
|
||
it('/_actuator/probes/readiness unhealthy', async () => { | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/_actuator/probes/readiness' | ||
}) | ||
|
||
expect(response.json()).toStrictEqual({ | ||
details: { | ||
unhealthyService: { | ||
readinessDetail: 1, | ||
status: 'down' | ||
} | ||
}, | ||
error: { | ||
unhealthyService: { | ||
readinessDetail: 1, | ||
status: 'down' | ||
} | ||
}, | ||
info: {}, | ||
status: 'error' | ||
}) | ||
}) | ||
}) |
2 changes: 1 addition & 1 deletion
2
...api/src/controllers/ActuatorController.ts → apps/libs/actuator/src/ActuatorController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './ActuatorModule' | ||
export * from './ActuatorController' | ||
export * from './BlockchainCppModule' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"outDir": "../../dist/libs/actuator" | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "dist", "test", "**/*test.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"collection": "@nestjs/schematics", | ||
"monorepo": true, | ||
"compilerOptions": { | ||
"tsConfigPath": "tsconfig.json" | ||
}, | ||
"projects": { | ||
"legacy-api": { | ||
"type": "application", | ||
"root": "legacy-api", | ||
"entryFile": "apps/legacy-api/src/index", | ||
"sourceRoot": "legacy-api/src" | ||
}, | ||
"ocean-api": { | ||
"type": "application", | ||
"root": "ocean-api", | ||
"entryFile": "apps/ocean-api/src/index", | ||
"sourceRoot": "ocean-api/src" | ||
}, | ||
"rich-list-api": { | ||
"type": "application", | ||
"root": "rich-list-api", | ||
"entryFile": "apps/rich-list-api/src/index", | ||
"sourceRoot": "rich-list-api/src" | ||
}, | ||
"actuator": { | ||
"type": "library", | ||
"root": "libs/actuator", | ||
"entryFile": "index", | ||
"sourceRoot": "libs/actuator/src", | ||
"compilerOptions": { | ||
"tsConfigPath": "libs/actuator/tsconfig.lib.json" | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.