Skip to content

Commit

Permalink
Merge pull request #294 from trivir/feature/service-list-tests
Browse files Browse the repository at this point in the history
Fix service list and add service list tests
  • Loading branch information
vscheuber authored Oct 7, 2023
2 parents f964cf2 + e4b25eb commit 82c6b56
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ops/ServiceOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export async function listServices(long = false, globalConfig = false) {
if (long) {
const table = createTable(['Service Id', 'Service Name']);
for (const service of services) {
table.push([service._id, service.name]);
table.push([
service._id,
globalConfig ? service['_type'].name : service.name,
]);
}
printMessage(table.toString(), 'data');
} else {
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/__snapshots__/service-list.e2e.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`frodo service list "frodo service list --long --global": should list the ids and names of the global services 1`] = `
"Service Id │Service Name
CorsService│CORS Service
dashboard │Dashboard
"
`;

exports[`frodo service list "frodo service list -g": should list the ids of the global services 1`] = `
"CorsService
dashboard
"
`;

exports[`frodo service list "frodo service list -l": should list the ids and names of the services 1`] = `
"Service Id │Service Name
baseurl │Base URL Source
DataStoreService │External Data Stores
oauth-oidc │OAuth2 Provider
policyconfiguration │Policy Configuration
selfServiceTrees │Self Service Trees
SocialIdentityProviders│Social Identity Provider Service
validation │Validation Service
"
`;

exports[`frodo service list "frodo service list": should list the ids of the services 1`] = `
"baseurl
DataStoreService
oauth-oidc
policyconfiguration
selfServiceTrees
SocialIdentityProviders
validation
"
`;
94 changes: 94 additions & 0 deletions test/e2e/service-list.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* 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 service list
FRODO_MOCK=record FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo service list -l
FRODO_MOCK=record FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo service list -g
FRODO_MOCK=record FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo service list --long --global
*/
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 service list', () => {
test('"frodo service list": should list the ids of the services', async () => {
const CMD = `frodo service list`;
const { stdout } = await exec(CMD, env);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});

test('"frodo service list -l": should list the ids and names of the services', async () => {
const CMD = `frodo service list -l`;
const { stdout } = await exec(CMD, env);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});

test('"frodo service list -g": should list the ids of the global services', async () => {
const CMD = `frodo service list -g`;
const { stdout } = await exec(CMD, env);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});

test('"frodo service list --long --global": should list the ids and names of the global services', async () => {
const CMD = `frodo service list --long --global`;
const { stdout } = await exec(CMD, env);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});
});

0 comments on commit 82c6b56

Please sign in to comment.