Skip to content

Commit

Permalink
fix: create bucket return newly created bucket id instead of bucket o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
phamhieu committed Apr 29, 2021
1 parent b18d8bf commit 31d6876
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/lib/StorageBucketApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ export class StorageBucketApi {
* Creates a new Storage bucket
*
* @param id A unique identifier for the bucket you are creating.
* @returns newly created bucket id
*/
async createBucket(id: string): Promise<{ data: Bucket | null; error: Error | null }> {
async createBucket(id: string): Promise<{ data: string | null; error: Error | null }> {
try {
const data = await post(`${this.url}/bucket`, { id, name: id }, { headers: this.headers })
return { data, error: null }
return { data: data.name, error: null }
} catch (error) {
return { data: null, error }
}
Expand Down
8 changes: 3 additions & 5 deletions test/storageApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const KEY =

const storage = new StorageBucketApi(URL, { Authorization: `Bearer ${KEY}` })
const newBucketName = `my-new-bucket-${Date.now()}`
let createdBucketId = ''

test('Build to succeed', async () => {
// Basic test to ensure TS build is working.
Expand All @@ -32,18 +31,17 @@ test('Get bucket with wrong id', async () => {

test('create new bucket', async () => {
const res = await storage.createBucket(newBucketName)
createdBucketId = res.data!.name
expect(res.data!.name).toEqual(newBucketName)
expect(res.data).toEqual(newBucketName)
})

test('empty bucket', async () => {
const res = await storage.emptyBucket(createdBucketId)
const res = await storage.emptyBucket(newBucketName)
expect(res.error).toBeNull()
expect(res.data).toMatchSnapshot()
})

test('delete bucket', async () => {
const res = await storage.deleteBucket(createdBucketId)
const res = await storage.deleteBucket(newBucketName)
expect(res.error).toBeNull()
expect(res.data).toMatchSnapshot()
})

0 comments on commit 31d6876

Please sign in to comment.