Skip to content

Commit

Permalink
chore: setup aliases in project
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman committed Jan 25, 2024
1 parent 443b107 commit 883dc5c
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 42 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/internal/config/data/ConfigDataSource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Either } from "purify-ts";
import { LocalConfigFailure, RemoteConfigFailure } from "../di/configTypes";
import { Config } from "../model/Config";
import {
LocalConfigFailure,
RemoteConfigFailure,
} from "@internal/config/di/configTypes";
import { Config } from "@internal/config/model/Config";

// Describe the different data sources interfaces our application could have

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { injectable } from "inversify";
import { Config } from "../model/Config";
import { LocalConfigDataSource } from "./ConfigDataSource";
import { Either } from "purify-ts";
import { Config } from "@internal/config/model/Config";
import { LocalConfigDataSource } from "./ConfigDataSource";

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from "fs";
import { Either, Left } from "purify-ts";
import { JSONParseError, ReadFileError } from "@internal/config/di/configTypes";
import { LocalConfigDataSource } from "./ConfigDataSource";
import { FileLocalConfigDataSource } from "./LocalConfigDataSource";
import { Either, Left } from "purify-ts";
import { JSONParseError, ReadFileError } from "../di/configTypes";

const readFileSyncSpy = jest.spyOn(fs, "readFileSync");
const jsonParse = jest.spyOn(JSON, "parse");
Expand All @@ -16,6 +16,11 @@ describe("LocalConfigDataSource", () => {
datasource = new FileLocalConfigDataSource();
});

afterAll(() => {
readFileSyncSpy.mockRestore();
jsonParse.mockRestore();
});

it("should return an Either<never, Config>", () => {
readFileSyncSpy.mockReturnValue(
JSON.stringify({ name: "DeviceSDK", version: "0.0.0-spied.1" })
Expand Down Expand Up @@ -56,9 +61,4 @@ describe("LocalConfigDataSource", () => {
expect(datasource.getConfig()).toEqual(Left(new JSONParseError(err)));
});
});

afterAll(() => {
readFileSyncSpy.mockRestore();
jsonParse.mockRestore();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
ReadFileError,
JSONParseError,
LocalConfigFailure,
} from "../di/configTypes";
import { Config } from "../model/Config";
} from "@internal/config/di/configTypes";
import { Config } from "@internal/config/model/Config";
import { LocalConfigDataSource } from "./ConfigDataSource";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { injectable } from "inversify";
import { RemoteConfigDataSource } from "./ConfigDataSource";
import { Config } from "../model/Config";
import { Either } from "purify-ts";
import { Config } from "@internal/config/model/Config";
import { RemoteConfigDataSource } from "./ConfigDataSource";

/**
* class RemoteRestConfigDataSource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Either, Left } from "purify-ts";
import { RemoteConfigDataSource } from "./ConfigDataSource";
import { RestRemoteConfigDataSource } from "./RemoteConfigDataSource";
import {
ApiCallError,
JSONParseError,
ParseResponseError,
} from "../di/configTypes";
} from "@internal/config/di/configTypes";
import { RemoteConfigDataSource } from "./ConfigDataSource";
import { RestRemoteConfigDataSource } from "./RemoteConfigDataSource";

let datasource: RemoteConfigDataSource;

// Necesary to use `any` on the prototype to be able to spy on private methods
/* eslint-disable @typescript-eslint/no-explicit-any */
const callApiSpy = jest.spyOn(
RestRemoteConfigDataSource.prototype as any,
"_callApi"
Expand All @@ -16,6 +19,7 @@ const parseResponseSpy = jest.spyOn(
RestRemoteConfigDataSource.prototype as any,
"_parseResponse"
);
/* eslint-enable @typescript-eslint/no-explicit-any */

describe("RemoteRestConfigDataSource", () => {
describe("RestRemoteConfigDataSource", () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/internal/config/data/RemoteConfigDataSource.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { injectable } from "inversify";
import { RemoteConfigDataSource } from "./ConfigDataSource";
import { ConfigDto } from "./Dto";
import { Config } from "../model/Config";
import { Either, Left } from "purify-ts";
import { Config } from "@internal/config/model/Config";
import {
ApiCallError,
JSONParseError,
ParseResponseError,
RemoteConfigFailure,
} from "../di/configTypes";
import { Either, Left } from "purify-ts";
} from "@internal/config/di/configTypes";
import { RemoteConfigDataSource } from "./ConfigDataSource";
import { ConfigDto } from "./Dto";

/**
* class RemoteRestConfigDataSource
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/internal/config/di/configModule.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Container } from "inversify";
import { FileLocalConfigDataSource } from "@internal/config/data/LocalConfigDataSource";
import { StubLocalConfigDataSource } from "@internal/config/data/LocalConfigDataSource.stub";
import { RestRemoteConfigDataSource } from "@internal/config/data/RemoteConfigDataSource";
import { StubRemoteConfigDataSource } from "@internal/config/data/RemoteConfigDataSource.stub";
import configModuleFactory from "./configModule";
import { types } from "./configTypes";
import { FileLocalConfigDataSource } from "../data/LocalConfigDataSource";
import { StubLocalConfigDataSource } from "../data/LocalConfigDataSource.stub";
import { RestRemoteConfigDataSource } from "../data/RemoteConfigDataSource";
import { StubRemoteConfigDataSource } from "../data/RemoteConfigDataSource.stub";

describe("configModuleFactory", () => {
describe("Default", () => {
Expand All @@ -31,7 +31,7 @@ describe("configModuleFactory", () => {
describe("Mocked", () => {
let container: Container;
let mod: ReturnType<typeof configModuleFactory>;
beforeAll(() => {
beforeEach(() => {
mod = configModuleFactory({ mock: true });
container = new Container();
container.load(mod);
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/internal/config/di/configModule.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ContainerModule } from "inversify";
import { FileLocalConfigDataSource } from "../data/LocalConfigDataSource";
import { StubLocalConfigDataSource } from "../data/LocalConfigDataSource.stub";
import { RestRemoteConfigDataSource } from "../data/RemoteConfigDataSource";
import { StubRemoteConfigDataSource } from "../data/RemoteConfigDataSource.stub";
import { DefaultConfigService } from "../service/DefaultConfigService";
import { GetSdkVersionUseCase } from "../usecase/GetSdkVersionUseCase";
import { FileLocalConfigDataSource } from "@internal/config/data/LocalConfigDataSource";
import { StubLocalConfigDataSource } from "@internal/config/data/LocalConfigDataSource.stub";
import { RestRemoteConfigDataSource } from "@internal/config/data/RemoteConfigDataSource";
import { StubRemoteConfigDataSource } from "@internal/config/data/RemoteConfigDataSource.stub";
import { DefaultConfigService } from "@internal/config/service/DefaultConfigService";
import { GetSdkVersionUseCase } from "@internal/config/usecase/GetSdkVersionUseCase";
import { types } from "./configTypes";

// This module is used to configure the dependency injection container
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/internal/config/service/ConfigService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from "../model/Config";
import { Config } from "@internal/config/model/Config";

export interface ConfigService {
getSdkConfig(): Promise<Config>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Either, Left } from "purify-ts";
import { ConfigService } from "./ConfigService";
import { DefaultConfigService } from "./DefaultConfigService";
import { JSONParseError } from "../di/configTypes";
import { JSONParseError } from "@internal/config/di/configTypes";

const localDataSource = {
getConfig: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { inject, injectable } from "inversify";
import { ConfigService } from "./ConfigService";
import { types } from "../di/configTypes";
import { types } from "@internal/config/di/configTypes";
import type {
LocalConfigDataSource,
RemoteConfigDataSource,
} from "../data/ConfigDataSource";
import { Config } from "../model/Config";
} from "@internal/config/data/ConfigDataSource";
import { Config } from "@internal/config/model/Config";

@injectable()
export class DefaultConfigService implements ConfigService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from "inversify";
import type { ConfigService } from "../service/ConfigService";
import { types } from "../di/configTypes";
import type { ConfigService } from "@internal/config/service/ConfigService";
import { types } from "@internal/config/di/configTypes";

/**
* class GetSDKVersionUseCase
Expand Down
6 changes: 5 additions & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"extends": "@ledgerhq/tsconfig-dsdk/sdk",
"compilerOptions": {
"outDir": "./lib"
"outDir": "./lib",
"baseUrl": "./src",
"paths": {
"@internal/*": ["internal/*"]
}
},
"include": ["src/**/*", "jest.config.ts", "jest.setup.ts"]
}

0 comments on commit 883dc5c

Please sign in to comment.