Skip to content

Commit

Permalink
Do not name fakes mocks (#298)
Browse files Browse the repository at this point in the history
* refactor: change naming of fakes to fakes

* chore: use the new fakes
  • Loading branch information
jkoenig134 authored Oct 17, 2024
1 parent 968643d commit 755203c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
14 changes: 7 additions & 7 deletions packages/app-runtime/test/lib/TestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import {
import { IConfigOverwrite, TransportLoggerFactory } from "@nmshd/transport";
import { LogLevel } from "typescript-logging";
import { AppConfig, AppRuntime, LocalAccountDTO, LocalAccountSession, createAppConfig as runtime_createAppConfig } from "../../src";
import { NativeBootstrapperMock } from "../mocks/NativeBootstrapperMock";
import { FakeUIBridge } from "./FakeUIBridge";
import { FakeNativeBootstrapper } from "./natives/FakeNativeBootstrapper";

export class TestUtil {
public static async createRuntime(configOverride?: any): Promise<AppRuntime> {
const config = this.createAppConfig(configOverride);

const nativeBootstrapperMock = new NativeBootstrapperMock();
await nativeBootstrapperMock.init();
const runtime = await AppRuntime.create(nativeBootstrapperMock, config);
const nativeBootstrapper = new FakeNativeBootstrapper();
await nativeBootstrapper.init();
const runtime = await AppRuntime.create(nativeBootstrapper, config);
runtime.registerUIBridge(new FakeUIBridge());

return runtime;
Expand All @@ -35,9 +35,9 @@ export class TestUtil {
public static async createRuntimeWithoutInit(configOverride?: any): Promise<AppRuntime> {
const config = this.createAppConfig(configOverride);

const nativeBootstrapperMock = new NativeBootstrapperMock();
await nativeBootstrapperMock.init();
const runtime = new AppRuntime(nativeBootstrapperMock.nativeEnvironment, config);
const nativeBootstrapper = new FakeNativeBootstrapper();
await nativeBootstrapper.init();
const runtime = new AppRuntime(nativeBootstrapper.nativeEnvironment, config);

return runtime;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { EventEmitter2EventBus, Result } from "@js-soft/ts-utils";
import { WebLoggerFactory } from "@js-soft/web-logger";
import { INativeBootstrapper, INativeEnvironment } from "../../src";
import { NativeConfigAccessMock } from "../mocks/NativeConfigAccessMock";
import { NativeDatabaseFactoryMock } from "../mocks/NativeDatabaseFactoryMock";
import { NativeDeviceInfoAccessMock } from "../mocks/NativeDeviceInfoAccessMock";
import { NativeNotificationAccessMock } from "../mocks/NativeNotificationAccessMock";
import { INativeBootstrapper, INativeEnvironment } from "../../../src";
import { FakeNativeConfigAccess } from "./FakeNativeConfigAccess";
import { FakeNativeDatabaseFactory } from "./FakeNativeDatabaseFactory";
import { FakeNativeDeviceInfoAccess } from "./FakeNativeDeviceInfoAccess";
import { FakeNativeNotificationAccess } from "./FakeNativeNotificationAccess";

export class NativeBootstrapperMock implements INativeBootstrapper {
export class FakeNativeBootstrapper implements INativeBootstrapper {
private _nativeEnvironment: INativeEnvironment;
public get nativeEnvironment(): INativeEnvironment {
return this._nativeEnvironment;
Expand All @@ -18,17 +18,17 @@ export class NativeBootstrapperMock implements INativeBootstrapper {

public async init(): Promise<Result<void>> {
const loggerFactory = new WebLoggerFactory();
const nativeLogger = loggerFactory.getLogger("NativeMocks");
const nativeLogger = loggerFactory.getLogger("FakeNatives");

this._nativeEnvironment = {
configAccess: new NativeConfigAccessMock(),
databaseFactory: new NativeDatabaseFactoryMock(),
deviceInfoAccess: new NativeDeviceInfoAccessMock(),
configAccess: new FakeNativeConfigAccess(),
databaseFactory: new FakeNativeDatabaseFactory(),
deviceInfoAccess: new FakeNativeDeviceInfoAccess(),
eventBus: new EventEmitter2EventBus(() => {
// noop
}),
loggerFactory,
notificationAccess: new NativeNotificationAccessMock(nativeLogger)
notificationAccess: new FakeNativeNotificationAccess(nativeLogger)
};

await this._nativeEnvironment.deviceInfoAccess.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Result } from "@js-soft/ts-utils";
import { INativeConfigAccess } from "../../src";
import { INativeConfigAccess } from "../../../src";

export class NativeConfigAccessMock implements INativeConfigAccess {
export class FakeNativeConfigAccess implements INativeConfigAccess {
public config: Record<string, any> = {};

public get(key: string): Result<any> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ILokiJsDatabaseFactory } from "@js-soft/docdb-access-loki";
import loki from "lokijs";

export class NativeDatabaseFactoryMock implements ILokiJsDatabaseFactory {
export class FakeNativeDatabaseFactory implements ILokiJsDatabaseFactory {
public create(name: string, options?: Partial<LokiConstructorOptions> & Partial<LokiConfigOptions> & Partial<ThrottledSaveDrainOptions>): Loki {
return new loki(name, { ...options, persistenceMethod: "memory" });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Result } from "@js-soft/ts-utils";
import { INativeDeviceInfo, INativeDeviceInfoAccess } from "../../src";
import { INativeDeviceInfo, INativeDeviceInfoAccess } from "../../../src";

export class NativeDeviceInfoAccessMock implements INativeDeviceInfoAccess {
export class FakeNativeDeviceInfoAccess implements INativeDeviceInfoAccess {
public get deviceInfo(): INativeDeviceInfo {
return {
uuid: "00000000-7e7a-4e82-bd56-9cdba102ac13",
model: "Mock-Model",
model: "Model",
isVirtual: true,
languageCode: "de",
manufacturer: "Mock-Manufacturer",
platform: "Mock-Platform",
version: "Mock-Version",
manufacturer: "Manufacturer",
platform: "Platform",
version: "Version",
pushService: "dummy"
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { ILogger } from "@js-soft/logging-abstractions";
import { Result } from "@js-soft/ts-utils";
import { INativeNotificationAccess, INativeNotificationScheduleOptions } from "../../src";
import { INativeNotificationAccess, INativeNotificationScheduleOptions } from "../../../src";

export class NativeNotificationAccessMock implements INativeNotificationAccess {
export class FakeNativeNotificationAccess implements INativeNotificationAccess {
public constructor(private readonly logger: ILogger) {}

public schedule(title: string, body: string, options?: INativeNotificationScheduleOptions): Promise<Result<number>> {
this.logger.info(`NativeNotificationAccessMock.schedule(${title},${body},${options})`);
this.logger.info(`NativeNotificationAccess.schedule(${title},${body},${options})`);

return Promise.resolve(Result.ok(0));
}

public update(id: number, title: string, body: string, options?: INativeNotificationScheduleOptions): Promise<Result<void>> {
this.logger.info(`NativeNotificationAccessMock.update(${id},${title},${body},${options})`);
this.logger.info(`NativeNotificationAccess.update(${id},${title},${body},${options})`);
return Promise.resolve(Result.ok(undefined));
}

public clear(id: number): Promise<Result<void>> {
this.logger.info(`NativeNotificationAccessMock.clear(${id})`);
this.logger.info(`NativeNotificationAccess.clear(${id})`);
return Promise.resolve(Result.ok(undefined));
}

public clearAll(): Promise<Result<void>> {
this.logger.info("NativeNotificationAccessMock.clearAll()");
this.logger.info("NativeNotificationAccess.clearAll()");
return Promise.resolve(Result.ok(undefined));
}

public getAll(): Promise<Result<number[]>> {
this.logger.info("NativeNotificationAccessMock.getAll()");
this.logger.info("NativeNotificationAccess.getAll()");
return Promise.resolve(Result.ok([0]));
}

public init(): Promise<Result<void>> {
this.logger.info("NativeNotificationAccessMock.init()");
this.logger.info("NativeNotificationAccess.init()");
return Promise.resolve(Result.ok(undefined));
}
}

0 comments on commit 755203c

Please sign in to comment.