From 2c0657e654a2685bc093b43fecc7ee4e59e04def Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Fri, 28 Jul 2023 12:02:02 -0600 Subject: [PATCH] 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> --- tests/integration/10.command.addons.test.cjs | 157 ----------------- .../commands/addons/addons.test.mjs | 158 ++++++++++++++++++ 2 files changed, 158 insertions(+), 157 deletions(-) delete mode 100644 tests/integration/10.command.addons.test.cjs create mode 100644 tests/integration/commands/addons/addons.test.mjs diff --git a/tests/integration/10.command.addons.test.cjs b/tests/integration/10.command.addons.test.cjs deleted file mode 100644 index face72eb064..00000000000 --- a/tests/integration/10.command.addons.test.cjs +++ /dev/null @@ -1,157 +0,0 @@ -const test = require('ava') - -const callCli = require('./utils/call-cli.cjs') -const { getCLIOptions, withMockApi } = require('./utils/mock-api.cjs') -const { withSiteBuilder } = require('./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 }], - }, -] - -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.true(cliResponse.includes('No addons currently installed')) - }) - }) -}) - -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.true(Array.isArray(json)) - t.is(json.length, 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.true(cliResponse.includes('Add-on "demo" created')) - }) - }) -}) - -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.true(Array.isArray(json)) - t.is(json.length, 1) - t.is(json[0].service_slug, '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.true(cliResponse.includes('Updating demo add-on config values')) - t.true(cliResponse.includes('Add-on "demo" successfully updated')) - }) - }) -}) - -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.true(cliResponse.includes('Addon "demo" deleted')) - }) - }) -}) diff --git a/tests/integration/commands/addons/addons.test.mjs b/tests/integration/commands/addons/addons.test.mjs new file mode 100644 index 00000000000..912d43ccb3c --- /dev/null +++ b/tests/integration/commands/addons/addons.test.mjs @@ -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) + }) + }) + }) +})