From 0853060a3dfcda448a4d497763ae78f9c0ba0335 Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Tue, 1 Jun 2021 07:26:28 +0900 Subject: [PATCH] feat: Added basic tests --- test/__snapshots__/storageFileApi.test.ts.snap | 9 +++++++++ test/storageFileApi.test.ts | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/__snapshots__/storageFileApi.test.ts.snap create mode 100644 test/storageFileApi.test.ts diff --git a/test/__snapshots__/storageFileApi.test.ts.snap b/test/__snapshots__/storageFileApi.test.ts.snap new file mode 100644 index 0000000..cc88772 --- /dev/null +++ b/test/__snapshots__/storageFileApi.test.ts.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`get public URL 1`] = ` +Object { + "publicURL": "/object/public/my-new-bucket-1622499505045/profiles/myUniqueUserId/profile.png", +} +`; + +exports[`get public URL 2`] = `"http://localhost:8000/storage/v1/object/public/my-new-bucket-1622499505045/profiles/myUniqueUserId/profile.png"`; diff --git a/test/storageFileApi.test.ts b/test/storageFileApi.test.ts new file mode 100644 index 0000000..da0077d --- /dev/null +++ b/test/storageFileApi.test.ts @@ -0,0 +1,16 @@ +import { SupabaseStorageClient } from '../src/index' + +// TODO: need to setup storage-api server for this test +const URL = 'http://localhost:8000/storage/v1' +const KEY = + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTYwMzk2ODgzNCwiZXhwIjoyNTUwNjUzNjM0LCJhdWQiOiIiLCJzdWIiOiIzMTdlYWRjZS02MzFhLTQ0MjktYTBiYi1mMTlhN2E1MTdiNGEiLCJSb2xlIjoicG9zdGdyZXMifQ.pZobPtp6gDcX0UbzMmG3FHSlg4m4Q-22tKtGWalOrNo' + +const storage = new SupabaseStorageClient(URL, { Authorization: `Bearer ${KEY}` }) +const newBucketName = `my-new-bucket-${Date.now()}` + +test('get public URL', async () => { + const res = storage.from(newBucketName).getPublicUrl('profiles/myUniqueUserId/profile.png') + expect(res.error).toBeNull() + expect(res.data).toMatchSnapshot() + expect(res.publicURL).toMatchSnapshot() +})