-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
271 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,3 +106,6 @@ dist | |
|
||
# generated docs | ||
docs | ||
|
||
# IDE | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testEnvironment: 'jsdom', | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`get public URL 1`] = ` | ||
exports[`bucket api Get bucket by id 1`] = ` | ||
Object { | ||
"data": Object { | ||
"publicUrl": "http://localhost:8000/storage/v1/object/public/my-new-public-bucket/profiles/myUniqueUserId/profile.png", | ||
}, | ||
"created_at": "2021-02-17T04:43:32.770206+00:00", | ||
"id": "bucket2", | ||
"name": "bucket2", | ||
"owner": "4d56e902-f0a0-4662-8448-a4d9e643c142", | ||
"public": false, | ||
"updated_at": "2021-02-17T04:43:32.770206+00:00", | ||
} | ||
`; | ||
|
||
exports[`bucket api Get bucket with wrong id 1`] = `[StorageApiError: The resource was not found]`; | ||
|
||
exports[`bucket api delete bucket 1`] = ` | ||
Object { | ||
"message": "Successfully deleted", | ||
} | ||
`; | ||
|
||
exports[`bucket api empty bucket 1`] = ` | ||
Object { | ||
"message": "Successfully emptied", | ||
} | ||
`; | ||
|
||
exports[`bucket api update bucket 1`] = ` | ||
Object { | ||
"message": "Successfully updated", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
supabase txt file 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
supabase txt file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,63 @@ | ||
import StorageBucketApi from '../src/packages/StorageBucketApi' | ||
import { StorageClient } 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 StorageBucketApi(URL, { Authorization: `Bearer ${KEY}` }) | ||
const storage = new StorageClient(URL, { Authorization: `Bearer ${KEY}` }) | ||
const newBucketName = `my-new-bucket-${Date.now()}` | ||
|
||
test('Build to succeed', async () => { | ||
// Basic test to ensure TS build is working. | ||
expect(true).toEqual(true) | ||
}) | ||
|
||
test('Get all buckets', async () => { | ||
const res = await storage.listBuckets() | ||
expect(res.data).not.toBeNull() | ||
expect(res.data).toMatchSnapshot() | ||
}) | ||
|
||
test('Get bucket by id', async () => { | ||
const res = await storage.getBucket('bucket2') | ||
expect(res.data).toMatchSnapshot() | ||
}) | ||
|
||
test('Get bucket with wrong id', async () => { | ||
const res = await storage.getBucket('not-exist-id') | ||
expect(res.error).toMatchSnapshot() | ||
}) | ||
|
||
test('create new bucket', async () => { | ||
const res = await storage.createBucket(newBucketName) | ||
expect(res.data?.name).toEqual(newBucketName) | ||
}) | ||
|
||
test('create new public bucket', async () => { | ||
const newPublicBucketName = 'my-new-public-bucket' | ||
await storage.createBucket(newPublicBucketName, { public: true }) | ||
const res = await storage.getBucket(newPublicBucketName) | ||
expect(res.data!.public).toBe(true) | ||
}) | ||
|
||
test('update bucket', async () => { | ||
const updateRes = await storage.updateBucket(newBucketName, { public: true }) | ||
expect(updateRes.error).toBeNull() | ||
expect(updateRes.data).toMatchSnapshot() | ||
const getRes = await storage.getBucket(newBucketName) | ||
expect(getRes.data!.public).toBe(true) | ||
}) | ||
|
||
test('empty bucket', async () => { | ||
const res = await storage.emptyBucket(newBucketName) | ||
expect(res.error).toBeNull() | ||
expect(res.data).toMatchSnapshot() | ||
}) | ||
|
||
test('delete bucket', async () => { | ||
const res = await storage.deleteBucket(newBucketName) | ||
expect(res.error).toBeNull() | ||
expect(res.data).toMatchSnapshot() | ||
describe('bucket api', () => { | ||
test('Build to succeed', async () => { | ||
// Basic test to ensure TS build is working. | ||
expect(true).toEqual(true) | ||
}) | ||
|
||
test('Get all buckets', async () => { | ||
const res = await storage.listBuckets() | ||
expect(res.data).not.toBeNull() | ||
}) | ||
|
||
test('Get bucket by id', async () => { | ||
const res = await storage.getBucket('bucket2') | ||
expect(res.data).toMatchSnapshot() | ||
}) | ||
|
||
test('Get bucket with wrong id', async () => { | ||
const res = await storage.getBucket('not-exist-id') | ||
expect(res.error).toMatchSnapshot() | ||
}) | ||
|
||
test('create new bucket', async () => { | ||
const res = await storage.createBucket(newBucketName) | ||
expect(res.data?.name).toEqual(newBucketName) | ||
}) | ||
|
||
test('create new public bucket', async () => { | ||
const newPublicBucketName = 'my-new-public-bucket' | ||
await storage.createBucket(newPublicBucketName, { public: true }) | ||
const res = await storage.getBucket(newPublicBucketName) | ||
expect(res.data!.public).toBe(true) | ||
}) | ||
|
||
test('update bucket', async () => { | ||
const updateRes = await storage.updateBucket(newBucketName, { public: true }) | ||
expect(updateRes.error).toBeNull() | ||
expect(updateRes.data).toMatchSnapshot() | ||
const getRes = await storage.getBucket(newBucketName) | ||
expect(getRes.data!.public).toBe(true) | ||
}) | ||
|
||
test('empty bucket', async () => { | ||
const res = await storage.emptyBucket(newBucketName) | ||
expect(res.error).toBeNull() | ||
expect(res.data).toMatchSnapshot() | ||
}) | ||
|
||
test('delete bucket', async () => { | ||
const res = await storage.deleteBucket(newBucketName) | ||
expect(res.error).toBeNull() | ||
expect(res.data).toMatchSnapshot() | ||
}) | ||
}) |
Oops, something went wrong.