From d4240fa5c8c0353de81cc8c052eea2915c3e383c Mon Sep 17 00:00:00 2001 From: Denis DelGrosso <85250797+ddelgrosso1@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:03:08 -0400 Subject: [PATCH] fix: use correct indices for file.from and fix tests to verify names (#2449) --- src/file.ts | 8 ++++---- test/file.ts | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/file.ts b/src/file.ts index e4438a7d8..14024cb2b 100644 --- a/src/file.ts +++ b/src/file.ts @@ -2410,11 +2410,11 @@ class File extends ServiceObject { const httpsMatches = [...publicUrlOrGsUrl.matchAll(HTTPS_PUBLIC_URL_REGEX)]; if (gsMatches.length > 0) { - const bucket = new Bucket(storageInstance, gsMatches[0][1]); - return new File(bucket, gsMatches[0][2], options); + const bucket = new Bucket(storageInstance, gsMatches[0][2]); + return new File(bucket, gsMatches[0][3], options); } else if (httpsMatches.length > 0) { - const bucket = new Bucket(storageInstance, httpsMatches[0][2]); - return new File(bucket, httpsMatches[0][3], options); + const bucket = new Bucket(storageInstance, httpsMatches[0][3]); + return new File(bucket, httpsMatches[0][4], options); } else { throw new Error( 'URL string must be of format gs://bucket/file or https://storage.googleapis.com/bucket/file' diff --git a/test/file.ts b/test/file.ts index bd95ad26d..bd60273f4 100644 --- a/test/file.ts +++ b/test/file.ts @@ -5180,8 +5180,8 @@ describe('File', () => { const result = File.from(gsUrl, STORAGE); assert(result); - assert(result.bucket.name, 'mybucket'); - assert(result.name, 'myfile'); + assert.strictEqual(result.bucket.name, 'mybucket'); + assert.strictEqual(result.name, 'myfile'); }); it('should create a File object from a gs:// formatted URL including a folder', () => { @@ -5189,8 +5189,8 @@ describe('File', () => { const result = File.from(gsUrl, STORAGE); assert(result); - assert(result.bucket.name, 'mybucket'); - assert(result.name, 'myfolder/myfile'); + assert.strictEqual(result.bucket.name, 'mybucket'); + assert.strictEqual(result.name, 'myfolder/myfile'); }); it('should create a File object from a https:// formatted URL', () => { @@ -5198,8 +5198,8 @@ describe('File', () => { const result = File.from(httpsUrl, STORAGE); assert(result); - assert(result.bucket.name, 'mybucket'); - assert(result.name, 'myfile'); + assert.strictEqual(result.bucket.name, 'mybucket'); + assert.strictEqual(result.name, 'myfile'); }); it('should create a File object from a https:// formatted URL including a folder', () => { @@ -5208,8 +5208,8 @@ describe('File', () => { const result = File.from(httpsUrl, STORAGE); assert(result); - assert(result.bucket.name, 'mybucket'); - assert(result.name, 'myfolder/myfile'); + assert.strictEqual(result.bucket.name, 'mybucket'); + assert.strictEqual(result.name, 'myfolder/myfile'); }); it('should throw an error when invoked with an incorrectly formatted URL', () => {