-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: tests/integration/commands/addons/addons.test.mjs (#5887)
- convert to ESM - replace ava with vitest Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3678e31
commit 2c0657e
Showing
2 changed files
with
158 additions
and
157 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,158 @@ | ||
import { describe, test } from 'vitest' | ||
|
||
import callCli from '../../utils/call-cli.cjs' | ||
import { getCLIOptions, withMockApi } from '../../utils/mock-api.cjs' | ||
import { withSiteBuilder } from '../../utils/site-builder.cjs' | ||
|
||
const siteInfo = { | ||
account_slug: 'test-account', | ||
id: 'site_id', | ||
name: 'site-name', | ||
} | ||
const routes = [ | ||
{ path: 'sites/site_id', response: siteInfo }, | ||
{ path: 'sites/site_id/service-instances', response: [] }, | ||
{ | ||
path: 'accounts', | ||
response: [{ slug: siteInfo.account_slug }], | ||
}, | ||
] | ||
describe.concurrent('command-addons', () => { | ||
test('netlify addons:list', async (t) => { | ||
await withSiteBuilder('site-with-addons', async (builder) => { | ||
await builder.buildAsync() | ||
|
||
await withMockApi(routes, async ({ apiUrl }) => { | ||
const cliResponse = await callCli(['addons:list'], getCLIOptions({ builder, apiUrl })) | ||
t.expect(cliResponse.includes('No addons currently installed')).toBe(true) | ||
}) | ||
}) | ||
}) | ||
|
||
test('netlify addons:list --json', async (t) => { | ||
await withSiteBuilder('site-with-addons', async (builder) => { | ||
await builder.buildAsync() | ||
|
||
await withMockApi(routes, async ({ apiUrl }) => { | ||
const cliResponse = await callCli(['addons:list', '--json'], getCLIOptions({ builder, apiUrl })) | ||
const json = JSON.parse(cliResponse) | ||
t.expect(Array.isArray(json)).toBe(true) | ||
t.expect(json.length).toBe(0) | ||
}) | ||
}) | ||
}) | ||
|
||
test('netlify addons:create demo', async (t) => { | ||
await withSiteBuilder('site-with-addons', async (builder) => { | ||
await builder.buildAsync() | ||
|
||
const createRoutes = [ | ||
...routes, | ||
{ path: 'services/demo/manifest', response: {} }, | ||
{ | ||
path: 'sites/site_id/services/demo/instances', | ||
response: {}, | ||
method: 'POST', | ||
requestBody: { config: { TWILIO_ACCOUNT_SID: 'foo' } }, | ||
}, | ||
] | ||
|
||
await withMockApi(createRoutes, async ({ apiUrl }) => { | ||
const cliResponse = await callCli( | ||
['addons:create', 'demo', '--TWILIO_ACCOUNT_SID', 'foo'], | ||
getCLIOptions({ builder, apiUrl }), | ||
) | ||
t.expect(cliResponse.includes('Add-on "demo" created')).toBe(true) | ||
}) | ||
}) | ||
}) | ||
|
||
test('After creation netlify addons:list --json', async (t) => { | ||
await withSiteBuilder('site-with-addons', async (builder) => { | ||
await builder.buildAsync() | ||
|
||
const withExistingAddon = [ | ||
{ path: 'sites/site_id', response: siteInfo }, | ||
{ | ||
path: 'sites/site_id/service-instances', | ||
response: [{ service_slug: 'demo' }], | ||
}, | ||
{ | ||
path: 'accounts', | ||
response: [{ slug: siteInfo.account_slug }], | ||
}, | ||
] | ||
|
||
await withMockApi(withExistingAddon, async ({ apiUrl }) => { | ||
const cliResponse = await callCli(['addons:list', '--json'], getCLIOptions({ builder, apiUrl })) | ||
const json = JSON.parse(cliResponse) | ||
t.expect(Array.isArray(json)).toBe(true) | ||
t.expect(json.length).toBe(1) | ||
t.expect(json[0].service_slug).toEqual('demo') | ||
}) | ||
}) | ||
}) | ||
|
||
test('netlify addons:config demo', async (t) => { | ||
await withSiteBuilder('site-with-addons', async (builder) => { | ||
await builder.buildAsync() | ||
|
||
const configRoutes = [ | ||
{ path: 'sites/site_id', response: siteInfo }, | ||
{ | ||
path: 'sites/site_id/service-instances', | ||
response: [{ id: 'demo', service_slug: 'demo', config: { TWILIO_ACCOUNT_SID: 'foo' } }], | ||
}, | ||
{ | ||
path: 'accounts', | ||
response: [{ slug: siteInfo.account_slug }], | ||
}, | ||
{ path: 'services/demo/manifest', response: { config: { TWILIO_ACCOUNT_SID: '' } } }, | ||
{ | ||
path: 'sites/site_id/services/demo/instances/demo', | ||
response: {}, | ||
method: 'PUT', | ||
requestBody: { config: { TWILIO_ACCOUNT_SID: 'bar' } }, | ||
}, | ||
] | ||
|
||
await withMockApi(configRoutes, async ({ apiUrl }) => { | ||
const cliResponse = await callCli( | ||
['addons:config', 'demo', '--TWILIO_ACCOUNT_SID', 'bar'], | ||
getCLIOptions({ builder, apiUrl }), | ||
) | ||
t.expect(cliResponse.includes('Updating demo add-on config values')).toBe(true) | ||
t.expect(cliResponse.includes('Add-on "demo" successfully updated')).toBe(true) | ||
}) | ||
}) | ||
}) | ||
|
||
test('netlify addon:delete demo', async (t) => { | ||
await withSiteBuilder('site-with-addons', async (builder) => { | ||
await builder.buildAsync() | ||
|
||
const deleteRoutes = [ | ||
{ path: 'sites/site_id', response: siteInfo }, | ||
{ | ||
path: 'sites/site_id/service-instances', | ||
response: [{ id: 'demo', service_slug: 'demo', config: { TWILIO_ACCOUNT_SID: 'foo' } }], | ||
}, | ||
{ | ||
path: 'accounts', | ||
response: [{ slug: siteInfo.account_slug }], | ||
}, | ||
{ path: 'services/demo/manifest', response: {} }, | ||
{ | ||
path: 'sites/site_id/services/demo/instances/demo', | ||
response: {}, | ||
method: 'DELETE', | ||
}, | ||
] | ||
|
||
await withMockApi(deleteRoutes, async ({ apiUrl }) => { | ||
const cliResponse = await callCli(['addons:delete', 'demo', '-f'], getCLIOptions({ builder, apiUrl })) | ||
t.expect(cliResponse.includes('Addon "demo" deleted')).toBe(true) | ||
}) | ||
}) | ||
}) | ||
}) |
2c0657e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📊 Benchmark results