|
1 |
| -import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'; |
| 1 | +import { afterAll, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals'; |
2 | 2 |
|
3 | 3 | import storage, {
|
4 | 4 | firebase,
|
@@ -30,6 +30,14 @@ import storage, {
|
30 | 30 | TaskState,
|
31 | 31 | } from '../lib';
|
32 | 32 |
|
| 33 | +import { |
| 34 | + createCheckV9Deprecation, |
| 35 | + CheckV9DeprecationFunction, |
| 36 | +} from '../../app/lib/common/unitTestUtils'; |
| 37 | + |
| 38 | +// @ts-ignore test |
| 39 | +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; |
| 40 | + |
33 | 41 | describe('Storage', function () {
|
34 | 42 | describe('namespace', function () {
|
35 | 43 | beforeAll(async function () {
|
@@ -196,4 +204,247 @@ describe('Storage', function () {
|
196 | 204 | expect(TaskState.SUCCESS).toBeDefined();
|
197 | 205 | });
|
198 | 206 | });
|
| 207 | + |
| 208 | + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { |
| 209 | + let storageV9Deprecation: CheckV9DeprecationFunction; |
| 210 | + let storageRefV9Deprecation: CheckV9DeprecationFunction; |
| 211 | + let staticsV9Deprecation: CheckV9DeprecationFunction; |
| 212 | + |
| 213 | + beforeEach(function () { |
| 214 | + storageV9Deprecation = createCheckV9Deprecation(['storage']); |
| 215 | + |
| 216 | + storageRefV9Deprecation = createCheckV9Deprecation(['storage', 'StorageReference']); |
| 217 | + |
| 218 | + staticsV9Deprecation = createCheckV9Deprecation(['storage', 'statics']); |
| 219 | + |
| 220 | + // @ts-ignore test |
| 221 | + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { |
| 222 | + return new Proxy( |
| 223 | + {}, |
| 224 | + { |
| 225 | + get: (_target, prop) => { |
| 226 | + // Handle list operations specially |
| 227 | + if (prop === 'list' || prop === 'listAll') { |
| 228 | + return jest.fn().mockResolvedValue({ |
| 229 | + items: [], |
| 230 | + prefixes: [], |
| 231 | + nextPageToken: null, |
| 232 | + } as never); |
| 233 | + } |
| 234 | + // Default mock for other operations |
| 235 | + return jest.fn().mockResolvedValue({ |
| 236 | + source: 'cache', |
| 237 | + changes: [], |
| 238 | + documents: [], |
| 239 | + metadata: {}, |
| 240 | + path: 'foo', |
| 241 | + } as never); |
| 242 | + }, |
| 243 | + }, |
| 244 | + ); |
| 245 | + }); |
| 246 | + }); |
| 247 | + |
| 248 | + describe('Storage', function () { |
| 249 | + it('useStorageEmulator()', function () { |
| 250 | + const storage = getStorage(); |
| 251 | + storageV9Deprecation( |
| 252 | + () => connectStorageEmulator(storage, 'localhost', 8080), |
| 253 | + () => storage.useEmulator('localhost', 8080), |
| 254 | + 'useEmulator', |
| 255 | + ); |
| 256 | + }); |
| 257 | + |
| 258 | + it('ref()', function () { |
| 259 | + const storage = getStorage(); |
| 260 | + storageV9Deprecation( |
| 261 | + () => ref(storage, 'foo'), |
| 262 | + () => storage.ref('foo'), |
| 263 | + 'ref', |
| 264 | + ); |
| 265 | + }); |
| 266 | + |
| 267 | + it('refFromURL()', function () { |
| 268 | + const storage = firebase.app().storage(); |
| 269 | + storageV9Deprecation( |
| 270 | + () => refFromURL(storage, 'gs://flutterfire-e2e-tests.appspot.com/flutter-tsts'), |
| 271 | + () => storage.refFromURL('gs://flutterfire-e2e-tests.appspot.com/flutter-tsts'), |
| 272 | + 'refFromURL', |
| 273 | + ); |
| 274 | + }); |
| 275 | + |
| 276 | + it('setMaxOperationRetryTime()', function () { |
| 277 | + const storage = firebase.app().storage(); |
| 278 | + storageV9Deprecation( |
| 279 | + () => setMaxOperationRetryTime(storage, 1000), |
| 280 | + () => storage.setMaxOperationRetryTime(1000), |
| 281 | + 'setMaxOperationRetryTime', |
| 282 | + ); |
| 283 | + }); |
| 284 | + |
| 285 | + it('setMaxUploadRetryTime()', function () { |
| 286 | + const storage = firebase.app().storage(); |
| 287 | + storageV9Deprecation( |
| 288 | + () => setMaxUploadRetryTime(storage, 1000), |
| 289 | + () => storage.setMaxUploadRetryTime(1000), |
| 290 | + 'setMaxUploadRetryTime', |
| 291 | + ); |
| 292 | + }); |
| 293 | + |
| 294 | + it('setMaxDownloadRetryTime()', function () { |
| 295 | + const storage = firebase.app().storage(); |
| 296 | + storageV9Deprecation( |
| 297 | + () => setMaxDownloadRetryTime(storage, 1000), |
| 298 | + () => storage.setMaxDownloadRetryTime(1000), |
| 299 | + 'setMaxDownloadRetryTime', |
| 300 | + ); |
| 301 | + }); |
| 302 | + |
| 303 | + it('delete()', function () { |
| 304 | + const storage = firebase.app().storage(); |
| 305 | + const storageRef = storage.ref('foo'); |
| 306 | + storageRefV9Deprecation( |
| 307 | + () => deleteObject(storageRef), |
| 308 | + () => storageRef.delete(), |
| 309 | + 'delete', |
| 310 | + ); |
| 311 | + }); |
| 312 | + |
| 313 | + it('getDownloadURL()', function () { |
| 314 | + const storage = firebase.app().storage(); |
| 315 | + const storageRef = storage.ref('foo'); |
| 316 | + storageRefV9Deprecation( |
| 317 | + () => getDownloadURL(storageRef), |
| 318 | + () => storageRef.getDownloadURL(), |
| 319 | + 'getDownloadURL', |
| 320 | + ); |
| 321 | + }); |
| 322 | + |
| 323 | + it('getMetadata()', function () { |
| 324 | + const storage = firebase.app().storage(); |
| 325 | + const storageRef = storage.ref('foo'); |
| 326 | + storageRefV9Deprecation( |
| 327 | + () => getMetadata(storageRef), |
| 328 | + () => storageRef.getMetadata(), |
| 329 | + 'getMetadata', |
| 330 | + ); |
| 331 | + }); |
| 332 | + |
| 333 | + it('list()', function () { |
| 334 | + const storage = firebase.app().storage(); |
| 335 | + const storageRef = storage.ref('foo'); |
| 336 | + storageRefV9Deprecation( |
| 337 | + () => list(storageRef), |
| 338 | + () => storageRef.list(), |
| 339 | + 'list', |
| 340 | + ); |
| 341 | + }); |
| 342 | + |
| 343 | + it('listAll()', function () { |
| 344 | + const storage = firebase.app().storage(); |
| 345 | + const storageRef = storage.ref('foo'); |
| 346 | + storageRefV9Deprecation( |
| 347 | + () => listAll(storageRef), |
| 348 | + () => storageRef.listAll(), |
| 349 | + 'listAll', |
| 350 | + ); |
| 351 | + }); |
| 352 | + |
| 353 | + it('updateMetadata()', function () { |
| 354 | + const storage = firebase.app().storage(); |
| 355 | + const storageRef = storage.ref('foo'); |
| 356 | + storageRefV9Deprecation( |
| 357 | + () => updateMetadata(storageRef, {}), |
| 358 | + () => storageRef.updateMetadata({}), |
| 359 | + 'updateMetadata', |
| 360 | + ); |
| 361 | + }); |
| 362 | + |
| 363 | + it('put()', function () { |
| 364 | + const storage = firebase.app().storage(); |
| 365 | + const storageRef = storage.ref('foo'); |
| 366 | + storageRefV9Deprecation( |
| 367 | + () => uploadBytesResumable(storageRef, new Blob(['foo']), {}), |
| 368 | + () => storageRef.put(new Blob(['foo']), {}), |
| 369 | + 'put', |
| 370 | + ); |
| 371 | + }); |
| 372 | + |
| 373 | + it('putString()', function () { |
| 374 | + const storage = firebase.app().storage(); |
| 375 | + const storageRef = storage.ref('foo'); |
| 376 | + storageRefV9Deprecation( |
| 377 | + () => uploadString(storageRef, 'foo', StringFormat.RAW), |
| 378 | + () => storageRef.putString('foo', StringFormat.RAW), |
| 379 | + 'putString', |
| 380 | + ); |
| 381 | + }); |
| 382 | + |
| 383 | + it('putFile()', function () { |
| 384 | + const storage = firebase.app().storage(); |
| 385 | + const storageRef = storage.ref('foo'); |
| 386 | + storageRefV9Deprecation( |
| 387 | + () => putFile(storageRef, 'foo', {}), |
| 388 | + () => storageRef.putFile('foo', {}), |
| 389 | + 'putFile', |
| 390 | + ); |
| 391 | + }); |
| 392 | + |
| 393 | + it('writeToFile()', function () { |
| 394 | + const storage = firebase.app().storage(); |
| 395 | + const storageRef = storage.ref('foo'); |
| 396 | + storageRefV9Deprecation( |
| 397 | + () => writeToFile(storageRef, 'foo'), |
| 398 | + () => storageRef.writeToFile('foo'), |
| 399 | + 'writeToFile', |
| 400 | + ); |
| 401 | + }); |
| 402 | + |
| 403 | + it('toString()', function () { |
| 404 | + const storage = firebase.app().storage(); |
| 405 | + const storageRef = storage.ref('foo'); |
| 406 | + storageRefV9Deprecation( |
| 407 | + () => toString(storageRef), |
| 408 | + () => storageRef.toString(), |
| 409 | + 'toString', |
| 410 | + ); |
| 411 | + }); |
| 412 | + |
| 413 | + it('child()', function () { |
| 414 | + const storage = firebase.app().storage(); |
| 415 | + const storageRef = storage.ref('foo'); |
| 416 | + storageRefV9Deprecation( |
| 417 | + () => child(storageRef, 'bar'), |
| 418 | + () => storageRef.child('bar'), |
| 419 | + 'child', |
| 420 | + ); |
| 421 | + }); |
| 422 | + }); |
| 423 | + |
| 424 | + describe('statics', function () { |
| 425 | + it('StringFormat static', function () { |
| 426 | + staticsV9Deprecation( |
| 427 | + () => StringFormat.RAW, |
| 428 | + () => firebase.storage.StringFormat.RAW, |
| 429 | + 'StringFormat', |
| 430 | + ); |
| 431 | + }); |
| 432 | + |
| 433 | + it('TaskEvent static', function () { |
| 434 | + staticsV9Deprecation( |
| 435 | + () => TaskEvent.STATE_CHANGED, |
| 436 | + () => firebase.storage.TaskEvent.STATE_CHANGED, |
| 437 | + 'TaskEvent', |
| 438 | + ); |
| 439 | + }); |
| 440 | + |
| 441 | + it('TaskState static', function () { |
| 442 | + staticsV9Deprecation( |
| 443 | + () => TaskState.SUCCESS, |
| 444 | + () => firebase.storage.TaskState.SUCCESS, |
| 445 | + 'TaskState', |
| 446 | + ); |
| 447 | + }); |
| 448 | + }); |
| 449 | + }); |
199 | 450 | });
|
0 commit comments