Skip to content

Commit

Permalink
Merge pull request #293 from trivir/feature/theme-delete-tests
Browse files Browse the repository at this point in the history
Add theme delete tests
  • Loading branch information
vscheuber authored Oct 7, 2023
2 parents dc88ceb + 61900cc commit f964cf2
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 181 deletions.
181 changes: 0 additions & 181 deletions src/cli/theme/theme-delete.e2e.test_.ts

This file was deleted.

61 changes: 61 additions & 0 deletions test/e2e/__snapshots__/theme-delete.e2e.test.js.snap
Original file line number Diff line number Diff line change
@@ -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 (<anonymous>)
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.<anonymous> (/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 (<anonymous>)
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.<anonymous> (/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 (<anonymous>)
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.<anonymous> (/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`] = `""`;
107 changes: 107 additions & 0 deletions test/e2e/theme-delete.e2e.test.js
Original file line number Diff line number Diff line change
@@ -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();
});

});

0 comments on commit f964cf2

Please sign in to comment.