File tree Expand file tree Collapse file tree 3 files changed +89
-1
lines changed
__tests__/unit/core-manager/actions Expand file tree Collapse file tree 3 files changed +89
-1
lines changed Original file line number Diff line number Diff line change 1+ import "jest-extended" ;
2+
3+ import { Container } from "@packages/core-kernel" ;
4+ import { Action } from "@packages/core-manager/src/actions/snaphsots-delete" ;
5+ import { Sandbox } from "@packages/core-test-framework" ;
6+
7+ let sandbox : Sandbox ;
8+ let action : Action ;
9+
10+ let mockFilesystem ;
11+
12+ beforeEach ( ( ) => {
13+ mockFilesystem = {
14+ exists : jest . fn ( ) . mockResolvedValue ( true ) ,
15+ delete : jest . fn ( ) . mockResolvedValue ( true ) ,
16+ } ;
17+
18+ sandbox = new Sandbox ( ) ;
19+
20+ sandbox . app . bind ( Container . Identifiers . FilesystemService ) . toConstantValue ( mockFilesystem ) ;
21+
22+ action = sandbox . app . resolve ( Action ) ;
23+ } ) ;
24+
25+ describe ( "Snapshots:Delete" , ( ) => {
26+ it ( "should have name" , ( ) => {
27+ expect ( action . name ) . toEqual ( "snapshots.delete" ) ;
28+ } ) ;
29+
30+ it ( "should delete snapshot" , async ( ) => {
31+ const result = await action . execute ( { name : "1-10" } ) ;
32+
33+ expect ( result ) . toEqual ( { } ) ;
34+ } ) ;
35+
36+ it ( "should throw error if snapshot is not found" , async ( ) => {
37+ mockFilesystem . exists = jest . fn ( ) . mockResolvedValue ( false ) ;
38+
39+ await expect ( action . execute ( { name : "1-10" } ) ) . rejects . toThrow ( "Snapshot not found" ) ;
40+ } ) ;
41+
42+ it ( "should throw error if snapshot is not deleted" , async ( ) => {
43+ mockFilesystem . delete = jest . fn ( ) . mockResolvedValue ( false ) ;
44+
45+ await expect ( action . execute ( { name : "1-10" } ) ) . rejects . toThrow ( "Cannot delete snapshot" ) ;
46+ } ) ;
47+ } ) ;
Original file line number Diff line number Diff line change 1+ import { Container , Contracts } from "@arkecosystem/core-kernel" ;
2+ import { join } from "path" ;
3+
4+ import { Actions } from "../contracts" ;
5+
6+ @Container . injectable ( )
7+ export class Action implements Actions . Action {
8+ public name = "snapshots.delete" ;
9+
10+ public schema = {
11+ type : "object" ,
12+ properties : {
13+ name : {
14+ type : "string" ,
15+ } ,
16+ } ,
17+ required : [ "name" ] ,
18+ } ;
19+
20+ @Container . inject ( Container . Identifiers . FilesystemService )
21+ private readonly filesystem ! : Contracts . Kernel . Filesystem ;
22+
23+ public async execute ( params : { name : string } ) : Promise < any > {
24+ await this . deleteSnapshot ( params . name ) ;
25+
26+ return { } ;
27+ }
28+
29+ public async deleteSnapshot ( name : string ) : Promise < void > {
30+ const snapshotsDir = `${ process . env . CORE_PATH_DATA } /snapshots/` ;
31+ const snapshotPath = join ( snapshotsDir , name ) ;
32+
33+ if ( ! ( await this . filesystem . exists ( snapshotPath ) ) ) {
34+ throw new Error ( "Snapshot not found" ) ;
35+ }
36+
37+ if ( ! ( await this . filesystem . delete ( snapshotPath ) ) ) {
38+ throw new Error ( "Cannot delete snapshot" ) ;
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ export class Command extends Commands.Command {
5858 const flags : Contracts . AnyObject = { ...this . getFlags ( ) } ;
5959 flags . processType = "core" ;
6060
61- this . actions . abortRunningProcess ( `${ flags . token } -core` ) ;
61+ // this.actions.abortRunningProcess(`${flags.token}-core`);
6262
6363 await Utils . buildApplication ( {
6464 flags,
You can’t perform that action at this time.
0 commit comments