-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtestCaseGenerate.test.ts
More file actions
954 lines (838 loc) · 37.5 KB
/
testCaseGenerate.test.ts
File metadata and controls
954 lines (838 loc) · 37.5 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
/*
* Copyright (c) 2024 Provar Limited.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.md file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* eslint-disable camelcase */
import { strict as assert } from 'node:assert';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { describe, it, beforeEach, afterEach } from 'mocha';
import { registerTestCaseGenerate } from '../../../src/mcp/tools/testCaseGenerate.js';
import type { ServerConfig } from '../../../src/mcp/server.js';
// ── Minimal McpServer mock ─────────────────────────────────────────────────────
// Note: bypasses Zod parsing — always pass explicit values for fields with defaults
// (steps, dry_run, overwrite).
type ToolHandler = (args: Record<string, unknown>) => unknown;
class MockMcpServer {
public registrations: Array<{ name: string; description: string }> = [];
private handlers = new Map<string, ToolHandler>();
public tool(name: string, _description: string, _schema: unknown, handler: ToolHandler): void {
this.handlers.set(name, handler);
}
public registerTool(name: string, config: unknown, handler: ToolHandler): void {
this.handlers.set(name, handler);
const desc = (config as Record<string, unknown>)['description'];
if (typeof desc === 'string') this.registrations.push({ name, description: desc });
}
public call(name: string, args: Record<string, unknown>): ReturnType<ToolHandler> {
const h = this.handlers.get(name);
if (!h) throw new Error(`Tool not registered: ${name}`);
return h(args);
}
}
// ── Helpers ────────────────────────────────────────────────────────────────────
function parseText(result: unknown): Record<string, unknown> {
const r = result as { content: Array<{ type: string; text: string }> };
return JSON.parse(r.content[0].text) as Record<string, unknown>;
}
function isError(result: unknown): boolean {
return (result as { isError?: boolean }).isError === true;
}
// UUID v4 pattern
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
// ── Test setup ─────────────────────────────────────────────────────────────────
let tmpDir: string;
let server: MockMcpServer;
let config: ServerConfig;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tcgen-test-'));
server = new MockMcpServer();
config = { allowedPaths: [tmpDir] };
registerTestCaseGenerate(server as never, config);
});
afterEach(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});
// ── tool description ──────────────────────────────────────────────────────────
describe('provar_testcase_generate description', () => {
it('references corpus tool and step-reference fallback', () => {
const reg = server.registrations.find((r) => r.name === 'provar_testcase_generate');
assert.ok(reg, 'tool should be registered');
assert.ok(
reg.description.includes('provar_qualityhub_examples_retrieve'),
'description should reference corpus tool'
);
assert.ok(
reg.description.includes('provar://docs/step-reference'),
'description should include step-reference fallback'
);
});
});
// ── provar_testcase_generate ───────────────────────────────────────────────────
describe('provar_testcase_generate', () => {
describe('dry_run', () => {
it('returns xml_content without writing to disk', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Login Test',
steps: [],
dry_run: true,
overwrite: false,
});
assert.equal(isError(result), false);
const body = parseText(result);
assert.ok(typeof body['xml_content'] === 'string' && body['xml_content'].length > 0);
assert.equal(body['written'], false);
assert.equal(body['dry_run'], true);
});
it('does NOT write a file even when output_path is provided', () => {
const outPath = path.join(tmpDir, 'LoginTest.testcase');
server.call('provar_testcase_generate', {
test_case_name: 'Login Test',
steps: [],
output_path: outPath,
dry_run: true,
overwrite: false,
});
assert.equal(fs.existsSync(outPath), false, 'file must not be written in dry_run mode');
});
});
describe('generated XML content', () => {
it('generates correct <testCase> element structure per Provar requirements', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Create Account',
steps: [],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('standalone="no"'), 'Expected standalone="no" in XML declaration');
assert.ok(xml.includes('<testCase'), 'Expected <testCase element');
assert.ok(xml.includes('id="1"'), 'Expected id="1" (Provar integer literal)');
assert.ok(!xml.includes('name="Create Account"'), 'testCase must NOT have a name attribute');
assert.ok(xml.includes('<summary/>'), 'Expected <summary/> as first child of testCase');
});
it('contains <steps> element', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'My Test',
steps: [],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('<steps>') && xml.includes('</steps>'), 'Expected <steps> block');
});
it('generates UUID v4 guids for testCase guid attribute', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'UUID Test',
steps: [],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
const guidMatch = /guid="([^"]+)"/.exec(xml);
assert.ok(guidMatch, 'Expected guid attribute');
assert.ok(UUID_RE.test(guidMatch[1]), `Expected UUID v4, got: ${guidMatch[1]}`);
});
it('always emits id="1" regardless of test_case_name (Provar integer literal requirement)', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Explicit ID Test',
steps: [],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('id="1"'), 'Expected id="1" literal in testCase element');
// Ensure the testCase id attr specifically is "1", not a UUID.
// Use word-boundary regex to avoid matching registryId="<uuid>" or guid="<uuid>".
assert.ok(!xml.match(/\btestCase\b[^>]*?\bid="[0-9a-f]{8}-/), 'testCase id must not be a UUID');
});
it('includes steps with correct apiId and sequential testItemId', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Multi Step',
steps: [
{ api_id: 'UiConnect', name: 'Connect', attributes: {} },
{ api_id: 'UiNavigate', name: 'Navigate', attributes: {} },
{ api_id: 'UiDoAction', name: 'Click', attributes: {} },
],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('apiId="com.provar.plugins.forcedotcom.core.ui.UiConnect"'));
assert.ok(xml.includes('apiId="com.provar.plugins.forcedotcom.core.ui.UiNavigate"'));
assert.ok(xml.includes('apiId="com.provar.plugins.forcedotcom.core.ui.UiDoAction"'));
assert.ok(xml.includes('testItemId="1"'), 'Expected first step testItemId=1');
assert.ok(xml.includes('testItemId="2"'), 'Expected second step testItemId=2');
assert.ok(xml.includes('testItemId="3"'), 'Expected third step testItemId=3');
});
it('reports step_count matching the number of steps', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Count Test',
steps: [
{ api_id: 'UiConnect', name: 'Step 1', attributes: {} },
{ api_id: 'UiNavigate', name: 'Step 2', attributes: {} },
],
dry_run: true,
overwrite: false,
});
assert.equal(parseText(result)['step_count'], 2);
});
it('includes validation field with is_valid and scores', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Validated Test',
steps: [{ api_id: 'UiConnect', name: 'Connect', attributes: {} }],
dry_run: true,
overwrite: false,
});
const body = parseText(result);
const validation = body['validation'] as Record<string, unknown>;
assert.ok(validation, 'Expected validation field in response');
assert.equal(typeof validation['is_valid'], 'boolean');
assert.equal(typeof validation['validity_score'], 'number');
assert.equal(typeof validation['quality_score'], 'number');
assert.equal(validation['is_valid'], true, 'Well-formed generated XML should be valid');
assert.ok(
!('best_practices_violations' in validation),
'best_practices_violations should be omitted from slim response'
);
});
it('emits a TODO comment when no steps are provided', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'No Steps',
steps: [],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('TODO'), 'Expected TODO placeholder for empty steps');
});
it('does not embed test_case_name in XML (name attr removed per Provar spec)', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Test & "Escape" <this>',
steps: [],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
// Provar derives test name from the file name — the name attr is not written to testCase
assert.ok(!xml.includes('name="Test'), 'testCase must NOT have a name attribute');
assert.ok(!xml.includes('Test &'), 'escaped name must not appear in XML');
});
it('escapes XML special characters in step api_id and name', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Escape Step Test',
steps: [{ api_id: 'Api<Id>', name: 'Step & "Name"', attributes: {} }],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('<') && xml.includes('>'), 'Expected < > escaped in apiId');
assert.ok(xml.includes('&'), 'Expected & escaped in step name');
});
});
describe('writing to disk', () => {
it('writes file when dry_run=false and output_path provided', () => {
const outPath = path.join(tmpDir, 'Login.testcase');
const result = server.call('provar_testcase_generate', {
test_case_name: 'Login',
steps: [],
output_path: outPath,
dry_run: false,
overwrite: false,
});
assert.equal(isError(result), false);
assert.equal(fs.existsSync(outPath), true, 'file should be written');
assert.equal(parseText(result)['written'], true);
});
it('does NOT write when dry_run=false but no output_path', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'No Path Test',
steps: [],
dry_run: false,
overwrite: false,
});
assert.equal(isError(result), false);
assert.equal(parseText(result)['written'], false);
});
it('returns FILE_EXISTS when file exists and overwrite=false', () => {
const outPath = path.join(tmpDir, 'Existing.testcase');
fs.writeFileSync(outPath, '<old/>', 'utf-8');
const result = server.call('provar_testcase_generate', {
test_case_name: 'Existing',
steps: [],
output_path: outPath,
dry_run: false,
overwrite: false,
});
assert.equal(isError(result), true);
assert.equal(parseText(result)['error_code'], 'FILE_EXISTS');
});
it('overwrites when overwrite=true and file exists', () => {
const outPath = path.join(tmpDir, 'Existing.testcase');
fs.writeFileSync(outPath, '<old/>', 'utf-8');
const result = server.call('provar_testcase_generate', {
test_case_name: 'Existing',
steps: [],
output_path: outPath,
dry_run: false,
overwrite: true,
});
assert.equal(isError(result), false);
const written = fs.readFileSync(outPath, 'utf-8');
assert.ok(written.includes('<testCase'), 'old content should be replaced');
});
it('creates parent directories as needed', () => {
const outPath = path.join(tmpDir, 'tests', 'suite', 'Login.testcase');
server.call('provar_testcase_generate', {
test_case_name: 'Login',
steps: [],
output_path: outPath,
dry_run: false,
overwrite: false,
});
assert.equal(fs.existsSync(outPath), true, 'nested directories should be created');
});
});
describe('path policy', () => {
it('returns PATH_NOT_ALLOWED when output_path is outside allowedPaths', () => {
const strictServer = new MockMcpServer();
registerTestCaseGenerate(strictServer as never, { allowedPaths: [tmpDir] });
const result = strictServer.call('provar_testcase_generate', {
test_case_name: 'Evil',
steps: [],
output_path: path.join(os.tmpdir(), 'evil.testcase'),
dry_run: false,
overwrite: false,
});
assert.equal(isError(result), true);
const code = parseText(result)['error_code'] as string;
assert.ok(code === 'PATH_NOT_ALLOWED' || code === 'PATH_TRAVERSAL', `Unexpected: ${code}`);
});
it('does NOT check path policy in dry_run=true mode', () => {
const strictServer = new MockMcpServer();
registerTestCaseGenerate(strictServer as never, { allowedPaths: [tmpDir] });
const result = strictServer.call('provar_testcase_generate', {
test_case_name: 'Safe',
steps: [],
output_path: '/etc/evil.testcase',
dry_run: true,
overwrite: false,
});
assert.equal(isError(result), false, 'dry_run should not trigger path check');
});
});
describe('idempotency_key', () => {
it('echoes back the provided idempotency_key', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Idempotent',
steps: [],
idempotency_key: 'dedup-key-abc',
dry_run: true,
overwrite: false,
});
assert.equal(parseText(result)['idempotency_key'], 'dedup-key-abc');
});
});
describe('XML argument valueClass casing', () => {
it('emits lowercase valueClass="string" not uppercase "String"', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'ValueClass Test',
steps: [
{
api_id: 'UiConnect',
name: 'Connect',
attributes: { connectionName: 'MyOrg' },
},
],
dry_run: true,
overwrite: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('valueClass="string"'), 'Expected lowercase valueClass="string"');
assert.ok(!xml.includes('valueClass="String"'), 'Must not emit uppercase valueClass="String"');
});
});
describe('target_uri — non-SF page object (ui:) nesting', () => {
it('wraps steps in UiWithScreen when target_uri uses ?pageId= format', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Non-SF Login',
steps: [{ api_id: 'UiDoAction', name: 'Enter username', attributes: { field: 'username' } }],
target_uri: 'ui:pageobject:target?pageId=pageobjects.LoginPage',
dry_run: true,
overwrite: false,
validate_after_edit: true,
});
assert.equal(isError(result), false);
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('UiWithScreen'), 'Expected UiWithScreen wrapper');
assert.ok(xml.includes('testItemId="1"'), 'UiWithScreen should be testItemId=1');
assert.ok(xml.includes('ui:pageobject:target?pageId=pageobjects.LoginPage'), 'Expected target URI in XML');
assert.ok(xml.includes('<clause name="substeps"'), 'Expected substeps clause wrapper');
});
it('substeps clause uses testItemId=2, inner steps start at testItemId=3', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Non-SF Multi',
steps: [
{ api_id: 'UiDoAction', name: 'Step A', attributes: {} },
{ api_id: 'UiDoAction', name: 'Step B', attributes: {} },
],
target_uri: 'ui:pageobject:target?pageId=pageobjects.LoginPage',
dry_run: true,
overwrite: false,
validate_after_edit: true,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('testItemId="2"'), 'substeps clause should be testItemId=2');
assert.ok(xml.includes('testItemId="3"'), 'First inner step should be testItemId=3');
assert.ok(xml.includes('testItemId="4"'), 'Second inner step should be testItemId=4');
});
it('uses flat structure when target_uri starts with sf:', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'SF Target',
steps: [{ api_id: 'UiConnect', name: 'Connect', attributes: {} }],
target_uri: 'sf:ui:target:Salesforce__Standard__Account',
dry_run: true,
overwrite: false,
validate_after_edit: true,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(!xml.includes('UiWithScreen'), 'Should not wrap in UiWithScreen for sf: target');
assert.ok(xml.includes('testItemId="1"'), 'Step should be testItemId=1 directly');
});
it('uses flat structure when target_uri is omitted', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'No URI',
steps: [{ api_id: 'UiConnect', name: 'Connect', attributes: {} }],
dry_run: true,
overwrite: false,
validate_after_edit: true,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(!xml.includes('UiWithScreen'), 'No UiWithScreen without target_uri');
});
});
describe('D2 — uiTarget / uiLocator argument types', () => {
it('emits class="uiTarget" uri="..." for the target argument', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'UI Target Test',
steps: [
{
api_id: 'UiWithScreen',
name: 'With page',
attributes: { target: 'sf:ui:target?pageObject=pageobjects.Account&flexiPage=Account_flexiPage' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="uiTarget"'), 'Expected class="uiTarget"');
assert.ok(xml.includes('uri="sf:ui:target?'), 'Expected uri attribute with sf:ui:target value');
assert.ok(
!xml.includes('valueClass="string">sf:ui:target'),
'Must NOT emit uiTarget URI as a plain string value'
);
});
it('emits class="uiLocator" uri="..." for the locator argument', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'UI Locator Test',
steps: [
{
api_id: 'UiDoAction',
name: 'Click button',
attributes: { locator: 'sf:ui:locator:button?label=Save' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="uiLocator"'), 'Expected class="uiLocator"');
assert.ok(xml.includes('uri="sf:ui:locator:'), 'Expected uri attribute with locator value');
assert.ok(
!xml.includes('valueClass="string">sf:ui:locator'),
'Must NOT emit locator URI as a plain string value'
);
});
it('uiTarget also applies inside UiWithScreen wrapper when target_uri is non-SF', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Non-SF With Target',
steps: [],
target_uri: 'ui:pageobject:target?pageId=pageobjects.LoginPage',
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="uiTarget"'), 'Wrapper UiWithScreen target should use uiTarget class');
assert.ok(
xml.includes('uri="ui:pageobject:target?pageId=pageobjects.LoginPage"'),
'URI should appear as attribute'
);
});
});
describe('D3 — SetValues / AssertValues use valueList/namedValues structure', () => {
it('SetValues emits <value class="valueList"> with <namedValues>', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'SetValues Test',
steps: [
{
api_id: 'SetValues',
name: 'Set test vars',
attributes: { testCaseName: 'TC_New', testType: 'Acceptance testing' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="valueList"'), 'Expected class="valueList"');
assert.ok(xml.includes('mutable="Mutable"'), 'Expected mutable="Mutable"');
assert.ok(xml.includes('<namedValues>'), 'Expected <namedValues> element');
assert.ok(xml.includes('<namedValue name="testCaseName">'), 'Expected namedValue for testCaseName');
assert.ok(xml.includes('<namedValue name="testType">'), 'Expected namedValue for testType');
assert.ok(xml.includes('<argument id="values">'), 'Expected argument id="values"');
assert.ok(!xml.includes('testCaseName|TC_New'), 'Must NOT emit pipe-delimited string for SetValues');
});
it('AssertValues uses flat argument structure (not valueList)', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'AssertValues Test',
steps: [
{
api_id: 'AssertValues',
name: 'Assert vars',
attributes: { opportunityName: 'My Opp' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('<argument id="opportunityName">'), 'Expected flat argument id for AssertValues');
assert.ok(!xml.includes('class="valueList"'), 'AssertValues must NOT emit valueList structure');
assert.ok(!xml.includes('<namedValue'), 'AssertValues must NOT emit namedValue elements');
});
it('non-SetValues steps still use flat argument structure', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Flat Args Test',
steps: [{ api_id: 'ApexCreateObject', name: 'Create record', attributes: { objectApiName: 'Opportunity' } }],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('<argument id="objectApiName">'), 'Expected flat argument id');
assert.ok(!xml.includes('valueList'), 'Must NOT emit valueList for non-SetValues steps');
});
});
describe('D4 — Variable references use class="variable" with <path> elements', () => {
it('{VarName} emits class="variable" <path element="VarName"/>', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Variable Ref Test',
steps: [
{
api_id: 'ApexCreateObject',
name: 'Create record',
attributes: { provar__Test_Project__c: '{TestProjectId}' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="variable"'), 'Expected class="variable"');
assert.ok(xml.includes('<path element="TestProjectId"/>'), 'Expected <path element="TestProjectId"/>');
assert.ok(!xml.includes('valueClass="string">{TestProjectId}'), 'Must NOT emit {VarName} as a string literal');
});
it('{Obj.Field} dotted path emits two <path> elements', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Dotted Variable Test',
steps: [
{
api_id: 'ApexCreateObject',
name: 'Create with nested var',
attributes: { Name: '{Opportunity.Name}' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('<path element="Opportunity"/>'), 'Expected first path element');
assert.ok(xml.includes('<path element="Name"/>'), 'Expected second path element');
});
it('variable reference also works inside SetValues namedValues', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'SetValues With Var',
steps: [
{
api_id: 'SetValues',
name: 'Set with variable',
attributes: { projectId: '{TestProjectId}', label: 'Static Label' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="variable"'), 'Expected variable reference inside namedValues');
assert.ok(xml.includes('<path element="TestProjectId"/>'));
assert.ok(xml.includes('valueClass="string">Static Label'), 'Static value should still be a plain string');
});
it('plain string values without braces are not treated as variable references', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'No Var Test',
steps: [{ api_id: 'ApexCreateObject', name: 'Create', attributes: { Name: 'Literal Name' } }],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('valueClass="string">Literal Name'), 'Plain string should use valueClass="string"');
assert.ok(!xml.includes('class="variable"'), 'No variable element expected');
});
});
describe('F1 — Compound values for {VarName} embedded in surrounding text', () => {
it('"Hello {Name}" emits class="compound" with literal and variable parts', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Compound Value Test',
steps: [
{
api_id: 'UiDoAction',
name: 'Enter greeting',
attributes: { value: 'Hello {Name}' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
assert.equal(isError(result), false);
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="compound"'), 'Expected class="compound" for mixed value');
assert.ok(xml.includes('<parts>'), 'Expected <parts> element');
assert.ok(xml.includes('valueClass="string">Hello '), 'Expected literal prefix as string part');
assert.ok(xml.includes('<variable>'), 'Expected <variable> element for the token');
assert.ok(xml.includes('<path element="Name"/>'), 'Expected <path element="Name"/>');
assert.ok(!xml.includes('valueClass="string">Hello {Name}'), 'Must NOT emit raw {Name} as string literal');
});
it('"{A} and {B}" emits compound with two variable parts', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Multi-Var Compound Test',
steps: [
{
api_id: 'UiDoAction',
name: 'Combine two vars',
attributes: { value: '{First} and {Last}' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
assert.equal(isError(result), false);
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="compound"'), 'Expected compound for two variables');
assert.ok(xml.includes('<path element="First"/>'), 'Expected path for First');
assert.ok(xml.includes('<path element="Last"/>'), 'Expected path for Last');
});
it('pure {VarName} alone still uses class="variable" (not compound)', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Pure Var Test',
steps: [
{
api_id: 'UiDoAction',
name: 'Pure var',
attributes: { value: '{AccountId}' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
assert.equal(isError(result), false);
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="variable"'), 'Pure token should still use class="variable"');
assert.ok(!xml.includes('class="compound"'), 'Should not emit compound for a pure variable token');
});
});
describe('D7 — Cleanup warning for ApexDeleteObject', () => {
it('includes cleanup warning when ApexDeleteObject is in the step list', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Create and Delete',
steps: [
{ api_id: 'ApexCreateObject', name: 'Create record', attributes: { objectApiName: 'Account' } },
{ api_id: 'ApexDeleteObject', name: 'Delete record', attributes: { objectApiName: 'Account' } },
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
assert.equal(isError(result), false);
const body = parseText(result);
const warnings = body['warnings'] as string[] | undefined;
assert.ok(Array.isArray(warnings) && warnings.length > 0, 'Expected at least one warning');
assert.ok(
warnings.some((w) => w.includes('ApexDeleteObject') && w.includes('cleanup')),
'Expected cleanup warning mentioning ApexDeleteObject'
);
});
it('does NOT warn when no ApexDeleteObject steps are present', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'No Cleanup',
steps: [{ api_id: 'ApexCreateObject', name: 'Create', attributes: {} }],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
assert.equal(isError(result), false);
const body = parseText(result);
const warnings = body['warnings'] as string[] | undefined;
const hasCleanupWarning = warnings?.some((w) => w.includes('ApexDeleteObject'));
assert.ok(!hasCleanupWarning, 'No cleanup warning expected without ApexDeleteObject');
});
});
describe('validate_after_edit', () => {
it('includes validation field when validate_after_edit=true (default)', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Validated',
steps: [{ api_id: 'UiConnect', name: 'Connect', attributes: {} }],
dry_run: true,
overwrite: false,
validate_after_edit: true,
});
assert.equal(isError(result), false);
const body = parseText(result);
assert.ok(body['validation'], 'Expected validation field');
});
it('omits validation field when validate_after_edit=false', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Skip Validation',
steps: [],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
assert.equal(isError(result), false);
const body = parseText(result);
assert.ok(!('validation' in body), 'validation field should be absent when validate_after_edit=false');
});
});
describe('F1/F3 — compound value emission for embedded {VarName} tokens', () => {
it('emits class="compound" with <parts> when a SOQL query embeds a variable (F1)', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'SOQL Compound Test',
steps: [
{
api_id: 'ApexSoqlQuery',
name: 'Query account',
attributes: { soqlQuery: "SELECT Id, Name FROM Account WHERE Id = '{AccountId}'" },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
assert.equal(isError(result), false);
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="compound"'), 'Expected class="compound" for embedded variable in SOQL');
assert.ok(xml.includes('<parts>'), 'Expected <parts> element inside compound value');
assert.ok(xml.includes('<variable>'), 'Expected <variable> element for the AccountId reference');
assert.ok(xml.includes('<path element="AccountId"/>'), 'Expected <path element="AccountId"/>');
assert.ok(
!xml.includes('valueClass="string">{AccountId}'),
'Must NOT emit {AccountId} as a plain string literal'
);
});
it('emits class="compound" for Provar system variables embedded in a string (F3: {NOW})', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'NOW Compound Test',
steps: [
{
api_id: 'SetValues',
name: 'Set account name',
attributes: { AccountName: 'Acme Corp CRUD Test {NOW}' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
assert.equal(isError(result), false);
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="compound"'), 'Expected class="compound" inside namedValues');
assert.ok(xml.includes('<path element="NOW"/>'), 'Expected <path element="NOW"/> for system variable');
assert.ok(
!xml.includes('valueClass="string">Acme Corp CRUD Test {NOW}'),
'Must NOT emit {NOW} as a literal string'
);
});
it('emits <parts> with correct literal fragments around the variable', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Fragment Test',
steps: [
{
api_id: 'ApexSoqlQuery',
name: 'Query with prefix and suffix',
attributes: { soqlQuery: "SELECT Id FROM Contact WHERE Email = '{Email}' LIMIT 1" },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes("SELECT Id FROM Contact WHERE Email = '"), 'Expected literal prefix fragment');
assert.ok(xml.includes("' LIMIT 1"), 'Expected literal suffix fragment');
assert.ok(xml.includes('<path element="Email"/>'), 'Expected variable path element');
});
it('handles multiple embedded variables in one string', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Multi Var Test',
steps: [
{
api_id: 'ApexSoqlQuery',
name: 'Query by two fields',
attributes: { soqlQuery: "SELECT Id FROM Case WHERE AccountId='{AccId}' AND OwnerId='{OwnerId}'" },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('<path element="AccId"/>'), 'Expected first variable path');
assert.ok(xml.includes('<path element="OwnerId"/>'), 'Expected second variable path');
const compoundCount = (xml.match(/class="compound"/g) ?? []).length;
assert.equal(compoundCount, 1, 'Should be exactly one compound element for the soqlQuery argument');
});
it('pure {VarName} value (entire argument) still uses class="variable", not compound', () => {
const result = server.call('provar_testcase_generate', {
test_case_name: 'Pure Var Test',
steps: [
{
api_id: 'ApexDeleteObject',
name: 'Delete account',
attributes: { recordId: '{AccountId}' },
},
],
dry_run: true,
overwrite: false,
validate_after_edit: false,
});
const xml = parseText(result)['xml_content'] as string;
assert.ok(xml.includes('class="variable"'), 'Pure {VarName} should use class="variable"');
assert.ok(!xml.includes('class="compound"'), 'Pure {VarName} must NOT use class="compound"');
});
});
});