Skip to content

Commit

Permalink
build: Add unit tests for script-get command
Browse files Browse the repository at this point in the history
 ...
  • Loading branch information
Göran Sander committed Nov 22, 2023
1 parent 3556a55 commit 855b714
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ console.log(`Jest timeout: ${defaultTestTimeout}`);
jest.setTimeout(defaultTestTimeout);

// Get app script
describe('get app script', () => {
test('Verify parameters (should succeed)', async () => {
describe('get app script (cert auth)', () => {
test('Verify parameters', async () => {
expect(options.authCertFile).not.toHaveLength(0);
expect(options.authCertKeyFile).not.toHaveLength(0);
expect(options.host).not.toHaveLength(0);
Expand All @@ -36,7 +36,7 @@ describe('get app script', () => {
* Get app script
* Should succeed
*/
test('get app script (should succeed)', async () => {
test('get app script', async () => {
const result = await getScript(options);

expect(result.appId).toBe('a3e0f5d2-000a-464f-998d-33d333b175d7');
Expand Down
47 changes: 47 additions & 0 deletions src/__tests__/script_get_jwt.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');

const { getScript } = require('../lib/cmd/getscript');

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
authType: process.env.CTRL_Q_AUTH_TYPE || 'cert',
host: process.env.CTRL_Q_HOST || '',
port: process.env.CTRL_Q_PORT || '4747',
virtualProxy: process.env.CTRL_Q_VIRTUAL_PROXY || '',
secure: process.env.CTRL_Q_SECURE || true,
schemaVersion: process.env.CTRL_Q_SCHEMA_VERSION || '12.612.0',
appId: process.env.CTRL_Q_APP_ID || 'a3e0f5d2-000a-464f-998d-33d333b175d7',
authUserDir: process.env.CTRL_Q_AUTH_USER_DIR || '',
authUserId: process.env.CTRL_Q_AUTH_USER_ID || '',
authJwt: process.env.CTRL_Q_AUTH_JWT || '',
};

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

// Get app script
describe('get app script (cert auth)', () => {
options.authType = 'jwt';
options.port = '443';
options.virtualProxy = 'jwt';

test('Verify parameters', async () => {
expect(options.host).not.toHaveLength(0);
expect(options.authUserDir).not.toHaveLength(0);
expect(options.authUserId).not.toHaveLength(0);
});

/**
* Get app script
* Should succeed
*/
test('get app script', async () => {
const result = await getScript(options);

expect(result.appId).toBe('a3e0f5d2-000a-464f-998d-33d333b175d7');
expect(result.appCreatedDate).toBe('2021-06-03T22:04:52.283Z');
expect(result.appModifiedDate).toBe('2023-05-05T06:17:05.456Z');
expect(result.appScript.length).toBe(1989);
});
});

0 comments on commit 855b714

Please sign in to comment.