-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core-manager): implement
configuration.getPlugins
action (#3717)
- Loading branch information
1 parent
ef450f9
commit dcfff76
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
__tests__/unit/core-manager/actions/configuration-get-plugins.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
packages/core-manager/src/actions/configuration-get-plugins.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |