-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb9fae7
commit 3e5f860
Showing
6 changed files
with
238 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`displays general validation errors 1`] = ` | ||
Array [ | ||
Array [ | ||
"[31m[1m✕[22m[39m [31m[1mDeployment failed [90m(xxxx-xxxx-xxxx)[31m[22m[39m", | ||
], | ||
Array [ | ||
"", | ||
], | ||
Array [ | ||
" 1) [36mname[39m is required", | ||
], | ||
Array [ | ||
"", | ||
], | ||
] | ||
`; | ||
|
||
exports[`displays instructions for a missing mailchimp api keys 1`] = ` | ||
Array [ | ||
Array [ | ||
"[31m[1m✕[22m[39m [31m[1mDeployment failed [90m(xxxx-xxxx-xxxx)[31m[22m[39m", | ||
], | ||
Array [ | ||
"", | ||
], | ||
Array [ | ||
" 1) The secret [36m[1m@my-mailchimp-key[22m[39m is not defined yet [90m(actions[0].apiKey)[39m", | ||
], | ||
Array [ | ||
"", | ||
], | ||
Array [ | ||
" Here's where to find your API key: | ||
• Log in to your Mailchimp account | ||
• Open the menu with your avatar in the upper right | ||
• Navigate to [1m[36mProfile › Extras › API keys[39m[22m | ||
• Under \\"Your API keys\\", click [1m[36mCreate A Key[39m[22m | ||
Copy the generated key and run the following command: | ||
[90m$[39m statickit secrets add [36mmy-mailchimp-key[39m [33m<paste-api-key-here>[39m | ||
Then, try deploying again.", | ||
], | ||
Array [ | ||
"", | ||
], | ||
Array [ | ||
"", | ||
], | ||
] | ||
`; | ||
exports[`displays instructions when a secret reference is required 1`] = ` | ||
Array [ | ||
Array [ | ||
"[31m[1m✕[22m[39m [31m[1mDeployment failed [90m(xxxx-xxxx-xxxx)[31m[22m[39m", | ||
], | ||
Array [ | ||
"", | ||
], | ||
Array [ | ||
" 1) [36m[1mactions[0].apiKey[22m[39m must reference a secret (e.g. [36m[1m@mailchimp-api-key[22m[39m)", | ||
], | ||
Array [ | ||
"", | ||
], | ||
Array [ | ||
" This field must reference a secret instead of a raw value, | ||
because it's too sensitive to commit to version control. | ||
[33m[1m-- Instructions ----------------------------------------------------------[22m[39m | ||
First, choose a name for this value and run the following command: | ||
[90m$[39m statickit secrets add [36mmailchimp-api-key[39m [32m\\"myinlinekey\\"[39m | ||
Then, reference your secret like this (notice the @-symbol prefix): | ||
{ | ||
[32m\\"apiKey\\"[39m: [32m\\"@mailchimp-api-key\\"[39m | ||
}", | ||
], | ||
Array [ | ||
"", | ||
], | ||
Array [ | ||
"", | ||
], | ||
] | ||
`; | ||
exports[`sends a deploy request with the right params 1`] = ` | ||
Array [ | ||
Array [ | ||
"[32m✔[39m [32mDeployment succeeded [90m(xxxx-xxxx-xxxx)[32m[39m", | ||
], | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
const deploy = require('@statickit/deploy'); | ||
const version = require('../../package.json').version; | ||
|
||
jest.mock('process', () => ({ env: {} })); | ||
jest.mock('@statickit/deploy'); | ||
|
||
const cmd = require('../../src/cmds/deploy'); | ||
|
||
beforeEach(() => { | ||
jest.spyOn(console, 'log').mockImplementation(); | ||
jest.spyOn(console, 'error').mockImplementation(); | ||
}); | ||
|
||
afterEach(() => { | ||
console.log.mockRestore(); | ||
console.error.mockRestore(); | ||
}); | ||
|
||
it('sends a deploy request with the right params', async () => { | ||
const config = { forms: { newsletter: { name: 'Newsletter' } } }; | ||
const args = { config: JSON.stringify(config), key: 'xxx' }; | ||
|
||
deploy.getRawConfig.mockImplementation(args => args.config); | ||
deploy.getDeployKey.mockImplementation(args => args.key); | ||
|
||
deploy.request.mockImplementation(params => { | ||
expect(params.config).toStrictEqual(config); | ||
expect(params.key).toBe('xxx'); | ||
expect(params.userAgent).toBe(`@statickit/cli@${version}`); | ||
|
||
return Promise.resolve({ status: 200, data: { id: 'xxxx-xxxx-xxxx' } }); | ||
}); | ||
|
||
await cmd.handler(args); | ||
expect(console.log.mock.calls).toMatchSnapshot(); | ||
}); | ||
|
||
it('displays instructions for a missing mailchimp api keys', 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].apiKey', | ||
message: 'is required', | ||
properties: { | ||
secret_type: 'mailchimp_api_key', | ||
secret_key: 'my-mailchimp-key' | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
|
||
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' }; | ||
|
||
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_REFERENCE_REQUIRED', | ||
field: 'actions[0].apiKey', | ||
message: 'must reference a secret (e.g. @mailchimp-api-key)', | ||
properties: { | ||
example_value: 'mailchimp-api-key', | ||
given_value: 'myinlinekey' | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
|
||
await cmd.handler(args); | ||
expect(console.error.mock.calls).toMatchSnapshot(); | ||
}); | ||
|
||
it('displays general validation errors', 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: 'REQUIRED', | ||
field: 'name', | ||
message: 'is required', | ||
properties: {} | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
|
||
await cmd.handler(args); | ||
expect(console.error.mock.calls).toMatchSnapshot(); | ||
}); |
4 changes: 2 additions & 2 deletions
4
test/secret_cmds/add.test.js → test/cmds/secret_cmds/add.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/secret_cmds/delete.test.js → test/cmds/secret_cmds/delete.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/secret_cmds/update.test.js → test/cmds/secret_cmds/update.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters