-
Notifications
You must be signed in to change notification settings - Fork 2
/
task_import_cert.test.js
199 lines (152 loc) · 6.63 KB
/
task_import_cert.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* eslint-disable no-await-in-loop */
/* eslint-disable no-console */
const { test, expect, describe } = require('@jest/globals');
const { importTaskFromFile } = require('../lib/cmd/importtask');
const { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } = require('../lib/util/task');
const { mapTaskType } = require('../lib/util/lookups');
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 || '4242',
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 || '',
updateMode: process.env.CTRL_Q_UPDATE_MODE || 'create',
};
const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 600000; // 10 minute default timeout
jest.setTimeout(defaultTestTimeout);
// Test suite for task import
describe('import task (cert auth)', () => {
test('get tasks (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);
});
test('csv 1: reload task, no triggers', async () => {
const inputDir = './testdata';
const inputFile = `tasks-1.csv`;
options.fileType = 'csv';
options.fileName = `${inputDir}/${inputFile}`;
const result = await importTaskFromFile(options);
// Result should be array with length 1
expect(result).not.toBe(false);
expect(result.length).toBe(1);
// Delete all tasks in array
for (let i = 0; i < result.length; i += 1) {
const task = result[i];
const { taskId } = task;
await deleteReloadTaskById(taskId, options);
}
});
test('csv 2: reload task, 1 schema trigger', async () => {
const inputDir = './testdata';
const inputFile = `tasks-2.csv`;
options.fileType = 'csv';
options.fileName = `${inputDir}/${inputFile}`;
const result = await importTaskFromFile(options);
// Result should be array with length 1
expect(result).not.toBe(false);
expect(result.length).toBe(1);
// Delete all tasks in array
for (let i = 0; i < result.length; i += 1) {
const task = result[i];
const { taskId } = task;
await deleteReloadTaskById(taskId, options);
}
});
test('csv 3: reload task, 1 composite trigger', async () => {
const inputDir = './testdata';
const inputFile = `tasks-3.csv`;
options.fileType = 'csv';
options.fileName = `${inputDir}/${inputFile}`;
const result = await importTaskFromFile(options);
// Result should be array with length 1
expect(result).not.toBe(false);
expect(result.length).toBe(1);
// Delete all tasks in array
for (let i = 0; i < result.length; i += 1) {
const task = result[i];
const { taskId } = task;
await deleteReloadTaskById(taskId, options);
}
});
test('csv 4: 2 reload tasks, composite & schema triggers', async () => {
const inputDir = './testdata';
const inputFile = `tasks-4.csv`;
options.fileType = 'csv';
options.fileName = `${inputDir}/${inputFile}`;
const result = await importTaskFromFile(options);
// Result should be array with length 2
expect(result).not.toBe(false);
expect(result.length).toBe(2);
// Delete all tasks in array
for (let i = 0; i < result.length; i += 1) {
const task = result[i];
const { taskId } = task;
await deleteReloadTaskById(taskId, options);
}
});
test('csv 5: 1 ext program task, schema trigger', async () => {
const inputDir = './testdata';
const inputFile = `tasks-5.csv`;
options.fileType = 'csv';
options.fileName = `${inputDir}/${inputFile}`;
const result = await importTaskFromFile(options);
// Result should be array with length 1
expect(result).not.toBe(false);
expect(result.length).toBe(1);
// Delete all tasks in array
for (let i = 0; i < result.length; i += 1) {
const task = result[i];
const { taskId } = task;
await deleteExternalProgramTaskById(taskId, options);
}
});
test('csv 6: 1 ext program task, composite trigger', async () => {
const inputDir = './testdata';
const inputFile = `tasks-6.csv`;
options.fileType = 'csv';
options.fileName = `${inputDir}/${inputFile}`;
const result = await importTaskFromFile(options);
// Result should be array with length 1
expect(result).not.toBe(false);
expect(result.length).toBe(1);
// Delete all tasks in array
for (let i = 0; i < result.length; i += 1) {
const task = result[i];
const { taskId } = task;
await deleteExternalProgramTaskById(taskId, options);
}
});
test('csv 7: complex. many schema and composite triggers', async () => {
const inputDir = './testdata';
const inputFile = `tasks-7.csv`;
options.fileType = 'csv';
options.fileName = `${inputDir}/${inputFile}`;
const result = await importTaskFromFile(options);
// Result should be array with length 1
expect(result).not.toBe(false);
expect(result.length).toBe(18);
// Delete all tasks in array
for (let i = 0; i < result.length; i += 1) {
const task = result[i];
const { taskId } = task;
// Call getTaskById to verify that task exists and what task type it is
const task2 = await getTaskById(taskId, options);
const taskType = mapTaskType.get(task2.taskType);
// taskType should be 'Reload' or 'External Program'
if (taskType === 'Reload') {
await deleteReloadTaskById(taskId, options);
} else if (taskType === 'ExternalProgram') {
await deleteExternalProgramTaskById(taskId, options);
}
}
});
});