Skip to content

Commit

Permalink
Add special message for missing mailchimp audience secret
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickreimer committed Nov 25, 2019
1 parent 8f1cc4b commit 205eedd
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
21 changes: 18 additions & 3 deletions src/cmds/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const printError = (error, idx) => {
console.error('');
console.error(indent(body, 7));
console.error('');
console.error('');
}
};

Expand Down Expand Up @@ -80,8 +81,24 @@ const errorMessage = error => {
Copy the generated key and run the following command:
${chalk.gray('$')} statickit secrets add ${chalk.cyan(error.properties.secret_key)} ${chalk.yellow('<paste-api-key-here>')}
`;

break;

Then, try deploying again.
case 'mailchimp_audience':
// prettier-ignore
body = stripIndent`
Here's how to found your Audience ID:
• Log in to your Mailchimp account
• Click the ${chalk.bold.cyan('Audience')} tab at the top
• Navigate to ${chalk.bold.cyan('Manage Audience › Settings')}
• Click ${chalk.bold.cyan('Audience name and defaults')}
• Locate the value under the "Audience ID" heading
Copy the ID and run the following command:
${chalk.gray('$')} statickit secrets add ${chalk.cyan(error.properties.secret_key)} ${chalk.yellow('<paste-audience-id-here>')}
`;

break;
Expand All @@ -92,8 +109,6 @@ const errorMessage = error => {
Run the following command to add this secret:
${chalk.gray('$')} statickit secrets add ${chalk.cyan(error.properties.secret_key)} ${chalk.yellow('<enter-the-value-here>')}
Then, try deploying again.
`;
break;
}
Expand Down
49 changes: 46 additions & 3 deletions test/cmds/__snapshots__/deploy.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Array [
]
`;

exports[`displays instructions for a missing mailchimp api keys 1`] = `
exports[`displays instructions for a missing mailchimp api key 1`] = `
Array [
Array [
"✕ Deployment failed (xxxx-xxxx-xxxx)",
Expand All @@ -41,9 +41,49 @@ Array [
Copy the generated key and run the following command:
$ statickit secrets add my-mailchimp-key <paste-api-key-here>
$ statickit secrets add my-mailchimp-key <paste-api-key-here>",
],
Array [
"",
],
Array [
"",
],
Array [
"",
],
]
`;
exports[`displays instructions for a missing mailchimp audience 1`] = `
Array [
Array [
"✕ Deployment failed (xxxx-xxxx-xxxx)",
],
Array [
"",
],
Array [
" 1) The secret @my-mailchimp-audience is not defined yet (actions[0].audience)",
],
Array [
"",
],
Array [
" Here's how to found your Audience ID:
Then, try deploying again.",
• Log in to your Mailchimp account
• Click the Audience tab at the top
• Navigate to Manage Audience › Settings
• Click Audience name and defaults
• Locate the value under the \\"Audience ID\\" heading
Copy the ID and run the following command:
$ statickit secrets add my-mailchimp-audience <paste-audience-id-here>",
],
Array [
"",
],
Array [
"",
Expand Down Expand Up @@ -90,6 +130,9 @@ Array [
Array [
"",
],
Array [
"",
],
]
`;
Expand Down
33 changes: 32 additions & 1 deletion test/cmds/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ it('sends a deploy request with the right params', async () => {
expect(console.log.mock.calls).toMatchSnapshot();
});

it('displays instructions for a missing mailchimp api keys', async () => {
it('displays instructions for a missing mailchimp api key', async () => {
const config = {};
const args = { config: JSON.stringify(config), key: 'xxx' };

Expand Down Expand Up @@ -66,6 +66,37 @@ it('displays instructions for a missing mailchimp api keys', async () => {
expect(console.error.mock.calls).toMatchSnapshot();
});

it('displays instructions for a missing mailchimp audience', async () => {
const config = {};
const args = { config: JSON.stringify(config), key: 'xxx' };

deploy.getRawConfig.mockImplementation(args => args.config);
deploy.getDeployKey.mockImplementation(args => args.key);

deploy.request.mockImplementation(_params => {
return Promise.resolve({
status: 422,
data: {
id: 'xxxx-xxxx-xxxx',
errors: [
{
code: 'SECRET_REQUIRED',
field: 'actions[0].audience',
message: 'is required',
properties: {
secret_type: 'mailchimp_audience',
secret_key: 'my-mailchimp-audience'
}
}
]
}
});
});

await cmd.handler(args);
expect(console.error.mock.calls).toMatchSnapshot();
});

it('displays instructions when a secret reference is required', async () => {
const config = {};
const args = { config: JSON.stringify(config), key: 'xxx' };
Expand Down

0 comments on commit 205eedd

Please sign in to comment.