@@ -85,6 +85,11 @@ describe(commands.FILE_VERSION_KEEP, () => {
85
85
assert . strictEqual ( actual . success , false ) ;
86
86
} ) ;
87
87
88
+ it ( 'fails validation if label is not specified' , async ( ) => {
89
+ const actual = commandOptionsSchema . safeParse ( { webUrl : validWebUrl , fileUrl : validFileUrl } ) ;
90
+ assert . strictEqual ( actual . success , false ) ;
91
+ } ) ;
92
+
88
93
it ( 'passes validation if fileUrl is specified' , async ( ) => {
89
94
const actual = await command . validate ( { options : { webUrl : validWebUrl , label : validLabel , fileUrl : validFileUrl } } , commandInfo ) ;
90
95
assert . strictEqual ( actual , true ) ;
@@ -97,7 +102,7 @@ describe(commands.FILE_VERSION_KEEP, () => {
97
102
98
103
it ( 'ensures that a specific file version will never expire (fileUrl)' , async ( ) => {
99
104
sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
100
- if ( opts . url === `${ validWebUrl } /_api/web/GetFileByServerRelativePath(DecodedUrl='${ formatting . encodeQueryParameter ( validFileUrl ) } ')/versions/?$filter=VersionLabel eq '${ validLabel } '` ) {
105
+ if ( opts . url === `${ validWebUrl } /_api/web/GetFileByServerRelativePath(DecodedUrl='${ formatting . encodeQueryParameter ( validFileUrl ) } ')/versions/?$filter=VersionLabel eq '${ validLabel } '&$select=Id ` ) {
101
106
return {
102
107
value : [
103
108
{
@@ -111,7 +116,7 @@ describe(commands.FILE_VERSION_KEEP, () => {
111
116
throw 'Invalid request' ;
112
117
} ) ;
113
118
114
- sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
119
+ const postStub : sinon . SinonStub = sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
115
120
if ( opts . url === `${ validWebUrl } /_api/web/GetFileByServerRelativePath(DecodedUrl='${ formatting . encodeQueryParameter ( validFileUrl ) } ')/versions(1)/SetExpirationDate()` ) {
116
121
return ;
117
122
}
@@ -120,11 +125,12 @@ describe(commands.FILE_VERSION_KEEP, () => {
120
125
} ) ;
121
126
122
127
await command . action ( logger , { options : { webUrl : validWebUrl , fileUrl : validFileUrl , label : validLabel , verbose : true } } ) ;
128
+ assert . strictEqual ( postStub . lastCall . args [ 0 ] . url , `${ validWebUrl } /_api/web/GetFileByServerRelativePath(DecodedUrl='${ formatting . encodeQueryParameter ( validFileUrl ) } ')/versions(1)/SetExpirationDate()` ) ;
123
129
} ) ;
124
130
125
131
it ( 'ensures that a specific file version will never expire (fileId)' , async ( ) => {
126
132
sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
127
- if ( opts . url === `${ validWebUrl } /_api/web/GetFileById('${ validFileId } ')/versions/?$filter=VersionLabel eq '${ validLabel } '` ) {
133
+ if ( opts . url === `${ validWebUrl } /_api/web/GetFileById('${ validFileId } ')/versions/?$filter=VersionLabel eq '${ validLabel } '&$select=Id ` ) {
128
134
return {
129
135
value : [
130
136
{
@@ -138,7 +144,7 @@ describe(commands.FILE_VERSION_KEEP, () => {
138
144
throw 'Invalid request' ;
139
145
} ) ;
140
146
141
- sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
147
+ const postStub : sinon . SinonStub = sinon . stub ( request , 'post' ) . callsFake ( async ( opts ) => {
142
148
if ( opts . url === `${ validWebUrl } /_api/web/GetFileById('${ validFileId } ')/versions(1)/SetExpirationDate()` ) {
143
149
return ;
144
150
}
@@ -147,11 +153,12 @@ describe(commands.FILE_VERSION_KEEP, () => {
147
153
} ) ;
148
154
149
155
await command . action ( logger , { options : { webUrl : validWebUrl , fileId : validFileId , label : validLabel , verbose : true } } ) ;
156
+ assert . strictEqual ( postStub . lastCall . args [ 0 ] . url , `${ validWebUrl } /_api/web/GetFileById('${ validFileId } ')/versions(1)/SetExpirationDate()` ) ;
150
157
} ) ;
151
158
152
159
it ( 'correctly handles error when the specified version does not exist' , async ( ) => {
153
160
sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
154
- if ( opts . url === `${ validWebUrl } /_api/web/GetFileByServerRelativePath(DecodedUrl='${ formatting . encodeQueryParameter ( validFileUrl ) } ')/versions/?$filter=VersionLabel eq '${ validLabel } '` ) {
161
+ if ( opts . url === `${ validWebUrl } /_api/web/GetFileByServerRelativePath(DecodedUrl='${ formatting . encodeQueryParameter ( validFileUrl ) } ')/versions/?$filter=VersionLabel eq '${ validLabel } '&$select=Id ` ) {
155
162
return { value : [ ] } ;
156
163
}
157
164
@@ -163,7 +170,7 @@ describe(commands.FILE_VERSION_KEEP, () => {
163
170
164
171
it ( 'correctly handles API OData error' , async ( ) => {
165
172
sinon . stub ( request , 'get' ) . callsFake ( async ( opts ) => {
166
- if ( opts . url === `${ validWebUrl } /_api/web/GetFileById('${ validFileId } ')/versions/?$filter=VersionLabel eq '${ validLabel } '` ) {
173
+ if ( opts . url === `${ validWebUrl } /_api/web/GetFileById('${ validFileId } ')/versions/?$filter=VersionLabel eq '${ validLabel } '&$select=Id ` ) {
167
174
throw {
168
175
error : {
169
176
'odata.error' : {
0 commit comments