Skip to content

Commit

Permalink
chore(core-manager): implements process.delete action (#4470)
Browse files Browse the repository at this point in the history
* chore(core-manager): add process.delete action

* test(core-manager): process.delete action
  • Loading branch information
sebastijankuzner committed Aug 25, 2021
1 parent 5815752 commit 063e929
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
43 changes: 43 additions & 0 deletions __tests__/unit/core-manager/actions/process-delete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import "jest-extended";

import { Action } from "@packages/core-manager/src/actions/process-delete";
import { Identifiers } from "@packages/core-manager/src/ioc";
import { Sandbox } from "@packages/core-test-framework";

let sandbox: Sandbox;
let action: Action;

let mockCli;
const deleteMethod = jest.fn();

beforeEach(() => {
mockCli = {
get: jest.fn().mockReturnValue({
delete: deleteMethod,
}),
};

sandbox = new Sandbox();

sandbox.app.bind(Identifiers.CLI).toConstantValue(mockCli);

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

afterEach(() => {
delete process.env.CORE_API_DISABLED;
jest.clearAllMocks();
});

describe("Process:Delete", () => {
it("should have name", () => {
expect(action.name).toEqual("process.delete");
});

it("should resolve", async () => {
const result = await action.execute({ name: "ark-core" });

expect(result).toEqual({ });
expect(deleteMethod).toHaveBeenCalled();
});
});
37 changes: 37 additions & 0 deletions packages/core-manager/src/actions/process-delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Application as Cli, Container as CliContainer, Services } from "@arkecosystem/core-cli";
import { Application, Container } from "@arkecosystem/core-kernel";

import { Actions } from "../contracts";
import { Identifiers } from "../ioc";

@Container.injectable()
export class Action implements Actions.Action {
@Container.inject(Container.Identifiers.Application)
private readonly app!: Application;

public name = "process.delete";

public schema = {
type: "object",
properties: {
name: {
type: "string",
},
},
required: ["name"],
};

public async execute(params: any): Promise<any> {
this.deleteProcess(params.name);

return {};
}

private deleteProcess(name: string): void {
const cli = this.app.get<Cli>(Identifiers.CLI);

const processManager = cli.get<Services.ProcessManager>(CliContainer.Identifiers.ProcessManager);

processManager.delete(name);
}
}

0 comments on commit 063e929

Please sign in to comment.