From 855b714022ca56027f704f3007f3f3b3e5e5d86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Wed, 22 Nov 2023 13:17:04 +0000 Subject: [PATCH] build: Add unit tests for script-get command ... --- ...pt_get.test.js => script_get_cert.test.js} | 6 +-- src/__tests__/script_get_jwt.test.js | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) rename src/__tests__/{script_get.test.js => script_get_cert.test.js} (92%) create mode 100644 src/__tests__/script_get_jwt.test.js diff --git a/src/__tests__/script_get.test.js b/src/__tests__/script_get_cert.test.js similarity index 92% rename from src/__tests__/script_get.test.js rename to src/__tests__/script_get_cert.test.js index 3d9ad50..84e33a9 100644 --- a/src/__tests__/script_get.test.js +++ b/src/__tests__/script_get_cert.test.js @@ -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); @@ -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'); diff --git a/src/__tests__/script_get_jwt.test.js b/src/__tests__/script_get_jwt.test.js new file mode 100644 index 0000000..307afab --- /dev/null +++ b/src/__tests__/script_get_jwt.test.js @@ -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); + }); +});