diff --git a/src/cli/theme/theme-delete.e2e.test_.ts b/src/cli/theme/theme-delete.e2e.test_.ts deleted file mode 100644 index 0d1f1eab0..000000000 --- a/src/cli/theme/theme-delete.e2e.test_.ts +++ /dev/null @@ -1,181 +0,0 @@ -/* eslint-disable no-console */ -// import { jest } from '@jest/globals'; -import { spawn, spawnSync } from 'child_process'; - -const ansiEscapeCodes = - // eslint-disable-next-line no-control-regex - /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; - -/** - * Run once before running the suites in this file - */ -beforeAll(async () => { - // -}); - -/** - * Run before every test in every suite in this file - */ -beforeEach(async () => { - // delete all themes - const deleteThemesCmd = spawnSync('frodo', [ - 'theme', - 'delete', - '--all', - 'frodo-dev', - ]); - if (deleteThemesCmd.status && deleteThemesCmd.status > 0) { - console.error(deleteThemesCmd.stderr.toString()); - console.log(deleteThemesCmd.stdout.toString()); - } - - // import test themes - const importTestThemesCmd = spawnSync( - 'frodo', - ['theme', 'import', '--all-separate', 'frodo-dev'], - { - cwd: `test/e2e/theme/baseline`, - } - ); - if (importTestThemesCmd.status && importTestThemesCmd.status > 0) { - console.error(importTestThemesCmd.stderr.toString()); - console.log(importTestThemesCmd.stdout.toString()); - } -}); - -describe('frodo theme delete', () => { - it('"frodo theme delete -n Zardoz": should delete the Zardoz theme', (done) => { - const deleteThemeCmd = spawn('frodo', [ - 'theme', - 'delete', - '-n', - 'Zardoz', - 'frodo-dev', - ]); - const expected = ['✔ Deleted Zardoz.', ''].join('\n'); - const chunks: Uint8Array[] = []; - deleteThemeCmd.stderr.on('data', (chunk) => { - chunks.push(chunk); - }); - deleteThemeCmd.stderr.on('end', () => { - const output = Buffer.concat(chunks) - .toString() - .replace(ansiEscapeCodes, ''); - try { - expect(output).toContain(expected); - done(); - } catch (error) { - done(error); - } - }); - }); - - it('"frodo theme delete -n DoesNotExist": should report an error that the theme does not exist', (done) => { - const deleteThemeCmd = spawn('frodo', [ - 'theme', - 'delete', - '-n', - 'DoesNotExist', - 'frodo-dev', - ]); - const expected = ['✖ Error: DoesNotExist not found', ''].join('\n'); - const chunks: Uint8Array[] = []; - deleteThemeCmd.stderr.on('data', (chunk) => { - chunks.push(chunk); - }); - deleteThemeCmd.stderr.on('end', () => { - const output = Buffer.concat(chunks) - .toString() - .replace(ansiEscapeCodes, ''); - try { - expect(output).toContain(expected); - done(); - } catch (error) { - done(error); - } - }); - }); - - it('"frodo theme delete -i 4ded6d91-ceea-400a-ae3f-42209f1b0e06": should delete the 4ded6d91-ceea-400a-ae3f-42209f1b0e06 (Zardoz) theme', (done) => { - const deleteThemeCmd = spawn('frodo', [ - 'theme', - 'delete', - '-i', - '4ded6d91-ceea-400a-ae3f-42209f1b0e06', - 'frodo-dev', - ]); - const expected = [ - '✔ Deleted 4ded6d91-ceea-400a-ae3f-42209f1b0e06.', - '', - ].join('\n'); - const chunks: Uint8Array[] = []; - deleteThemeCmd.stderr.on('data', (chunk) => { - chunks.push(chunk); - }); - deleteThemeCmd.stderr.on('end', () => { - const output = Buffer.concat(chunks) - .toString() - .replace(ansiEscapeCodes, ''); - try { - expect(output).toContain(expected); - done(); - } catch (error) { - done(error); - } - }); - }); - - it('"frodo theme delete -i 4ded6d91-ceea-400a-ae3f-42209f1b0e07": should report an error that the theme does not exist', (done) => { - const deleteThemeCmd = spawn('frodo', [ - 'theme', - 'delete', - '-i', - '4ded6d91-ceea-400a-ae3f-42209f1b0e07', - 'frodo-dev', - ]); - const expected = [ - '✖ Error: 4ded6d91-ceea-400a-ae3f-42209f1b0e07 not found', - '', - ].join('\n'); - const chunks: Uint8Array[] = []; - deleteThemeCmd.stderr.on('data', (chunk) => { - chunks.push(chunk); - }); - deleteThemeCmd.stderr.on('end', () => { - const output = Buffer.concat(chunks) - .toString() - .replace(ansiEscapeCodes, ''); - try { - expect(output).toContain(expected); - done(); - } catch (error) { - done(error); - } - }); - }); - - it('"frodo theme delete -a": should delete all themes', (done) => { - const deleteThemeCmd = spawn('frodo', [ - 'theme', - 'delete', - '-a', - 'frodo-dev', - ]); - const expected = ['✔ Deleted all realm themes.', ''].join('\n'); - const chunks: Uint8Array[] = []; - deleteThemeCmd.stderr.on('data', (chunk) => { - chunks.push(chunk); - }); - deleteThemeCmd.stderr.on('end', () => { - const output = Buffer.concat(chunks) - .toString() - .replace(ansiEscapeCodes, ''); - try { - expect(output).toContain(expected); - done(); - } catch (error) { - done(error); - } - }); - }); -}); diff --git a/test/e2e/__snapshots__/theme-delete.e2e.test.js.snap b/test/e2e/__snapshots__/theme-delete.e2e.test.js.snap new file mode 100644 index 000000000..06da3866e --- /dev/null +++ b/test/e2e/__snapshots__/theme-delete.e2e.test.js.snap @@ -0,0 +1,61 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`frodo theme delete "frodo theme delete --all": should display error when no themes can be deleted 1`] = ` +"(Use \`frodo --trace-warnings ...\` to show where the warning was created) +Errored ➞ GET https://openam-frodo-dev.forgeblocks.com/am/json/serverinfo/* SyntaxError: /home/trivir/Work/frodo-rebase/tmp/frodo-lib/mocks/theme_2834462706/delete_1740784714/0_all_1797740195/am_1076162899/recording.har: Unexpected end of JSON input + at JSON.parse () + at Object.readFileSync (/snapshot/tmp/frodo-lib/node_modules/jsonfile/index.js:52:17) + at API.getRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/node-server/dist/cjs/pollyjs-node-server.js:37:35) + at FSPersister.onFindRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister-fs/dist/cjs/pollyjs-persister-fs.js:35:21) + at onFindRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3586:38) + at FSPersister.findRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3597:30) + at FSPersister.findEntry (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3638:34) + at HttpAdapter.replay (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1329:49) + at HttpAdapter. (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1264:19) + at HttpAdapter.handleRequest (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1219:34) +/home/trivir/Work/frodo-rebase/tmp/frodo-lib/mocks/theme_2834462706/delete_1740784714/0_all_1797740195/am_1076162899/recording.har: Unexpected end of JSON input +Unrecognized combination of options or no options... +" +`; + +exports[`frodo theme delete "frodo theme delete --theme-id 2c23505e-e10c-4f09-be73-13307f615298": should display error when the theme with id '2c23505e-e10c-4f09-be73-13307f615298' cannot be deleted since it does not exist 1`] = ` +"(Use \`frodo --trace-warnings ...\` to show where the warning was created) +Errored ➞ GET https://openam-frodo-dev.forgeblocks.com/am/json/serverinfo/* SyntaxError: /home/trivir/Work/frodo-rebase/tmp/frodo-lib/mocks/theme_2834462706/delete_1740784714/0_theme-id_1554519189/am_1076162899/recording.har: Unexpected end of JSON input + at JSON.parse () + at Object.readFileSync (/snapshot/tmp/frodo-lib/node_modules/jsonfile/index.js:52:17) + at API.getRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/node-server/dist/cjs/pollyjs-node-server.js:37:35) + at FSPersister.onFindRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister-fs/dist/cjs/pollyjs-persister-fs.js:35:21) + at onFindRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3586:38) + at FSPersister.findRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3597:30) + at FSPersister.findEntry (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3638:34) + at HttpAdapter.replay (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1329:49) + at HttpAdapter. (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1264:19) + at HttpAdapter.handleRequest (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1219:34) +/home/trivir/Work/frodo-rebase/tmp/frodo-lib/mocks/theme_2834462706/delete_1740784714/0_theme-id_1554519189/am_1076162899/recording.har: Unexpected end of JSON input +Unrecognized combination of options or no options... +" +`; + +exports[`frodo theme delete "frodo theme delete --theme-name 'Starter Theme'": should display error when the theme named 'Starter Theme' cannot be deleted since it does not exist 1`] = ` +"(Use \`frodo --trace-warnings ...\` to show where the warning was created) +Errored ➞ GET https://openam-frodo-dev.forgeblocks.com/am/json/serverinfo/* SyntaxError: /home/trivir/Work/frodo-rebase/tmp/frodo-lib/mocks/theme_2834462706/delete_1740784714/0_theme-name_1325589195/am_1076162899/recording.har: Unexpected end of JSON input + at JSON.parse () + at Object.readFileSync (/snapshot/tmp/frodo-lib/node_modules/jsonfile/index.js:52:17) + at API.getRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/node-server/dist/cjs/pollyjs-node-server.js:37:35) + at FSPersister.onFindRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister-fs/dist/cjs/pollyjs-persister-fs.js:35:21) + at onFindRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3586:38) + at FSPersister.findRecording (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3597:30) + at FSPersister.findEntry (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/persister/dist/cjs/pollyjs-persister.js:3638:34) + at HttpAdapter.replay (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1329:49) + at HttpAdapter. (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1264:19) + at HttpAdapter.handleRequest (/snapshot/tmp/frodo-lib/node_modules/@pollyjs/adapter/dist/cjs/pollyjs-adapter.js:1219:34) +/home/trivir/Work/frodo-rebase/tmp/frodo-lib/mocks/theme_2834462706/delete_1740784714/0_theme-name_1325589195/am_1076162899/recording.har: Unexpected end of JSON input +Unrecognized combination of options or no options... +" +`; + +exports[`frodo theme delete "frodo theme delete -a": should delete all themes 1`] = `""`; + +exports[`frodo theme delete "frodo theme delete -i 2c23505e-e10c-4f09-be73-13307f615298": should delete the theme with id '2c23505e-e10c-4f09-be73-13307f615298' 1`] = `""`; + +exports[`frodo theme delete "frodo theme delete -n 'Starter Theme'": should delete the theme named 'Starter Theme' 1`] = `""`; diff --git a/test/e2e/theme-delete.e2e.test.js b/test/e2e/theme-delete.e2e.test.js new file mode 100644 index 000000000..11062fdfc --- /dev/null +++ b/test/e2e/theme-delete.e2e.test.js @@ -0,0 +1,107 @@ +/** + * Follow this process to write e2e tests for the CLI project: + * + * 1. Test if all the necessary mocks for your tests already exist. + * In mock mode, run the command you want to test with the same arguments + * and parameters exactly as you want to test it, for example: + * + * $ FRODO_MOCK=1 frodo conn save https://openam-frodo-dev.forgeblocks.com/am volker.scheuber@forgerock.com Sup3rS3cr3t! + * + * If your command completes without errors and with the expected results, + * all the required mocks already exist and you are good to write your + * test and skip to step #4. + * + * If, however, your command fails and you see errors like the one below, + * you know you need to record the mock responses first: + * + * [Polly] [adapter:node-http] Recording for the following request is not found and `recordIfMissing` is `false`. + * + * 2. Record mock responses for your exact command. + * In mock record mode, run the command you want to test with the same arguments + * and parameters exactly as you want to test it, for example: + * + * $ FRODO_MOCK=record frodo conn save https://openam-frodo-dev.forgeblocks.com/am volker.scheuber@forgerock.com Sup3rS3cr3t! + * + * Wait until you see all the Polly instances (mock recording adapters) have + * shutdown before you try to run step #1 again. + * Messages like these indicate mock recording adapters shutting down: + * + * Polly instance 'conn/4' stopping in 3s... + * Polly instance 'conn/4' stopping in 2s... + * Polly instance 'conn/save/3' stopping in 3s... + * Polly instance 'conn/4' stopping in 1s... + * Polly instance 'conn/save/3' stopping in 2s... + * Polly instance 'conn/4' stopped. + * Polly instance 'conn/save/3' stopping in 1s... + * Polly instance 'conn/save/3' stopped. + * + * 3. Validate your freshly recorded mock responses are complete and working. + * Re-run the exact command you want to test in mock mode (see step #1). + * + * 4. Write your test. + * Make sure to use the exact command including number of arguments and params. + * + * 5. Commit both your test and your new recordings to the repository. + * Your tests are likely going to reside outside the frodo-lib project but + * the recordings must be committed to the frodo-lib project. + */ + +/* +FRODO_MOCK=record FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo theme delete -n 'Starter Theme' +FRODO_MOCK=record FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo theme delete -i 2c23505e-e10c-4f09-be73-13307f615298 +FRODO_MOCK=record FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo theme delete -a +*/ +import cp from 'child_process'; +import { promisify } from 'util'; +import { removeAnsiEscapeCodes } from './utils/TestUtils'; +import { connection as c } from './utils/TestConfig'; + +const exec = promisify(cp.exec); + +process.env['FRODO_MOCK'] = '1'; +const env = { + env: process.env, +}; +env.env.FRODO_HOST = c.host; +env.env.FRODO_SA_ID = c.saId; +env.env.FRODO_SA_JWK = c.saJwk; + +describe('frodo theme delete', () => { + + test('"frodo theme delete -n \'Starter Theme\'": should delete the theme named \'Starter Theme\'', async () => { + const CMD = `frodo theme delete -n 'Starter Theme'`; + const { stdout } = await exec(CMD, env); + expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot(); + }); + + test('"frodo theme delete --theme-name \'Starter Theme\'": should display error when the theme named \'Starter Theme\' cannot be deleted since it does not exist', async () => { + const CMD = `frodo theme delete --theme-name 'Starter Theme'`; + const { stderr } = await exec(CMD, env); + expect(removeAnsiEscapeCodes(stderr)).toMatchSnapshot(); + }); + + test('"frodo theme delete -i 2c23505e-e10c-4f09-be73-13307f615298": should delete the theme with id \'2c23505e-e10c-4f09-be73-13307f615298\'', async () => { + const CMD = `frodo theme delete -i 2c23505e-e10c-4f09-be73-13307f615298`; + const { stdout } = await exec(CMD, env); + expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot(); + }); + + test('"frodo theme delete --theme-id 2c23505e-e10c-4f09-be73-13307f615298": should display error when the theme with id \'2c23505e-e10c-4f09-be73-13307f615298\' cannot be deleted since it does not exist', async () => { + const CMD = `frodo theme delete --theme-id 2c23505e-e10c-4f09-be73-13307f615298`; + const { stderr } = await exec(CMD, env); + expect(removeAnsiEscapeCodes(stderr)).toMatchSnapshot(); + }); + + test('"frodo theme delete -a": should delete all themes', async () => { + const CMD = `frodo theme delete -a`; + const { stdout } = await exec(CMD, env); + expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot(); + }); + + test('"frodo theme delete --all": should display error when no themes can be deleted', async () => { + const CMD = `frodo theme delete --all`; + const { stderr } = await exec(CMD, env); + expect(removeAnsiEscapeCodes(stderr)).toMatchSnapshot(); + }); + +});