-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.test.ts
More file actions
56 lines (48 loc) · 2.1 KB
/
utils.test.ts
File metadata and controls
56 lines (48 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { parseListObjectsUserMetadataMiddleware } from '../../../src/commands/s3Extended/utils';
describe('parseListObjectsUserMetadataMiddleware', () => {
function buildXml(contents: Record<string, string>[]): string {
const inner = contents.map(obj => `<Contents>${
Object.entries(obj).map(([k, v]) => `<${k}>${v}</${k}>`).join('')
}</Contents>`).join('');
return `<ListBucketResult>${inner}</ListBucketResult>`;
}
function createNext(output: unknown) {
return async () => ({ output });
}
it('should extract user metadata when XML contains a single Contents element', async () => {
const captured = {
xml: buildXml([
{ 'Key': 'obj1', 'x-amz-meta-foo': 'bar' },
]),
};
const middleware = parseListObjectsUserMetadataMiddleware(captured);
const result = await middleware(createNext({
Contents: [{ Key: 'obj1' }],
}))({ request: {} });
expect(result.output.Contents[0]['x-amz-meta-foo']).toBe('bar');
});
it('should extract user metadata when XML contains multiple Contents elements', async () => {
const captured = {
xml: buildXml([
{ 'Key': 'obj1', 'x-amz-meta-foo': 'bar' },
{ 'Key': 'obj2', 'x-amz-meta-foo': 'baz' },
]),
};
const middleware = parseListObjectsUserMetadataMiddleware(captured);
const result = await middleware(createNext({
Contents: [{ Key: 'obj1' }, { Key: 'obj2' }],
}))({ request: {} });
expect(result.output.Contents[0]['x-amz-meta-foo']).toBe('bar');
expect(result.output.Contents[1]['x-amz-meta-foo']).toBe('baz');
});
it('should handle empty Contents gracefully', async () => {
const captured = {
xml: buildXml([]),
};
const middleware = parseListObjectsUserMetadataMiddleware(captured);
const result = await middleware(createNext({
Contents: undefined,
}))({ request: {} });
expect(result.output.Contents).toBeUndefined();
});
});