|
2 | 2 | DeleteObjectsCommand, |
3 | 3 | GetObjectCommand, |
4 | 4 | HeadObjectCommand, |
| 5 | + ListObjectsV2Command, |
5 | 6 | PutObjectCommand, |
6 | 7 | S3Client, |
7 | 8 | } from '@aws-sdk/client-s3' |
@@ -163,6 +164,53 @@ describe('S3Backend', () => { |
163 | 164 | }) |
164 | 165 | }) |
165 | 166 |
|
| 167 | + describe('list', () => { |
| 168 | + test('filters listed keys by cutoff date and strips the requested prefix', async () => { |
| 169 | + mockSend.mockResolvedValue({ |
| 170 | + Contents: [ |
| 171 | + { |
| 172 | + Key: 'tenant/bucket/old.txt', |
| 173 | + LastModified: new Date('2024-01-01T00:00:00.000Z'), |
| 174 | + Size: 12, |
| 175 | + }, |
| 176 | + { |
| 177 | + Key: 'tenant/bucket/new.txt', |
| 178 | + LastModified: new Date('2024-01-03T00:00:00.000Z'), |
| 179 | + Size: 34, |
| 180 | + }, |
| 181 | + { |
| 182 | + Key: 'tenant/bucket/no-date.txt', |
| 183 | + Size: 56, |
| 184 | + }, |
| 185 | + { |
| 186 | + LastModified: new Date('2024-01-01T00:00:00.000Z'), |
| 187 | + Size: 78, |
| 188 | + }, |
| 189 | + ], |
| 190 | + NextContinuationToken: 'next-page', |
| 191 | + }) |
| 192 | + |
| 193 | + const backend = createBackend() |
| 194 | + |
| 195 | + await expect( |
| 196 | + backend.list('test-bucket', { |
| 197 | + prefix: 'tenant/bucket', |
| 198 | + beforeDate: new Date('2024-01-02T00:00:00.000Z'), |
| 199 | + }) |
| 200 | + ).resolves.toEqual({ |
| 201 | + keys: [{ name: 'old.txt', size: 12 }], |
| 202 | + nextToken: 'next-page', |
| 203 | + }) |
| 204 | + |
| 205 | + expect(mockSend).toHaveBeenCalledTimes(1) |
| 206 | + expect(mockSend.mock.calls[0][0]).toBeInstanceOf(ListObjectsV2Command) |
| 207 | + expect(mockSend.mock.calls[0][0].input).toMatchObject({ |
| 208 | + Bucket: 'test-bucket', |
| 209 | + Prefix: 'tenant/bucket', |
| 210 | + }) |
| 211 | + }) |
| 212 | + }) |
| 213 | + |
166 | 214 | describe('deleteObjects', () => { |
167 | 215 | test('chunks DeleteObjectsCommand payloads to the S3 key limit', async () => { |
168 | 216 | mockSend.mockResolvedValue({ |
|
0 commit comments