Skip to content

Commit

Permalink
Restored a needed detail to cfAPINocks and straightened out S3SiteRem…
Browse files Browse the repository at this point in the history
…over.test
  • Loading branch information
svenaas committed Oct 26, 2023
1 parent 2e0e8be commit 9f1b468
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/api/support/cfAPINocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const mockFetchSpacesRequest = (name, resources) =>
const mockDefaultCredentials = (exists = true) => {
const serviceGuid = 'testing-guid';
const serviceName = 'federalist-dev-s3';
const credentials = factory.responses.credentials();
const credentials = exists ? factory.responses.credentials() : [];

return mockFetchServiceInstanceCredentialsRequest(serviceName, {
guid: serviceGuid,
Expand Down
28 changes: 25 additions & 3 deletions test/api/unit/services/S3SiteRemover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ function createServiceNocks(serviceName, guid, bucketName) {
factory.createCFAPIResourceList({ resources: [serviceInstanceResponse] }),
serviceName
);
}

function createCredentialsNock(serviceName, guid, bucketName) {
const credentialsResponse = factory.responses.credentials({
bucket: bucketName,
});
Expand All @@ -44,6 +46,7 @@ describe('S3SiteRemover', () => {
after(() => s3Mock.restore());

beforeEach(() => {
s3Mock.reset();
s3Mock.on(HeadBucketCommand).resolves({});
createServiceNocks(s3ServiceName, s3ServiceGuid, awsBucketName);
});
Expand All @@ -52,6 +55,7 @@ describe('S3SiteRemover', () => {

describe('.removeSite(site)', () => {
it('should delete all objects in the site\'s S3 bucket', (done) => {
createCredentialsNock(s3ServiceName, s3ServiceGuid, awsBucketName);
let site;
const objectsToDelete = [
'site/owner/repo/index.html',
Expand All @@ -77,9 +81,7 @@ describe('S3SiteRemover', () => {
deletionBucket = input.Bucket;
deletedObjects = input.Delete.Objects;
return {};
})
.on(HeadBucketCommand)
.resolves({});
});

mockTokenRequest();
apiNocks.mockDefaultCredentials();
Expand All @@ -103,6 +105,24 @@ describe('S3SiteRemover', () => {
mockTokenRequest();
apiNocks.mockDefaultCredentials(false);

s3Mock
.on(ListObjectsV2Command, {
Bucket: undefined,
Delimiter: '/',
ContinuationToken: undefined,
MaxKeys: undefined,
}).resolves({
IsTruncated: false,
CommonPrefixes: [],
Contents: [],
ContinuationToken: 'A',
NextContinuationToken: null,
})
.on(DeleteObjectsCommand, {
Bucket: undefined,
Delete: { Objects: [] },
}).resolves();

factory
.site()
.then(site => S3SiteRemover.removeSite(site))
Expand All @@ -111,6 +131,8 @@ describe('S3SiteRemover', () => {
});

describe('.removeInfrastructure', () => {
beforeEach(() => createCredentialsNock(s3ServiceName, s3ServiceGuid, awsBucketName));

it('should delete the bucket and proxy route service when site is in a private bucket', (done) => {
let site;
const s3Service = 'this-is-a-s3-service';
Expand Down

0 comments on commit 9f1b468

Please sign in to comment.