-
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.
chore(core-manager): implements
process.delete
action (#4470)
* chore(core-manager): add process.delete action * test(core-manager): process.delete action
- Loading branch information
1 parent
5815752
commit 063e929
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
__tests__/unit/core-manager/actions/process-delete.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,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(); | ||
}); | ||
}); |
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,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); | ||
} | ||
} |