Skip to content

Commit

Permalink
refactor: tests/integration/commands/addons/addons.test.mjs (#5887)
Browse files Browse the repository at this point in the history
- convert to ESM
- replace ava with vitest

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
hereje and kodiakhq[bot] authored Jul 28, 2023
1 parent 3678e31 commit 2c0657e
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 157 deletions.
157 changes: 0 additions & 157 deletions tests/integration/10.command.addons.test.cjs

This file was deleted.

158 changes: 158 additions & 0 deletions tests/integration/commands/addons/addons.test.mjs
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)
})
})
})
})

1 comment on commit 2c0657e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,303
  • Package size: 271 MB

Please sign in to comment.