Skip to content

Commit

Permalink
Add mocking option to module configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Nov 3, 2024
1 parent ff1370e commit cae9619
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dev/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { SomeModule } from "./some/some.module";
callbackUrl: "http://localhost:3000/sso/callback",
scopes: ["esi-characters.read_titles.v1"],
}),
CloneBayModule.forRoot({}),
CloneBayModule.forRoot({ unsafeEnableMocking: true }),
CloneBaySsoModule,
CloneBayResolversModule,
SomeModule,
Expand Down
11 changes: 11 additions & 0 deletions lib/src/clone-bay-module-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ export interface CloneBayModuleOptions {
*/
esiBaseUrl?: string;

/**
* Enable mocking for testing and development.
*
* **DO NOT ENABLE IN PRODUCTION!**
*
* Turning this on will cause the mocking module to be loaded which will mount
* REST endpoints that will enable anyone to trivially take over your
* application if it is connectable.
*/
unsafeEnableMocking?: boolean;

/**
* Override dynamic configuration values.
*
Expand Down
5 changes: 4 additions & 1 deletion lib/src/config/module-config.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsUrl } from "class-validator";
import { IsBoolean, IsUrl } from "class-validator";
import { DynamicConfig } from "./dynamic-config.model";

/** `CloneBayModule` static configuration. */
Expand All @@ -21,5 +21,8 @@ export class ModuleConfig {
})
esiBaseUrl = "https://esi.evetech.net";

@IsBoolean()
unsafeEnableMocking = false;

dynamicConfigOverride?: Partial<DynamicConfig> = {};
}
1 change: 1 addition & 0 deletions lib/test/mocks/mock-module-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { provideMockService } from "./mock-services";
export const defaultMockConfiguration: ModuleConfig = {
afterLoginUrl: "/",
esiBaseUrl: "",
unsafeEnableMocking: false,
};

export const provideMockModuleConfigService = (
Expand Down

0 comments on commit cae9619

Please sign in to comment.