Skip to content

Commit

Permalink
test(amplify-category-api): add unit test for generating sandbox mode…
Browse files Browse the repository at this point in the history
… directive; rm unused method
  • Loading branch information
danielleadams committed Sep 8, 2021
1 parent 37f7ed4 commit e3a1c25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineGlobalSandboxMode } from '../../../../provider-utils/awscloudformation/utils/global-sandbox-mode';
import { $TSContext } from 'amplify-cli-core';

describe('global sandbox mode GraphQL directive', () => {
it('returns AMPLIFY_DIRECTIVE type with code comment, directive, and env name', () => {
const envName = 'envone';
const ctx = <$TSContext>{
amplify: {
getEnvInfo() {
return { envName };
},
},
};

expect(defineGlobalSandboxMode(ctx))
.toBe(`# This allows public create, read, update, and delete access for a limited time to all models via API Key.
# To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth
type AMPLIFY_GLOBAL @allow_public_data_access_with_api_key(in: \"${envName}\") # FOR TESTING ONLY!\n
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,6 @@ class CfnApiArtifactHandler implements ApiArtifactHandler {
printApiKeyWarnings(this.context, oldConfigHadApiKey, authConfigHasApiKey(authConfig));
};

updateArtifactsWithoutCompile = async (request: UpdateApiRequest): Promise<void> => {
const updates = request.serviceModification;
const apiName = getAppSyncResourceName(this.context.amplify.getProjectMeta());
if (!apiName) {
throw new Error(`No AppSync API configured in the project. Use 'amplify add api' to create an API.`);
}
const resourceDir = this.getResourceDir(apiName);
if (updates.transformSchema) {
this.writeSchema(resourceDir, updates.transformSchema);
}
if (updates.conflictResolution) {
updates.conflictResolution = await this.createResolverResources(updates.conflictResolution);
await writeResolverConfig(updates.conflictResolution, resourceDir);
}
const authConfig = getAppSyncAuthConfig(this.context.amplify.getProjectMeta());

if (updates.defaultAuthType) authConfig.defaultAuthentication = appSyncAuthTypeToAuthConfig(updates.defaultAuthType);
if (updates.additionalAuthTypes)
authConfig.additionalAuthenticationProviders = updates.additionalAuthTypes.map(appSyncAuthTypeToAuthConfig);

this.context.amplify.updateamplifyMetaAfterResourceUpdate(category, apiName, 'output', { authConfig });
this.context.amplify.updateBackendConfigAfterResourceUpdate(category, apiName, 'output', { authConfig });
};

private writeSchema = (resourceDir: string, schema: string) => {
fs.writeFileSync(path.join(resourceDir, gqlSchemaFilename), schema);
};
Expand Down

0 comments on commit e3a1c25

Please sign in to comment.