Skip to content

Commit

Permalink
fix: unit tests, make resource + bucket names optional for add (#8398)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhockett committed Oct 11, 2021
1 parent 083f7b1 commit b0814ae
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,26 @@ function constructParametersJson(parameters: $TSAny, permissions: S3Permissions,

async function createS3StorageArtifacts(context: $TSContext, storageRequest: AddStorageRequest) {
const {
serviceConfiguration: { bucketName, permissions, resourceName, lambdaTrigger },
serviceConfiguration: { permissions, lambdaTrigger },
} = storageRequest;
let {
serviceConfiguration: { bucketName, resourceName },
} = storageRequest;
let parameters = getAllDefaults(context.amplify.getProjectDetails());

if (!resourceName) {
({ resourceName } = parameters);
}

if (!bucketName) {
({ bucketName } = parameters);
}

if (isResourceNameUnique(categoryName, resourceName)) {
const resourceDirPath = pathManager.getResourceDirectoryPath(undefined, categoryName, resourceName);
fs.ensureDirSync(resourceDirPath);

// create parameters.json
let parameters = getAllDefaults(context.amplify.getProjectDetails());
parameters.bucketName = bucketName;
parameters.resourceName = resourceName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
}
},
"required": [
"bucketName",
"permissions",
"resourceName",
"serviceName"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export interface AddS3ServiceConfiguration extends S3ServiceConfigurationBase {
/**
* Amplify resource name
*/
resourceName: string;
resourceName?: string;

/**
* Globally unique bucket name
*/
bucketName: string;
bucketName?: string;

/**
* Optional parameter specifying a lambda that should run when the bucket is modified
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('rejects promise when invalid payload', () => {
await expect(resultPromise).rejects.toBeTruthy();
});

const missingFields = ['permissions', 'resourceName', 'serviceName', 'version'];
const missingFields = ['permissions', 'serviceName', 'version'];
for (const field of missingFields) {
it(`rejects request with missing field ${field}`, async () => {
const rawRequest = fs.readFileSync(path.join(assetRoot, 'storage', 'add', `invalidRequest.missing.${field}.json`), 'utf8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('rejects promise when invalid payload', () => {
const missingFields = ['resourceName', 'serviceName', 'version'];
for (const field of missingFields) {
it(`rejects request with missing field ${field}`, async () => {
const rawRequest = fs.readFileSync(path.join(assetRoot, 'storage', 'add', `invalidRequest.missing.${field}.json`), 'utf8');
const rawRequest = fs.readFileSync(path.join(assetRoot, 'storage', 'remove', `invalidRequest.missing.${field}.json`), 'utf8');
const resultPromise = validateRemoveStorageRequest(rawRequest);
await expect(resultPromise).rejects.toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('rejects promise when invalid payload', () => {
const missingFields = ['permissions', 'resourceName', 'serviceName', 'version'];
for (const field of missingFields) {
it(`rejects request with missing field ${field}`, async () => {
const rawRequest = fs.readFileSync(path.join(assetRoot, 'storage', 'add', `invalidRequest.missing.${field}.json`), 'utf8');
const rawRequest = fs.readFileSync(path.join(assetRoot, 'storage', 'update', `invalidRequest.missing.${field}.json`), 'utf8');
const resultPromise = validateUpdateStorageRequest(rawRequest);
await expect(resultPromise).rejects.toBeTruthy();
});
Expand Down

0 comments on commit b0814ae

Please sign in to comment.