14
14
import * as fs from "fs-extra" ;
15
15
import * as path from "path" ;
16
16
import * as vscode from "vscode" ;
17
- import { CopybookURI } from "../services/copybook/CopybookURI" ;
18
- import { ProfileService } from "../services/ProfileService" ;
19
- import { SettingsUtils } from "../services/util/SettingsUtils" ;
20
- import { ZoweApi } from "../services/ZoweApi" ;
17
+ import { CopybookURI } from "../services/copybook/CopybookURI" ;
18
+ import { ProfileService } from "../services/ProfileService" ;
19
+ import { SettingsUtils } from "../services/util/SettingsUtils" ;
20
+ import { ZoweApi } from "../services/ZoweApi" ;
21
21
import * as fsUtils from "../services/util/FSUtils" ;
22
- import { COPYBOOK_EXT_ARRAY } from "../constants" ;
22
+ import { COPYBOOK_EXT_ARRAY } from "../constants" ;
23
23
24
24
const zoweApi : ZoweApi = new ZoweApi ( ) ;
25
25
const profileService : ProfileService = new ProfileService ( zoweApi ) ;
26
26
const copybookURI : CopybookURI = new CopybookURI ( profileService ) ;
27
27
const copybookName : string = "NSTCOPY1" ;
28
28
const copybookNameWithExtension : string = "NSTCOPY2.CPY" ;
29
29
const CPY_FOLDER_NAME = ".cobcopy" ;
30
+ const RELATIVE_CPY_FOLDER_NAME = "../relativeCobcopy" ;
30
31
const folderPath = path . join ( __dirname , CPY_FOLDER_NAME ) ;
31
32
SettingsUtils . getWorkspacesURI = jest . fn ( ) . mockReturnValue ( [ "file://" + __dirname ] ) ;
32
33
profileService . resolveProfile = jest . fn ( ) . mockReturnValue ( "PRF" ) ;
@@ -35,7 +36,7 @@ vscode.workspace.getConfiguration = jest.fn().mockReturnValue({
35
36
} ) ;
36
37
37
38
// file utils
38
- function createFile ( filename : string ) : string {
39
+ function createFile ( filename : string , folderPath : string ) : string {
39
40
fs . writeFileSync ( path . join ( folderPath , filename ) , "Some dummy content" , err => {
40
41
if ( err ) {
41
42
return null ;
@@ -46,13 +47,17 @@ function createFile(filename: string): string {
46
47
47
48
function createDirectory ( targetPath : string ) {
48
49
49
- fs . mkdirSync ( targetPath , { recursive : true } ) ;
50
+ fs . mkdirSync ( targetPath , { recursive : true } ) ;
50
51
}
51
52
52
53
function removeFolder ( pathFile : string ) {
53
54
fs . remove ( pathFile ) ;
54
55
}
55
56
57
+ function removeNonEmptyFolder ( targetPath : string ) {
58
+ fs . rmdirSync ( targetPath , { recursive : true } ) ;
59
+ }
60
+
56
61
function buildResultArrayFrom ( settingsMockValue : string [ ] , profileName : string ) : number {
57
62
vscode . workspace . getConfiguration = jest . fn ( ) . mockReturnValue ( {
58
63
get : jest . fn ( ) . mockReturnValue ( settingsMockValue ) ,
@@ -65,8 +70,8 @@ beforeEach(() => {
65
70
} ) ;
66
71
beforeAll ( ( ) => {
67
72
createDirectory ( folderPath ) ;
68
- createFile ( copybookName ) ;
69
- createFile ( copybookNameWithExtension ) ;
73
+ createFile ( copybookName , folderPath ) ;
74
+ createFile ( copybookNameWithExtension , folderPath ) ;
70
75
} ) ;
71
76
afterAll ( ( ) => {
72
77
return removeFolder ( folderPath ) ;
@@ -95,6 +100,16 @@ describe("Resolve local copybook present in one or more folders specified by the
95
100
test ( "Given a copybook with extension on filesystem, the uri is correctly returned" , ( ) => {
96
101
expect ( fsUtils . searchInWorkspace ( "NSTCOPY2" , [ CPY_FOLDER_NAME ] , COPYBOOK_EXT_ARRAY ) ) . toBeDefined ( ) ;
97
102
} ) ;
103
+ test ( "Given a valid relative path for copybook with extension on filesystem, the uri is correctly returned" , ( ) => {
104
+ const dir = path . join ( __dirname , RELATIVE_CPY_FOLDER_NAME ) ;
105
+ createDirectory ( dir ) ;
106
+ createFile ( copybookNameWithExtension , dir ) ;
107
+ expect ( fsUtils . searchInWorkspace ( "NSTCOPY2" , [ RELATIVE_CPY_FOLDER_NAME ] , COPYBOOK_EXT_ARRAY ) ) . toBeDefined ( ) ;
108
+ removeNonEmptyFolder ( dir ) ;
109
+ } ) ;
110
+ test ( "Given a valid absolute path for copybook with extension on filesystem, the uri is correctly returned" , ( ) => {
111
+ expect ( fsUtils . searchInWorkspace ( "NSTCOPY2" , [ path . normalize ( folderPath ) ] , COPYBOOK_EXT_ARRAY ) ) . toBeDefined ( ) ;
112
+ } ) ;
98
113
} ) ;
99
114
describe ( "With invalid input parameters, the list of URI that represent copybook downloaded are not generated" , ( ) => {
100
115
test ( "given a profile but no dataset, the result list returned is empty" , ( ) => {
@@ -136,9 +151,9 @@ describe("Prioritize search criteria for copybooks test suite", () => {
136
151
} ) ;
137
152
test ( "With both local and dsn references defined in the settings.json, the search is applied on local resources" +
138
153
"first" , async ( ) => {
139
- provideMockValueForLocalAndDSN ( CPY_FOLDER_NAME , "" ) ;
140
- const uri : string = await copybookURI . resolveCopybookURI ( copybookName , "PRGNAME" ) ;
141
- expect ( uri ) . not . toBe ( "" ) ;
142
- expect ( spySearchInWorkspace ) . toBeCalledTimes ( 1 ) ;
143
- } ) ;
154
+ provideMockValueForLocalAndDSN ( CPY_FOLDER_NAME , "" ) ;
155
+ const uri : string = await copybookURI . resolveCopybookURI ( copybookName , "PRGNAME" ) ;
156
+ expect ( uri ) . not . toBe ( "" ) ;
157
+ expect ( spySearchInWorkspace ) . toBeCalledTimes ( 1 ) ;
158
+ } ) ;
144
159
} ) ;
0 commit comments