Skip to content

Commit

Permalink
build: Add unit tests for bookmark-get command
Browse files Browse the repository at this point in the history
First unit tests for this command
  • Loading branch information
Göran Sander committed Dec 21, 2023
1 parent c187f2d commit 4085282
Show file tree
Hide file tree
Showing 4 changed files with 478 additions and 83 deletions.
157 changes: 79 additions & 78 deletions .vscode/launch.json
Expand Up @@ -809,38 +809,40 @@
// ------------------------------------
// Get all bookmarks
// ------------------------------------
// "args": [
// "bookmark-get",
// "--host",
// "192.168.100.109",

// "--port",
// // "4747",
// "443",

// "--virtual-proxy",
// "jwt",
// "--auth-type",
// "jwt",
// "--auth-jwt",
// "<jwt>",

// "--app-id",
// "2933711d-6638-41d4-a2d2-6dd2d965208b",

// "--auth-user-dir",
// "LAB",
// "--auth-user-id",
// "goran",

// "--id-type",
// "id",
// // "--bookmark",
// // "Bookmark 1",
// // "Bookmark 3",
// "--output-format",
// "table"
// ]
"args": [
"bookmark-get",
"--host",
"192.168.100.109",

"--port",
"4747",
// "443",

// "--virtual-proxy",
// "jwt",
// "--auth-type",
// "jwt",
// "--auth-jwt",
// "<jwt>",

"--app-id",
// "2933711d-6638-41d4-a2d2-6dd2d965208b",
// "449f2186-0e86-4e19-b46f-c4c23212d730", // No bookmarks app
"e5d051f0-34c6-4f47-9bc8-7dfabf784f18", // Has 2 bookmarks

"--auth-user-dir",
"LAB",
"--auth-user-id",
"goran",

"--id-type",
"id",
// "--bookmark",
// "Bookmark 1",
// "Bookmark 3",
"--output-format",
"table"
]

// ------------------------------------
// Get measure by id
Expand Down Expand Up @@ -1003,16 +1005,15 @@
// "connection-test",
// "--host",
// "192.168.100.109",
// // "--port",
// // "443",
// "--port",
// "443",

// // "--virtual-proxy",
// // "/jwt",
// // "/jwt",
// "--virtual-proxy",
// "/jwt",

// // "--auth-type",
// // "jwt",
// // "cert",
// "--auth-type",
// "jwt",
// // "cert",
// // "--host",
// // "192.168.100.109",
// // "--auth-cert-file",
Expand All @@ -1032,45 +1033,45 @@
// ]

// ------------------------------------
// Connection test
// Network chart visualization
// ------------------------------------
"args": [
"task-vis",
"--host",
"192.168.100.109",
// "--port",
// "443",

"--vis-host",
"192.168.100.143",
"--vis-port",
"3000",

// "--virtual-proxy",
// "/jwt",

"--auth-type",
// "jwt",
"cert",
// "--host",
// "192.168.100.109",
"--auth-cert-file",
"../../code/secret/pro2win1-nopwd/client.pem",
"--auth-cert-key-file",
"../../code/secret/pro2win1-nopwd/client_key.pem",
// "./cert/client.pem",
// "./cert/client_key.pem",
// "--auth-jwt",
// "....",

"--auth-user-dir",
"LAB",
"--auth-user-id",
"goran",

"--log-level",
"verbose"
]
// "args": [
// "task-vis",
// "--host",
// "192.168.100.109",
// // "--port",
// // "443",

// "--vis-host",
// "192.168.100.143",
// "--vis-port",
// "3000",

// // "--virtual-proxy",
// // "/jwt",

// "--auth-type",
// // "jwt",
// "cert",
// // "--host",
// // "192.168.100.109",
// "--auth-cert-file",
// "../../code/secret/pro2win1-nopwd/client.pem",
// "--auth-cert-key-file",
// "../../code/secret/pro2win1-nopwd/client_key.pem",
// // "./cert/client.pem",
// // "./cert/client_key.pem",
// // "--auth-jwt",
// // "....",

// "--auth-user-dir",
// "LAB",
// "--auth-user-id",
// "goran",

// "--log-level",
// "verbose"
// ]
}
]
}
200 changes: 200 additions & 0 deletions src/__tests__/bookmark_get_cert.test.js
@@ -0,0 +1,200 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');

const { getBookmark } = require('../lib/cmd/getbookmark');

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
authType: process.env.CTRL_Q_AUTH_TYPE || 'cert',
authCertFile: process.env.CTRL_Q_AUTH_CERT_FILE || './cert/client.pem',
authCertKeyFile: process.env.CTRL_Q_AUTH_CERT_KEY_FILE || './cert/client_key.pem',
host: process.env.CTRL_Q_HOST || '',
port: process.env.CTRL_Q_PORT || '4747',
schemaVersion: process.env.CTRL_Q_SCHEMA_VERSION || '12.612.0',
virtualProxy: process.env.CTRL_Q_VIRTUAL_PROXY || '',
secure: process.env.CTRL_Q_SECURE || true,
authUserDir: process.env.CTRL_Q_AUTH_USER_DIR || '',
authUserId: process.env.CTRL_Q_AUTH_USER_ID || '',

idType: process.env.CTRL_Q_ID_TYPE || 'name',
outputFormat: process.env.CTRL_Q_OUTPUT_FORMAT || 'json',
};

const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 600000; // 10 minute default timeout
jest.setTimeout(defaultTestTimeout);

const appIdNoExists = '449f2186-0e86-4e19-b46f-c4c23212d731';
const appIdExistsNoBookmarks1 = '449f2186-0e86-4e19-b46f-c4c23212d730';
const appIdExistsHasBookmarks1 = 'e5d051f0-34c6-4f47-9bc8-7dfabf784f18';
const appIdExistsHasBookmarks1Bookmark1 = '5ec99a44-3ffd-4a35-8fb9-6c0899cf07ea';
const appIdExistsHasBookmarks1Bookmark2 = 'c49210ea-3005-4f2c-8697-52fe541b51d8';

test('get bookmark (verify parameters)', async () => {
expect(options.authCertFile).not.toHaveLength(0);
expect(options.authCertKeyFile).not.toHaveLength(0);
expect(options.host).not.toHaveLength(0);
expect(options.authUserDir).not.toHaveLength(0);
expect(options.authUserId).not.toHaveLength(0);
expect(options.idType).not.toHaveLength(0);
expect(options.outputFormat).not.toHaveLength(0);
});

// Test suite for app export
describe('get in-app bookmarks (cert auth)', () => {
/**
* All bookmarks in app that doesn't exist, JSON output
*
* --app-id <id>
* --id-type id
* --output-format json
*/
test('get all bookmarks from app that does not exist', async () => {
options.appId = appIdNoExists;
options.idType = 'id';
options.outputFormat = 'json';

const result = await getBookmark(options);

// Result should be false
expect(result).toBe(false);
});

/**
* All bookmarks in app, JSON output
* No bookmarks exist in app that exist
*
* --app-id <id>
* --id-type id
* --output-format json
*/
test('get all bookmarks from app that has no bookmarks in it', async () => {
options.appId = appIdExistsNoBookmarks1;
options.idType = 'id';
options.outputFormat = 'json';

const result = await getBookmark(options);

// Result should be empty array
expect(result).toStrictEqual([]);
});

/**
* All bookmarks in app, JSON output
* App has 2 bookmarks
*
* --app-id <id>
* --id-type id
* --output-format json
*/
test('get all bookmarks from app that has bookmarks in it', async () => {
options.appId = appIdExistsHasBookmarks1;
options.idType = 'id';
options.outputFormat = 'json';

const result = await getBookmark(options);

// Result should be array with 2 bookmarks
expect(result.length).toBe(2);

// Verify that the bookmarks have the correct IDs
expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1);
expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2);
});

/**
* All bookmarks in app, table output
* App has 2 bookmarks
*
* --app-id <id>
* --id-type id
* --output-format json
*/
test('get all bookmarks from app that has bookmarks in it', async () => {
options.appId = appIdExistsHasBookmarks1;
options.idType = 'id';
options.outputFormat = 'table';

const result = await getBookmark(options);

// Result should be array with 2 bookmarks
expect(result.length).toBe(2);

// Verify that the bookmarks have the correct IDs
expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1);
expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2);
});

/**
* Get 1 specific bookmark (based on ID) from app, JSON output
* App has 2 bookmarks
*
* --app-id <id>
* --id-type id
* --output-format json
* --bookmark [<id>]
*/
test('get 1 specific bookmark from app that has bookmarks in it', async () => {
options.appId = appIdExistsHasBookmarks1;
options.idType = 'id';
options.outputFormat = 'json';
options.bookmark = [appIdExistsHasBookmarks1Bookmark1];

const result = await getBookmark(options);

// Result should be array with 1 bookmark
expect(result.length).toBe(1);

// Verify that the bookmarks have the correct IDs
expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1);
});

/**
* Get 2 specific bookmarks (based on ID) from app, JSON output
* App has 2 bookmarks
*
* --app-id <id>
* --id-type id
* --output-format json
* --bookmark [<id>, <id>]
*/
test('get 2 specific bookmarks from app that has bookmarks in it', async () => {
options.appId = appIdExistsHasBookmarks1;
options.idType = 'id';
options.outputFormat = 'json';
options.bookmark = [appIdExistsHasBookmarks1Bookmark1, appIdExistsHasBookmarks1Bookmark2];

const result = await getBookmark(options);

// Result should be array with 2 bookmarks
expect(result.length).toBe(2);

// Verify that the bookmarks have the correct IDs
expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1);
expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2);
});

/**
* Get 2 specific bookmarks (based on name) from app, JSON output
* App has 2 bookmarks
*
* --app-id <id>
* --id-type name
* --output-format json
* --bookmark [<name>, <name>]
*/
test('get 2 specific bookmarks from app that has bookmarks in it', async () => {
options.appId = appIdExistsHasBookmarks1;
options.idType = 'name';
options.outputFormat = 'json';
options.bookmark = ['Bookmark 1', 'Bookmark 2'];

const result = await getBookmark(options);

// Result should be array with 2 bookmark
expect(result.length).toBe(2);

// Verify that the bookmarks have the correct IDs
expect(result[0].qMeta.title).toBe('Bookmark 1');
expect(result[1].qMeta.title).toBe('Bookmark 2');
});
});

0 comments on commit 4085282

Please sign in to comment.