diff --git a/apps/api/src/api.controller.spec.ts b/apps/api/src/api.controller.spec.ts index 9d15d03..635f08e 100644 --- a/apps/api/src/api.controller.spec.ts +++ b/apps/api/src/api.controller.spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from "@nestjs/testing"; +import { EvmProviderService } from "@packages/providers"; import { ApiController } from "./api.controller"; -import { ApiService } from "./api.service"; describe("ApiController", () => { let apiController: ApiController; @@ -9,15 +9,15 @@ describe("ApiController", () => { beforeEach(async () => { const app: TestingModule = await Test.createTestingModule({ controllers: [ApiController], - providers: [ApiService], + providers: [EvmProviderService], }).compile(); apiController = app.get(ApiController); }); describe("root", () => { - it('should return "Hello World!"', () => { - expect(apiController.getHello()).toBe("Hello World!"); + it("should return 1", async () => { + expect(await apiController.getTvl()).toBe(1); }); }); }); diff --git a/apps/api/src/api.controller.ts b/apps/api/src/api.controller.ts index 53a4e1e..f749e01 100644 --- a/apps/api/src/api.controller.ts +++ b/apps/api/src/api.controller.ts @@ -1,13 +1,12 @@ import { Controller, Get } from "@nestjs/common"; - -import { ApiService } from "./api.service"; +import { EvmProviderService } from "@packages/providers"; @Controller() export class ApiController { - constructor(private readonly apiService: ApiService) {} + constructor(private readonly evmProvider: EvmProviderService) {} @Get() - getHello(): string { - return this.apiService.getHello(); + getTvl() { + return this.evmProvider.getTvl(); } } diff --git a/apps/api/src/api.module.ts b/apps/api/src/api.module.ts index b94af93..bd87eed 100644 --- a/apps/api/src/api.module.ts +++ b/apps/api/src/api.module.ts @@ -1,11 +1,11 @@ import { Module } from "@nestjs/common"; +import { ProvidersModule } from "@packages/providers"; import { ApiController } from "./api.controller"; -import { ApiService } from "./api.service"; @Module({ - imports: [], + imports: [ProvidersModule], controllers: [ApiController], - providers: [ApiService], + providers: [], }) export class ApiModule {} diff --git a/apps/api/src/api.service.ts b/apps/api/src/api.service.ts deleted file mode 100644 index f515d36..0000000 --- a/apps/api/src/api.service.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Injectable } from "@nestjs/common"; - -@Injectable() -export class ApiService { - getHello(): string { - return "Hello World!"; - } -} diff --git a/apps/api/test/app.e2e-spec.ts b/apps/api/test/app.e2e-spec.ts index 196bc57..d2c2dc3 100644 --- a/apps/api/test/app.e2e-spec.ts +++ b/apps/api/test/app.e2e-spec.ts @@ -17,6 +17,6 @@ describe("ApiController (e2e)", () => { }); it("/ (GET)", () => { - return request(app.getHttpServer()).get("/").expect(200).expect("Hello World!"); + return request(app.getHttpServer()).get("/").expect(200).expect("1"); }); }); diff --git a/libs/providers/src/evmProvider.service.spec.ts b/libs/providers/src/evmProvider.service.spec.ts new file mode 100644 index 0000000..b918c37 --- /dev/null +++ b/libs/providers/src/evmProvider.service.spec.ts @@ -0,0 +1,24 @@ +import { Test, TestingModule } from "@nestjs/testing"; + +import { EvmProviderService } from "./evmProvider.service"; + +describe("EvmProviderService", () => { + let service: EvmProviderService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [EvmProviderService], + }).compile(); + + service = module.get(EvmProviderService); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); + + it("should return the correct TVL", async () => { + const tvl = await service.getTvl(); + expect(tvl).toBe(1); + }); +}); diff --git a/libs/providers/src/evmProvider.service.ts b/libs/providers/src/evmProvider.service.ts new file mode 100644 index 0000000..d828acc --- /dev/null +++ b/libs/providers/src/evmProvider.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from "@nestjs/common"; + +@Injectable() +export class EvmProviderService { + async getTvl() { + return 1; + } +} diff --git a/libs/providers/src/index.ts b/libs/providers/src/index.ts new file mode 100644 index 0000000..917ae50 --- /dev/null +++ b/libs/providers/src/index.ts @@ -0,0 +1,2 @@ +export * from "./providers.module"; +export * from "./evmProvider.service"; diff --git a/libs/providers/src/providers.module.ts b/libs/providers/src/providers.module.ts new file mode 100644 index 0000000..686bcbf --- /dev/null +++ b/libs/providers/src/providers.module.ts @@ -0,0 +1,9 @@ +import { Module } from "@nestjs/common"; + +import { EvmProviderService } from "./evmProvider.service"; + +@Module({ + providers: [EvmProviderService], + exports: [EvmProviderService], +}) +export class ProvidersModule {} diff --git a/libs/providers/tsconfig.lib.json b/libs/providers/tsconfig.lib.json new file mode 100644 index 0000000..d17b0db --- /dev/null +++ b/libs/providers/tsconfig.lib.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "../../dist/libs/providers" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/nest-cli.json b/nest-cli.json index 05f0b14..c4542ba 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -18,6 +18,15 @@ "compilerOptions": { "tsConfigPath": "apps/api/tsconfig.app.json" } + }, + "providers": { + "type": "library", + "root": "libs/providers", + "entryFile": "index", + "sourceRoot": "libs/providers/src", + "compilerOptions": { + "tsConfigPath": "libs/providers/tsconfig.lib.json" + } } } } diff --git a/package.json b/package.json index 4db2a36..a3f1656 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "license": "UNLICENSED", "scripts": { "build": "nest build", - "format": "prettier --write \"apps/**/*.ts\"", + "format": "prettier --write \"{apps,libs}/**/*.ts\"", "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", @@ -74,8 +74,12 @@ "coverageDirectory": "./coverage", "testEnvironment": "node", "roots": [ - "/apps/" - ] + "/apps/", + "/libs/" + ], + "moduleNameMapper": { + "^@packages/providers(|/.*)$": "/libs/providers/src/$1" + } }, "packageManager": "pnpm@9.5.0+sha1.8c155dc114e1689d18937974f6571e0ceee66f1d", "lint-staged": { diff --git a/tsconfig.json b/tsconfig.json index 4f75e96..1196eab 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,27 @@ { - "extends": "@total-typescript/tsconfig/tsc/no-dom/app", - "compilerOptions": { - "module": "commonjs", - "declaration": true, - "removeComments": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "target": "ES2021", - "sourceMap": true, - "outDir": "./dist", - "baseUrl": "./", - "incremental": true, - "skipLibCheck": true, - "strictNullChecks": true, - "noImplicitAny": true, - "strictBindCallApply": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "paths": {}, - "verbatimModuleSyntax": false, - } -} \ No newline at end of file + "extends": "@total-typescript/tsconfig/tsc/no-dom/app", + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "ES2021", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true, + "strictNullChecks": true, + "noImplicitAny": true, + "strictBindCallApply": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "paths": { + "@packages/providers": ["libs/providers/src"], + "@packages/providers/*": ["libs/providers/src/*"] + }, + "verbatimModuleSyntax": false + } +}