Skip to content

Commit ea9e2d3

Browse files
committed
test: add failing test for user_metadata in list response
Proves that storage.list() does not return user_metadata even though the data exists on the objects table. See #759.
1 parent 6f587b6 commit ea9e2d3

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/test/object.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,6 +2862,49 @@ describe('testing list objects', () => {
28622862
tnx = undefined
28632863
}
28642864
})
2865+
2866+
test('list returns user_metadata for files uploaded with custom metadata', async () => {
2867+
// Upload a file with custom user_metadata
2868+
const file = fs.createReadStream(`./src/test/assets/sadcat.jpg`)
2869+
const uploadResponse = await appInstance.inject({
2870+
method: 'POST',
2871+
url: '/object/bucket2/metadata-list-test.jpg',
2872+
headers: {
2873+
authorization: `Bearer ${await serviceKeyAsync}`,
2874+
'x-upsert': 'true',
2875+
'x-metadata': Buffer.from(
2876+
JSON.stringify({ custom_field: 'hello', another: 'world' })
2877+
).toString('base64'),
2878+
},
2879+
payload: file,
2880+
})
2881+
expect(uploadResponse.statusCode).toBe(200)
2882+
2883+
// List files and find our uploaded file
2884+
const listResponse = await appInstance.inject({
2885+
method: 'POST',
2886+
url: '/object/list/bucket2',
2887+
headers: {
2888+
authorization: `Bearer ${await serviceKeyAsync}`,
2889+
},
2890+
payload: {
2891+
prefix: '',
2892+
limit: 100,
2893+
offset: 0,
2894+
},
2895+
})
2896+
expect(listResponse.statusCode).toBe(200)
2897+
const results = JSON.parse(listResponse.body) as any[]
2898+
const found = results.find((r: any) => r.name === 'metadata-list-test.jpg')
2899+
expect(found).toBeDefined()
2900+
expect(found.user_metadata).toEqual({ custom_field: 'hello', another: 'world' })
2901+
2902+
// Folders should have null user_metadata
2903+
const folder = results.find((r: any) => r.id === null)
2904+
if (folder) {
2905+
expect(folder.user_metadata).toBeNull()
2906+
}
2907+
})
28652908
})
28662909

28672910
describe('x-robots-tag header', () => {

0 commit comments

Comments
 (0)