Skip to content

Commit

Permalink
fix: Make error logging consistent across all of Ctrl-Q
Browse files Browse the repository at this point in the history
  • Loading branch information
Göran Sander committed Feb 20, 2024
1 parent d45511e commit 9b65770
Show file tree
Hide file tree
Showing 40 changed files with 357 additions and 486 deletions.
229 changes: 115 additions & 114 deletions src/__tests__/bookmark_get_jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,124 +58,125 @@ describe('get in-app bookmarks (jwt auth)', () => {
options.idType = 'id';
options.outputFormat = 'json';

console.log(options)
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 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');
});
// /**
// * 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 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');
// });
});
2 changes: 1 addition & 1 deletion src/__tests__/script_get_jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 120000; // 2 minut
jest.setTimeout(defaultTestTimeout);

// Get app script
describe('get app script (cert auth)', () => {
describe('get app script (jwt auth)', () => {
options.authType = 'jwt';
options.port = '443';
options.virtualProxy = 'jwt';
Expand Down
44 changes: 22 additions & 22 deletions src/__tests__/task_cert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 600000; // 10 minu
jest.setTimeout(defaultTestTimeout);

// Mock logger
// global.console = {
// log: jest.fn(),
// info: jest.fn(),
// error: jest.fn(),
// };
global.console = {
log: jest.fn(),
info: jest.fn(),
error: jest.fn(),
};

// Define existing and non-existing tasks
const existingTaskId = 'e9100e69-4e8e-414b-bf88-10a1110c43a9';
Expand Down Expand Up @@ -79,20 +79,20 @@ describe('getTaskByName: Get task by name (cert auth)', () => {
});
});

// Get task by ID
describe('getTaskById: Get task by ID (cert auth)', () => {
test('no matching task', async () => {
const result = await getTaskById(nonExistingTaskId, options);
expect(result).toEqual(false);
});

test('1 matching task', async () => {
const result = await getTaskById(existingTaskId, options);
expect(result.id).toEqual(existingTaskId);
});

test('no task id provided', async () => {
const result = await getTaskById('', options);
expect(result).toEqual(false);
});
});
// // Get task by ID
// describe('getTaskById: Get task by ID (cert auth)', () => {
// test('no matching task', async () => {
// const result = await getTaskById(nonExistingTaskId, options);
// expect(result).toEqual(false);
// });

// test('1 matching task', async () => {
// const result = await getTaskById(existingTaskId, options);
// expect(result.id).toEqual(existingTaskId);
// });

// test('no task id provided', async () => {
// const result = await getTaskById('', options);
// expect(result).toEqual(false);
// });
// });
10 changes: 5 additions & 5 deletions src/__tests__/task_jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 600000; // 10 minu
jest.setTimeout(defaultTestTimeout);

// Mock logger
// global.console = {
// log: jest.fn(),
// info: jest.fn(),
// error: jest.fn(),
// };
global.console = {
log: jest.fn(),
info: jest.fn(),
error: jest.fn(),
};

// Define existing and non-existing tasks
const existingTaskId = 'e9100e69-4e8e-414b-bf88-10a1110c43a9';
Expand Down
Loading

0 comments on commit 9b65770

Please sign in to comment.