Skip to content

Commit fc16aa6

Browse files
committed
fix: add delete many test
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent a55b5e2 commit fc16aa6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/test/object.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,65 @@ describe('testing deleting multiple objects', () => {
16211621
expect(results).toHaveLength(1)
16221622
expect(results[0].name).toBe('authenticated/delete-multiple7.png')
16231623
})
1624+
1625+
test('can delete multiple objects with Unicode keys', async () => {
1626+
const authorization = `Bearer ${await serviceKeyAsync}`
1627+
const path = './src/test/assets/sadcat.jpg'
1628+
const { size } = fs.statSync(path)
1629+
const prefixes = [
1630+
`authenticated/delete-many-${randomUUID()}-일이삼-🙂.png`,
1631+
`authenticated/delete-many-${randomUUID()}-éè-中文.png`,
1632+
]
1633+
1634+
for (const prefix of prefixes) {
1635+
const uploadResponse = await appInstance.inject({
1636+
method: 'PUT',
1637+
url: `/object/bucket2/${encodeURIComponent(prefix)}`,
1638+
headers: {
1639+
authorization,
1640+
'Content-Length': size,
1641+
'Content-Type': 'image/jpeg',
1642+
},
1643+
payload: fs.createReadStream(path),
1644+
})
1645+
1646+
expect(uploadResponse.statusCode).toBe(200)
1647+
}
1648+
1649+
const deleteResponse = await appInstance.inject({
1650+
method: 'DELETE',
1651+
url: '/object/bucket2',
1652+
headers: {
1653+
authorization,
1654+
},
1655+
payload: {
1656+
prefixes,
1657+
},
1658+
})
1659+
1660+
expect(deleteResponse.statusCode).toBe(200)
1661+
expect(S3Backend.prototype.deleteObjects).toBeCalled()
1662+
const results = JSON.parse(deleteResponse.body)
1663+
expect(results).toHaveLength(2)
1664+
expect(results.map((item: { name: string }) => item.name).sort()).toEqual([...prefixes].sort())
1665+
1666+
for (const prefix of prefixes) {
1667+
const getResponse = await appInstance.inject({
1668+
method: 'GET',
1669+
url: `/object/bucket2/${encodeURIComponent(prefix)}`,
1670+
headers: {
1671+
authorization,
1672+
},
1673+
})
1674+
1675+
expect(getResponse.statusCode).toBe(400)
1676+
expect(getResponse.json()).toMatchObject({
1677+
statusCode: '404',
1678+
error: 'not_found',
1679+
message: 'Object not found',
1680+
})
1681+
}
1682+
})
16241683
})
16251684

16261685
/**

0 commit comments

Comments
 (0)