Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

535 #584

Merged
merged 7 commits into from
Dec 15, 2024
Merged

535 #584

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,5 @@ certificate.p12
.vscode/launch.json
ctrl-q.exe
.vscode/launch.json
.test.env
.vscode/launch.json
20 changes: 15 additions & 5 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const dotenv = require('dotenv');
dotenv.config({ path: './.test.env' });

/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
Expand All @@ -18,19 +21,18 @@ const config = {
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: true,
collectCoverage: false,
collectCoverage: true,
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
// collectCoverageFrom: ['./src/**/*.{js,jsx}'],

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
coveragePathIgnorePatterns: ['/node_modules/', '/build/', '/dist/'],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',
Expand All @@ -45,6 +47,14 @@ const config = {

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
// coverageThreshold: {
// global: {
// branches: 90,
// functions: 90,
// lines: 90,
// statements: 90,
// },
// },

// A path to a custom dependency extractor
// dependencyExtractor: undefined,
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@babel/plugin-syntax-import-assertions": "^7.26.0",
"@eslint/js": "^9.15.0",
"@jest/globals": "^29.7.0",
"dotenv": "^16.4.7",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
Expand Down
65 changes: 65 additions & 0 deletions src/__tests__/cmd/qscloud/connection_test_cloud.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { jest, test, expect, describe } from '@jest/globals';
import { qscloudTestConnection } from '../../../lib/cmd/qscloud/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
tenantHost: process.env.CTRLQ_TENANT_HOST || '',
authType: process.env.CTRLQ_AUTH_TYPE || 'apikey',
apikey: process.env.CTRLQ_API_KEY || '',
};

const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 120000; // 2 minute default timeout
console.log(`Jest timeout: ${defaultTestTimeout}`);
jest.setTimeout(defaultTestTimeout);

// Connection test using JWT auth
describe('connection test (JWT auth)', () => {
test('Verify parameters', async () => {
expect(options.logLevel).not.toHaveLength(0);
expect(options.tenantHost).not.toHaveLength(0);
expect(options.authType).toBe('apikey');
expect(options.apikey).not.toHaveLength(0);

// Check if the API key is a valid JWT
try {
const decoded = JSON.parse(Buffer.from(options.apikey.split('.')[1], 'base64').toString('utf8'));
expect(decoded).toBeInstanceOf(Object);

expect(decoded.aud).toBe('qlik.api');
expect(decoded.iss).toBe('qlik.api/api-keys');

// JTI should be a UUID
expect(decoded.jti).not.toHaveLength(0);
expect(decoded.jti).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);

expect(decoded.sub).not.toHaveLength(0);
expect(decoded.subType).toBe('user');

expect(decoded.tenantId).not.toHaveLength(0);
} catch (error) {
expect(error).toBeInstanceOf(Error);
expect(error.message).toBe('Invalid API key');
}
});

/**
* Do connection test
* Should succeed
*/
test('do connection test', async () => {
const result = await qscloudTestConnection(options);

const decoded = JSON.parse(Buffer.from(options.apikey.split('.')[1], 'base64').toString('utf8'));

// Result should be a JSON object
expect(result).toBeInstanceOf(Object);
expect(result.tenantId).toBe(decoded.tenantId);

expect(result.id).not.toHaveLength(0);
expect(result.id).toBe(decoded.sub);

expect(result.name).not.toHaveLength(0);
expect(result.email).not.toHaveLength(0);
expect(result.status).not.toHaveLength(0);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { createUserActivityBucketsCustomProperty } from '../lib/cmd/qseow/createuseractivitycp.js';
import { createUserActivityBucketsCustomProperty } from '../../../lib/cmd/qseow/createuseractivitycp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { getApps, getAppById } from '../lib/util/qseow/app.js';
import { getApps, getAppById } from '../../../lib/util/qseow/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import { exportAppToFile } from '../lib/cmd/qseow/exportapp.js';
import { exportAppToFile } from '../../../lib/cmd/qseow/exportapp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import { exportAppToFile } from '../lib/cmd/qseow/exportapp.js';
import { exportAppToFile } from '../../../lib/cmd/qseow/exportapp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../lib/util/qseow/app.js';
import { importAppFromFile } from '../../../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../../../lib/util/qseow/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../lib/util/qseow/app.js';
import { importAppFromFile } from '../../../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../../../lib/util/qseow/app.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { getApps, getAppById, appExistById, deleteAppById } from '../lib/util/qseow/app.js';
import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { sleep } from '../globals.js';
import { getApps, getAppById, appExistById, deleteAppById } from '../../../lib/util/qseow/app.js';
import { importAppFromFile } from '../../../lib/cmd/qseow/importapp.js';
import { sleep } from '../../../globals.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jest, test, expect, describe } from '@jest/globals';
import { validate as uuidValidate } from 'uuid';

import { scrambleField } from '../lib/cmd/qseow/scramblefield.js';
import { scrambleField } from '../../../lib/cmd/qseow/scramblefield.js';

let options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import { getBookmark } from '../lib/cmd/qseow/getbookmark.js';
import { getBookmark } from '../../../lib/cmd/qseow/getbookmark.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { getBookmark } from '../lib/cmd/qseow/getbookmark.js';
import { getBookmark } from '../../../lib/cmd/qseow/getbookmark.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { testConnection } from '../lib/cmd/qseow/testconnection.js';
import { testConnection } from '../../../lib/cmd/qseow/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { testConnection } from '../lib/cmd/qseow/testconnection.js';
import { testConnection } from '../../../lib/cmd/qseow/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { getScript } from '../lib/cmd/qseow/getscript.js';
import { getScript } from '../../../lib/cmd/qseow/getscript.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { getScript } from '../lib/cmd/qseow/getscript.js';
import { getScript } from '../../../lib/cmd/qseow/getscript.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { taskExistById, getTaskByName, getTaskById } from '../lib/util/qseow/task.js';
import { taskExistById, getTaskByName, getTaskById } from '../../../lib/util/qseow/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jest, test, expect, describe } from '@jest/globals';

import { setTaskCustomProperty } from '../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../lib/util/qseow/task.js';
import { setTaskCustomProperty } from '../../../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../../../lib/util/qseow/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jest, test, expect, describe } from '@jest/globals';

import { setTaskCustomProperty } from '../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../lib/util/qseow/task.js';
import { setTaskCustomProperty } from '../../../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../../../lib/util/qseow/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import { getTask } from '../lib/cmd/qseow/gettask.js';
import { getTask } from '../../../lib/cmd/qseow/gettask.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import { getTask } from '../lib/cmd/qseow/gettask.js';
import { getTask } from '../../../lib/cmd/qseow/gettask.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { jest, test, expect, describe } from '@jest/globals';

import { importTaskFromFile } from '../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../lib/util/qseow/task.js';
import { mapTaskType } from '../lib/util/qseow/lookups.js';
import { importTaskFromFile } from '../../../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../../../lib/util/qseow/task.js';
import { mapTaskType } from '../../../lib/util/qseow/lookups.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { jest, test, expect, describe } from '@jest/globals';

import { importTaskFromFile } from '../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../lib/util/qseow/task.js';
import { mapTaskType } from '../lib/util/qseow/lookups.js';
import { importTaskFromFile } from '../../../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../../../lib/util/qseow/task.js';
import { mapTaskType } from '../../../lib/util/qseow/lookups.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import { taskExistById, getTaskByName, getTaskById } from '../lib/util/qseow/task.js';
import { taskExistById, getTaskByName, getTaskById } from '../../../lib/util/qseow/task.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/testdata/test-file-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, world!
1 change: 1 addition & 0 deletions src/__tests__/testdata/unreadable-file-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
Loading
Loading