Skip to content

Commit

Permalink
Export mocking module instead of mounting via env var
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Nov 6, 2024
1 parent cae428e commit 37c762a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "npm run install:local && UNSAFE_MOCKING_ENABLED=true nest start --watch --preserveWatchOutput",
"start:dev": "npm run install:local && nest start --watch --preserveWatchOutput",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
Expand Down
2 changes: 2 additions & 0 deletions dev/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
import {
CloneBayMockingModule,
CloneBayModule,
CloneBayResolversModule,
CloneBaySsoModule,
Expand Down Expand Up @@ -40,6 +41,7 @@ import { SomeModule } from "./some/some.module";
CloneBaySsoModule,
CloneBayResolversModule,
SomeModule,
CloneBayMockingModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
2 changes: 2 additions & 0 deletions dev/src/some/some.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
CloneBayEsiApiService,
CloneBayMockingModule,
CloneBayUserService,
} from "@joonashak/nestjs-clone-bay";
import { Module } from "@nestjs/common";
Expand All @@ -13,6 +14,7 @@ import { SomeService } from "./some.service";
@Module({
imports: [
MongooseModule.forFeature([{ name: Some.name, schema: SomeSchema }]),
CloneBayMockingModule,
],
providers: [
SomeService,
Expand Down
6 changes: 5 additions & 1 deletion dev/src/some/some.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { CloneBayEsiApiService } from "@joonashak/nestjs-clone-bay";
import {
CloneBayEsiApiService,
CloneBayMockingService,
} from "@joonashak/nestjs-clone-bay";
import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { Model } from "mongoose";
Expand All @@ -9,6 +12,7 @@ export class SomeService {
constructor(
@InjectModel(Some.name) private someModel: Model<SomeDocument>,
private apiService: CloneBayEsiApiService,
private mockingService: CloneBayMockingService,
) {}

async findAll() {
Expand Down
10 changes: 10 additions & 0 deletions lib/src/api/clone-bay-mocking-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from "@nestjs/common";
import { MockingModule } from "../mocking/mocking.module";
import { CloneBayMockingService } from "./clone-bay-mocking.service";

@Module({
imports: [MockingModule],
providers: [CloneBayMockingService],
exports: [CloneBayMockingService],
})
export class CloneBayMockingModule {}
16 changes: 16 additions & 0 deletions lib/src/api/clone-bay-mocking.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Injectable } from "@nestjs/common";
import { User } from "../entities/user/user.model";
import { MockingService } from "../mocking/mocking.service";

@Injectable()
export class CloneBayMockingService {
constructor(private mockingService: MockingService) {}

async createUser(user: Omit<User, "id">) {
return this.mockingService.createUser(user);
}

async loginWithEveId(session: unknown, eveId: number) {
return this.mockingService.loginWithEveId(session, eveId);
}
}
2 changes: 0 additions & 2 deletions lib/src/clone-bay.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
CLONE_BAY_MODULE_OPTIONS_TOKEN,
CloneBayModuleDefinition,
} from "./clone-bay.module-definition";
import { conditionalModules } from "./conditional-modules";
import { ConfigModule } from "./config/config.module";
import { CharacterModule } from "./entities/character/character.module";
import { UserModule } from "./entities/user/user.module";
Expand All @@ -28,7 +27,6 @@ import { EsiModule } from "./esi/esi.module";
SsoModule,
UserModule,
AuthenticatedEsiApiModule,
...conditionalModules(),
],
exports: [
CLONE_BAY_MODULE_OPTIONS_TOKEN,
Expand Down
14 changes: 0 additions & 14 deletions lib/src/conditional-modules.spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions lib/src/conditional-modules.ts

This file was deleted.

2 changes: 2 additions & 0 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export { CloneBayConfigService } from "./api/clone-bay-config.service";
export { CloneBayEsiApiService } from "./api/clone-bay-esi-api.service";
export { CloneBayMockingModule } from "./api/clone-bay-mocking-module";
export { CloneBayMockingService } from "./api/clone-bay-mocking.service";
export { CloneBayResolversModule } from "./api/clone-bay-resolvers.module";
export { CloneBaySsoModule } from "./api/clone-bay-sso.module";
export { CloneBayUserService } from "./api/clone-bay-user.service";
Expand Down
1 change: 1 addition & 0 deletions lib/src/mocking/mocking.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MockingService } from "./mocking.service";
@Module({
providers: [MockingService],
controllers: [MockingController],
exports: [MockingService],
})
export class MockingModule implements OnModuleInit {
private readonly logger = new Logger(MockingModule.name);
Expand Down

0 comments on commit 37c762a

Please sign in to comment.