Skip to content

Commit

Permalink
Add tests for getCommonPrefixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
svenaas committed Oct 26, 2023
1 parent 04ac373 commit b4d139a
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/api/unit/services/S3Helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,59 @@ describe('S3Helper', () => {
});

describe('.listCommonPrefixes(prefix)', () => {
it('can get common prefixes', (done) => {
const prefix = 'some-prefix/';

s3Mock.on(ListObjectsV2Command, {
Bucket: config.s3.bucket,
Prefix: prefix,
}).resolvesOnce({
IsTruncated: false,
CommonPrefixes: ['a', 'b', 'c'],
ContinuationToken: null,
NextContinuationToken: null,
});

const client = new S3Helper.S3Client(config.s3);
client.listCommonPrefixes(prefix)
.then((objects) => {
expect(objects).to.deep.equal(['a', 'b', 'c']);
done();
})
.catch(done);
});

it('can get all common prefixes when initial response is truncated', (done) => {
const prefix = 'abc/123/';

s3Mock.on(ListObjectsV2Command, {
Bucket: config.s3.bucket,
Prefix: prefix,
}).resolvesOnce({
IsTruncated: true,
CommonPrefixes: [1, 2, 3],
ContinuationToken: 'first-token',
NextContinuationToken: 'next-token',
}).resolvesOnce({
IsTruncated: true,
CommonPrefixes: [4, 5, 6],
ContinuationToken: 'next-token',
NextContinuationToken: 'last-token',
}).resolvesOnce({
IsTruncated: true,
CommonPrefixes: [7, 8, 9],
ContinuationToken: 'last-token',
NextContinuationToken: null,
});

const client = new S3Helper.S3Client(config.s3);
client.listCommonPrefixes(prefix)
.then((objects) => {
expect(objects).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9]);
done();
})
.catch(done);
});
});

describe('.listObjectsPaged(prefix, maxObjects, startAfter)', () => {
Expand Down

0 comments on commit b4d139a

Please sign in to comment.