Skip to content

Commit

Permalink
feat: return size and mime types in bucket GET (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
inian committed Apr 9, 2023
1 parent 24cabad commit 5dca04d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/http/routes/bucket/getAllBuckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const successResponseSchema = {
id: 'avatars',
name: 'avatars',
owner: '4d56e902-f0a0-4662-8448-a4d9e643c142',
public: false,
file_size_limit: 1000000,
allowed_mime_types: ['image/png', 'image/jpeg'],
created_at: '2021-02-17T04:43:32.770206+00:00',
updated_at: '2021-02-17T04:43:32.770206+00:00',
},
Expand All @@ -33,7 +36,7 @@ export default async function routes(fastify: FastifyInstance) {
},
async (request, response) => {
const results = await request.storage.listBuckets(
'id, name, public, owner, created_at, updated_at'
'id, name, public, owner, created_at, updated_at, file_size_limit, allowed_mime_types'
)

request.log.info({ results }, 'results')
Expand Down
3 changes: 3 additions & 0 deletions src/storage/schemas/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const bucketSchema = {
{
id: 'bucket2',
name: 'bucket2',
public: false,
file_size_limit: 1000000,
allowed_mime_types: ['image/png', 'image/jpeg'],
owner: '4d56e902-f0a0-4662-8448-a4d9e643c142',
created_at: '2021-02-17T04:43:32.770206+00:00',
updated_at: '2021-02-17T04:43:32.770206+00:00',
Expand Down
15 changes: 14 additions & 1 deletion src/test/bucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ describe('testing GET bucket', () => {
})
expect(response.statusCode).toBe(200)
const responseJSON = JSON.parse(response.body)
expect(responseJSON.id).toBe(bucketId)
expect(responseJSON).toMatchObject({
id: bucketId,
name: bucketId,
public: false,
file_size_limit: 0,
allowed_mime_types: null,
})
})

test('checking RLS: anon user is not able to get bucket details', async () => {
Expand Down Expand Up @@ -98,6 +104,13 @@ describe('testing GET all buckets', () => {
expect(response.statusCode).toBe(200)
const responseJSON = JSON.parse(response.body)
expect(responseJSON.length).toBe(10)
expect(responseJSON[0]).toMatchObject({
id: expect.any(String),
name: expect.any(String),
public: expect.any(Boolean),
file_size_limit: expect.any(Number),
allowed_mime_types: null,
})
})

test('checking RLS: anon user is not able to get all buckets', async () => {
Expand Down

0 comments on commit 5dca04d

Please sign in to comment.