From b4d139a2d011c14918590b3a9e371ff001687d78 Mon Sep 17 00:00:00 2001 From: Sven Aas Date: Thu, 26 Oct 2023 17:00:24 -0400 Subject: [PATCH] Add tests for getCommonPrefixes. --- test/api/unit/services/S3Helper.test.js | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/api/unit/services/S3Helper.test.js b/test/api/unit/services/S3Helper.test.js index 1c6f564d3..329644994 100644 --- a/test/api/unit/services/S3Helper.test.js +++ b/test/api/unit/services/S3Helper.test.js @@ -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)', () => {