@@ -228,14 +228,14 @@ describe('Storage Client Tests', () => {
228228 jest . resetAllMocks ( ) ;
229229 } ) ;
230230
231- test ( 'Then StorageClient.delete should reject' , async ( ) => {
231+ test ( 'Then file.signUrl should reject' , async ( ) => {
232232 const client = new Storage ( ) ;
233233 await expect ( client . bucket ( 'test' ) . file ( 'test' ) . signUrl ( FileMode . Read ) ) . rejects . toEqual (
234234 new UnimplementedError ( "UNIMPLEMENTED" )
235235 ) ;
236236 } ) ;
237237
238- test ( 'The Grpc client for Storage.delete should have been called exactly once' , ( ) => {
238+ test ( 'The Grpc client for file.signUrl should have been called exactly once' , ( ) => {
239239 expect ( signUrlMock ) . toBeCalledTimes ( 1 ) ;
240240 } ) ;
241241 } ) ;
@@ -244,38 +244,101 @@ describe('Storage Client Tests', () => {
244244 const MOCK_REPLY = new StoragePreSignUrlResponse ( ) ;
245245 MOCK_REPLY . setUrl ( "testingUrl" ) ;
246246
247- let preSignUrlMock ;
247+ let preSignUrlMock : jest . SpyInstance ;
248248
249249 beforeAll ( ( ) => {
250250 preSignUrlMock = jest
251251 . spyOn ( GrpcStorageClient . prototype , 'preSignUrl' )
252252 . mockImplementation ( ( _ , callback : any ) => {
253253 callback ( null , MOCK_REPLY ) ;
254-
255254 return null as any ;
256255 } ) ;
257256 } ) ;
258257
259258 afterAll ( ( ) => {
260259 jest . resetAllMocks ( ) ;
261260 } ) ;
262-
263- test ( 'Then StorageClient.delete should delete the bytes from the bucket' , async ( ) => {
264- const client = new Storage ( ) . bucket ( 'test_bucket' ) . file ( 'test/item' ) ;
265- await expect ( client . signUrl ( FileMode . Read ) ) . resolves . toEqual ( "testingUrl" ) ;
266- } ) ;
267-
268- test ( 'The Grpc client for Storage.delete should have been called exactly once' , ( ) => {
269- expect ( preSignUrlMock ) . toBeCalledTimes ( 1 ) ;
270- } ) ;
271-
272- test ( 'The Grpc client for Storage.delete should have been called with provided options' , ( ) => {
273- const MOCK_REQUEST = new StoragePreSignUrlRequest ( ) ;
274- MOCK_REQUEST . setBucketName ( "test_bucket" ) ;
275- MOCK_REQUEST . setKey ( "test/item" ) ;
276- MOCK_REQUEST . setOperation ( FileMode . Read ) ;
277- MOCK_REQUEST . setExpiry ( 600 ) ;
278- expect ( preSignUrlMock ) . toBeCalledWith ( MOCK_REQUEST , expect . anything ( ) ) ;
261+
262+
263+ describe ( 'When calling file.signUrl' , ( ) => {
264+ let signUrl ;
265+
266+ beforeAll ( async ( ) => {
267+ preSignUrlMock . mockClear ( ) ;
268+ const client = new Storage ( ) . bucket ( 'test_bucket' ) . file ( 'test/item' ) ;
269+ signUrl = await client . signUrl ( FileMode . Read )
270+ } )
271+
272+ test ( 'Then file.signUrl should delete the bytes from the bucket' , ( ) => {
273+ expect ( signUrl ) . toEqual ( "testingUrl" ) ;
274+ } ) ;
275+
276+ test ( 'The Grpc client for file.signUrl should have been called exactly once' , ( ) => {
277+ expect ( preSignUrlMock ) . toBeCalledTimes ( 1 ) ;
278+ } ) ;
279+
280+ test ( 'The Grpc client for file.signUrl should have been called with provided options' , ( ) => {
281+ const MOCK_REQUEST = new StoragePreSignUrlRequest ( ) ;
282+ MOCK_REQUEST . setBucketName ( "test_bucket" ) ;
283+ MOCK_REQUEST . setKey ( "test/item" ) ;
284+ MOCK_REQUEST . setOperation ( FileMode . Read ) ;
285+ MOCK_REQUEST . setExpiry ( 600 ) ;
286+ expect ( preSignUrlMock ) . toBeCalledWith ( MOCK_REQUEST , expect . anything ( ) ) ;
287+ } ) ;
288+ } ) ;
289+
290+ describe ( 'When calling file.getUploadUrl' , ( ) => {
291+ let signUrl ;
292+
293+ beforeAll ( async ( ) => {
294+ preSignUrlMock . mockClear ( ) ;
295+ const client = new Storage ( ) . bucket ( 'test_bucket' ) . file ( 'test/item' ) ;
296+ signUrl = await client . getUploadUrl ( )
297+ } )
298+
299+ test ( 'Then file.signUrl should delete the bytes from the bucket' , ( ) => {
300+ expect ( signUrl ) . toEqual ( "testingUrl" ) ;
301+ } ) ;
302+
303+ test ( 'The Grpc client for file.signUrl should have been called exactly once' , ( ) => {
304+ expect ( preSignUrlMock ) . toBeCalledTimes ( 1 ) ;
305+ } ) ;
306+
307+ test ( 'The Grpc client for file.signUrl should have been called with provided options' , ( ) => {
308+ const MOCK_REQUEST = new StoragePreSignUrlRequest ( ) ;
309+ MOCK_REQUEST . setBucketName ( "test_bucket" ) ;
310+ MOCK_REQUEST . setKey ( "test/item" ) ;
311+ MOCK_REQUEST . setOperation ( FileMode . Write ) ;
312+ MOCK_REQUEST . setExpiry ( 600 ) ;
313+ expect ( preSignUrlMock ) . toBeCalledWith ( MOCK_REQUEST , expect . anything ( ) ) ;
314+ } ) ;
315+ } ) ;
316+
317+ describe ( 'When calling file.getUploadUrl' , ( ) => {
318+ let signUrl ;
319+
320+ beforeAll ( async ( ) => {
321+ preSignUrlMock . mockClear ( ) ;
322+ const client = new Storage ( ) . bucket ( 'test_bucket' ) . file ( 'test/item' ) ;
323+ signUrl = await client . getDownloadUrl ( )
324+ } )
325+
326+ test ( 'Then file.signUrl should delete the bytes from the bucket' , ( ) => {
327+ expect ( signUrl ) . toEqual ( "testingUrl" ) ;
328+ } ) ;
329+
330+ test ( 'The Grpc client for file.signUrl should have been called exactly once' , ( ) => {
331+ expect ( preSignUrlMock ) . toBeCalledTimes ( 1 ) ;
332+ } ) ;
333+
334+ test ( 'The Grpc client for file.signUrl should have been called with provided options' , ( ) => {
335+ const MOCK_REQUEST = new StoragePreSignUrlRequest ( ) ;
336+ MOCK_REQUEST . setBucketName ( "test_bucket" ) ;
337+ MOCK_REQUEST . setKey ( "test/item" ) ;
338+ MOCK_REQUEST . setOperation ( FileMode . Read ) ;
339+ MOCK_REQUEST . setExpiry ( 600 ) ;
340+ expect ( preSignUrlMock ) . toBeCalledWith ( MOCK_REQUEST , expect . anything ( ) ) ;
341+ } ) ;
279342 } ) ;
280343 } ) ;
281344} ) ;
0 commit comments