Skip to content

Commit

Permalink
feat(core-manager): implement configuration.getPlugins action (#3717)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner authored May 20, 2020
1 parent ef450f9 commit dcfff76
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import "jest-extended";

import { Container } from "@packages/core-kernel";
import { Action } from "@packages/core-manager/src/actions/configuration-get-plugins";
import { Sandbox } from "@packages/core-test-framework";

let sandbox: Sandbox;
let action: Action;

const mockFilesystem = {
get: jest.fn().mockResolvedValue("file_content"),
};

beforeEach(() => {
sandbox = new Sandbox();

sandbox.app.bind(Container.Identifiers.FilesystemService).toConstantValue(mockFilesystem);

action = sandbox.app.resolve(Action);
});

describe("Configuration:EnvGet", () => {
it("should have name", () => {
expect(action.name).toEqual("configuration.getPlugins");
});

it("should return plugins.js content", async () => {
sandbox.app.configPath = jest.fn().mockReturnValue("path/to/env/file");

const result = await action.execute({});

await expect(result).toBe("file_content");
});
});
21 changes: 21 additions & 0 deletions packages/core-manager/src/actions/configuration-get-plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Application, Container, Contracts } from "@arkecosystem/core-kernel";
import { Actions } from "../contracts";

@Container.injectable()
export class Action implements Actions.Action {
public name = "configuration.getPlugins";

@Container.inject(Container.Identifiers.Application)
private readonly app!: Application;

@Container.inject(Container.Identifiers.FilesystemService)
private readonly filesystem!: Contracts.Kernel.Filesystem;

public async execute(params: object): Promise<any> {
return await this.getPluginFile();
}

public async getPluginFile(): Promise<string> {
return (await this.filesystem.get(this.app.configPath("plugins.js"))).toString();
}
}

0 comments on commit dcfff76

Please sign in to comment.