azure-pipelines-tasks-webdeployment-common 4.230.1 → 4.230.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/Tests/L0.d.ts +1 -0
  2. package/Tests/L0.js +25 -0
  3. package/Tests/L0.ts +24 -0
  4. package/Tests/L0CopyDirectory.d.ts +1 -5
  5. package/Tests/L0CopyDirectory.js +89 -51
  6. package/Tests/L0CopyDirectory.ts +93 -55
  7. package/Tests/L0GenerateWebConfig.d.ts +1 -2
  8. package/Tests/L0GenerateWebConfig.js +55 -24
  9. package/Tests/L0GenerateWebConfig.ts +51 -31
  10. package/Tests/L0MSDeployUtility.d.ts +2 -16
  11. package/Tests/L0MSDeployUtility.js +91 -97
  12. package/Tests/L0MSDeployUtility.ts +89 -100
  13. package/Tests/L0ParameterParserUtility.d.ts +1 -0
  14. package/Tests/L0ParameterParserUtility.js +59 -0
  15. package/Tests/L0ParameterParserUtility.ts +65 -0
  16. package/Tests/L1JSONVarSubWithComments.d.ts +1 -1
  17. package/Tests/L1JSONVarSubWithComments.js +30 -46
  18. package/Tests/L1JSONVarSubWithComments.ts +39 -52
  19. package/Tests/L1JsonVarSub.d.ts +1 -1
  20. package/Tests/L1JsonVarSub.js +58 -66
  21. package/Tests/L1JsonVarSub.ts +67 -66
  22. package/Tests/L1JsonVarSubV2.d.ts +1 -1
  23. package/Tests/L1JsonVarSubV2.js +82 -93
  24. package/Tests/L1JsonVarSubV2.ts +82 -94
  25. package/Tests/L1ValidateFileEncoding.d.ts +2 -5
  26. package/Tests/L1ValidateFileEncoding.js +52 -65
  27. package/Tests/L1ValidateFileEncoding.ts +61 -77
  28. package/Tests/L1XdtTransform.d.ts +2 -3
  29. package/Tests/L1XdtTransform.js +48 -6
  30. package/Tests/L1XdtTransform.ts +57 -6
  31. package/Tests/L1XmlVarSub.d.ts +2 -3
  32. package/Tests/L1XmlVarSub.js +56 -20
  33. package/Tests/L1XmlVarSub.ts +81 -24
  34. package/ctt/ctt/ctt.exe +0 -0
  35. package/package.json +7 -3
  36. package/packageUtility.js +6 -5
  37. package/utility.js +1 -1
  38. package/webconfigutil.d.ts +3 -1
  39. package/xdttransformationutility.js +1 -1
@@ -1,52 +1,39 @@
1
- var jsonSubUtil = require('azure-pipelines-tasks-webdeployment-common/jsonvariablesubstitutionutility.js');
2
- import fs = require('fs');
3
- import path = require('path');
4
-
5
- var envVarObject = jsonSubUtil.createEnvTree([
6
- { name: 'dataSourceBindings.0.target', value: 'AppServiceName', secret: false},
7
- { name: 'name', value: 'App Service Deploy', secret: false},
8
- { name: 'Hello.World', value: 'Hello World', secret: false},
9
- { name: 'dataSourceBindings.1.parameters.WebAppName', value: 'App Service Name params', secret: false},
10
- { name: 'messages.Invalidwebapppackageorfolderpathprovided', value: 'Invalidwebapppackageorfolderpathprovided', secret: true}
11
- ]);
12
-
13
- function validateJSONWithComments() {
14
- var fileContent: string = fs.readFileSync(path.join(__dirname, 'L1JSONVarSub', 'JSONWithComments.json'), 'utf-8');
15
- var jsonContent: string = jsonSubUtil.stripJsonComments(fileContent);
16
- var jsonObject = JSON.parse(jsonContent);
17
- jsonSubUtil.substituteJsonVariable(jsonObject, envVarObject);
18
-
19
- if(jsonObject['dataSourceBindings']['0']['target'] != 'AppServiceName') {
20
- throw new Error('JSON VAR SUB FAIL #1');
21
- }
22
- if(jsonObject['name'] != 'App Service Deploy') {
23
- throw new Error('JSON VAR SUB FAIL #2');
24
- }
25
- if(jsonObject['Hello']['World'] != 'Hello World') {
26
- throw new Error('JSON VAR SUB FAIL #3');
27
- }
28
- if(jsonObject['dataSourceBindings']['1']['parameters']['WebAppName'] != 'App Service Name params') {
29
- throw new Error('JSON VAR SUB FAIL #4');
30
- }
31
- if(jsonObject['messages']['Invalidwebapppackageorfolderpathprovided'] != 'Invalidwebapppackageorfolderpathprovided') {
32
- throw new Error('JSON VAR SUB FAIL #5');
33
- }
34
- console.log("VALID JSON COMMENTS TESTS PASSED");
35
- }
36
-
37
- function validateInvalidJSONWithComments() {
38
- var fileContent: string = fs.readFileSync(path.join(__dirname, 'L1JSONVarSub', 'InvalidJSONWithComments.json'), 'utf-8');
39
- var jsonContent: string = jsonSubUtil.stripJsonComments(fileContent);
40
- try {
41
- var jsonObject = JSON.parse(jsonContent);
42
- throw new Error('JSON VAR SUB FAIL #6');
43
- }
44
- catch(error) {
45
- console.log("INVALID JSON COMMENTS TESTS PASSED");
46
- }
47
- }
48
-
49
- export function validate() {
50
- validateJSONWithComments();
51
- validateInvalidJSONWithComments();
52
- }
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as assert from 'assert';
4
+
5
+ import { createEnvTree, stripJsonComments, substituteJsonVariable } from "../jsonvariablesubstitutionutility";
6
+
7
+
8
+ export function runL1JSONVarSubWithCommentsTests(): void {
9
+
10
+ it("Should substitute variables in JSON with comments", (done: Mocha.Done) => {
11
+ const envVarObject = createEnvTree([
12
+ { name: 'dataSourceBindings.0.target', value: 'AppServiceName', secret: false },
13
+ { name: 'name', value: 'App Service Deploy', secret: false },
14
+ { name: 'Hello.World', value: 'Hello World', secret: false },
15
+ { name: 'dataSourceBindings.1.parameters.WebAppName', value: 'App Service Name params', secret: false },
16
+ { name: 'messages.Invalidwebapppackageorfolderpathprovided', value: 'Invalidwebapppackageorfolderpathprovided', secret: true }
17
+ ]);
18
+
19
+ const fileContent: string = fs.readFileSync(path.join(__dirname, 'L1JSONVarSub', 'JSONWithComments.json'), 'utf-8');
20
+ const jsonContent: string = stripJsonComments(fileContent);
21
+ const jsonObject = JSON.parse(jsonContent);
22
+ substituteJsonVariable(jsonObject, envVarObject);
23
+
24
+ assert.strictEqual(jsonObject['dataSourceBindings']['0']['target'], 'AppServiceName', 'Should have substituted target variable');
25
+ assert.strictEqual(jsonObject['name'], 'App Service Deploy', 'Should have substituted name variable');
26
+ assert.strictEqual(jsonObject['Hello']['World'], 'Hello World', 'Should have substituted Hello.World variable');
27
+ assert.strictEqual(jsonObject['dataSourceBindings']['1']['parameters']['WebAppName'], 'App Service Name params', 'Should have substituted WebAppName variable');
28
+ assert.strictEqual(jsonObject['messages']['Invalidwebapppackageorfolderpathprovided'], 'Invalidwebapppackageorfolderpathprovided', 'Should have substituted Invalidwebapppackageorfolderpathprovided variable');
29
+
30
+ done();
31
+ });
32
+
33
+ it("Should throw exception for invalid JSON with comments", (done: Mocha.Done) => {
34
+ const fileContent = fs.readFileSync(path.join(__dirname, 'L1JSONVarSub', 'InvalidJSONWithComments.json'), 'utf-8');
35
+ const jsonContent = stripJsonComments(fileContent);
36
+ assert.throws(() => JSON.parse(jsonContent), "Parse is expected to throw an error");
37
+ done();
38
+ });
39
+ }
@@ -1 +1 @@
1
- export {};
1
+ export declare function runL1JsonVarSubTests(): void;
@@ -1,69 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const L1JSONVarSubWithComments_1 = require("./L1JSONVarSubWithComments");
4
- var jsonSubUtil = require('azure-pipelines-tasks-webdeployment-common/jsonvariablesubstitutionutility.js');
5
- var envVarObject = jsonSubUtil.createEnvTree([
6
- { name: 'system.debug', value: 'true', secret: false },
7
- { name: 'data.ConnectionString', value: 'database_connection', secret: false },
8
- { name: 'data.userName', value: 'db_admin', secret: false },
9
- { name: 'data.password', value: 'db_pass', secret: true },
10
- { name: '&pl.ch@r@cter.k^y', value: '*.config', secret: false },
11
- { name: 'build.sourceDirectory', value: 'DefaultWorkingDirectory', secret: false },
12
- { name: 'user.profile.name.first', value: 'firstName', secret: false },
13
- { name: 'user.profile', value: 'replace_all', secret: false },
14
- { name: 'constructor.name', value: 'newConstructorName', secret: false },
15
- { name: 'constructor.valueOf', value: 'constructorNewValue', secret: false },
16
- { name: 'systemsettings.appurl', value: 'https://dev.azure.com/helloworld', secret: false }
17
- ]);
18
- var jsonObject = {
19
- 'User.Profile': 'do_not_replace',
20
- 'data': {
21
- 'ConnectionString': 'connect_string',
22
- 'userName': 'name',
23
- 'password': 'pass'
24
- },
25
- '&pl': {
26
- 'ch@r@cter.k^y': 'v@lue'
27
- },
28
- 'system': {
29
- 'debug': 'no_change'
30
- },
31
- 'user.profile': {
32
- 'name.first': 'fname'
33
- },
34
- 'constructor.name': 'myconstructorname',
35
- 'constructor': {
36
- 'name': 'myconstructorname',
37
- 'valueOf': 'myconstructorvalue'
38
- },
39
- 'systemsettings': {
40
- 'appurl': 'https://helloworld.visualstudio.com'
41
- }
42
- };
43
- // Method to be checked for JSON variable substitution
44
- jsonSubUtil.substituteJsonVariable(jsonObject, envVarObject);
45
- if (typeof jsonObject['user.profile'] === 'object') {
46
- console.log('JSON - eliminating object variables validated');
3
+ exports.runL1JsonVarSubTests = void 0;
4
+ const assert = require("assert");
5
+ const jsonvariablesubstitutionutility_1 = require("../jsonvariablesubstitutionutility");
6
+ function runL1JsonVarSubTests() {
7
+ it("Should substitute JSON variables", (done) => {
8
+ const envVarObject = jsonvariablesubstitutionutility_1.createEnvTree([
9
+ { name: 'system.debug', value: 'true', secret: false },
10
+ { name: 'data.ConnectionString', value: 'database_connection', secret: false },
11
+ { name: 'data.userName', value: 'db_admin', secret: false },
12
+ { name: 'data.password', value: 'db_pass', secret: true },
13
+ { name: '&pl.ch@r@cter.k^y', value: '*.config', secret: false },
14
+ { name: 'build.sourceDirectory', value: 'DefaultWorkingDirectory', secret: false },
15
+ { name: 'user.profile.name.first', value: 'firstName', secret: false },
16
+ { name: 'user.profile', value: 'replace_all', secret: false },
17
+ { name: 'constructor.name', value: 'newConstructorName', secret: false },
18
+ { name: 'constructor.valueOf', value: 'constructorNewValue', secret: false },
19
+ { name: 'systemsettings.appurl', value: 'https://dev.azure.com/helloworld', secret: false }
20
+ ]);
21
+ const jsonObject = {
22
+ 'User.Profile': 'do_not_replace',
23
+ 'data': {
24
+ 'ConnectionString': 'connect_string',
25
+ 'userName': 'name',
26
+ 'password': 'pass'
27
+ },
28
+ '&pl': {
29
+ 'ch@r@cter.k^y': 'v@lue'
30
+ },
31
+ 'system': {
32
+ 'debug': 'no_change'
33
+ },
34
+ 'user.profile': {
35
+ 'name.first': 'fname'
36
+ },
37
+ 'constructor.name': 'myconstructorname',
38
+ 'constructor': {
39
+ 'name': 'myconstructorname',
40
+ 'valueOf': 'myconstructorvalue'
41
+ },
42
+ 'systemsettings': {
43
+ 'appurl': 'https://helloworld.visualstudio.com'
44
+ }
45
+ };
46
+ jsonvariablesubstitutionutility_1.substituteJsonVariable(jsonObject, envVarObject);
47
+ assert.strictEqual(typeof jsonObject['user.profile'], 'object');
48
+ assert.strictEqual(jsonObject['data']['ConnectionString'], 'database_connection');
49
+ assert.strictEqual(jsonObject['data']['userName'], 'db_admin');
50
+ assert.strictEqual(jsonObject['systemsettings']['appurl'], 'https://dev.azure.com/helloworld');
51
+ assert.strictEqual(jsonObject['system']['debug'], 'no_change');
52
+ assert.strictEqual(jsonObject['&pl']['ch@r@cter.k^y'], '*.config');
53
+ assert.strictEqual(jsonObject['user.profile']['name.first'], 'firstName');
54
+ assert.strictEqual(jsonObject['User.Profile'], 'do_not_replace');
55
+ assert.strictEqual(jsonObject['constructor.name'], 'newConstructorName');
56
+ assert.strictEqual(jsonObject['constructor']['name'], 'newConstructorName');
57
+ assert.strictEqual(jsonObject['constructor']['valueOf'], 'constructorNewValue');
58
+ done();
59
+ });
47
60
  }
48
- if (jsonObject['data']['ConnectionString'] === 'database_connection'
49
- && jsonObject['data']['userName'] === 'db_admin'
50
- && jsonObject['systemsettings']['appurl'] == 'https://dev.azure.com/helloworld') {
51
- console.log('JSON - simple string change validated');
52
- }
53
- if (jsonObject['system']['debug'] === 'no_change') {
54
- console.log('JSON - system variable elimination validated');
55
- }
56
- if (jsonObject['&pl']['ch@r@cter.k^y'] === '*.config') {
57
- console.log('JSON - special variables validated');
58
- }
59
- if (jsonObject['user.profile']['name.first'] === 'firstName') {
60
- console.log('JSON - variables with dot character validated');
61
- }
62
- if (jsonObject['User.Profile'] === 'do_not_replace') {
63
- console.log('JSON - case sensitive variables validated');
64
- }
65
- if (jsonObject['constructor.name'] === 'newConstructorName' &&
66
- jsonObject['constructor']['name'] === 'newConstructorName' && jsonObject['constructor']['valueOf'] === 'constructorNewValue') {
67
- console.log('JSON - substitute inbuilt JSON attributes validated');
68
- }
69
- L1JSONVarSubWithComments_1.validate();
61
+ exports.runL1JsonVarSubTests = runL1JsonVarSubTests;
@@ -1,71 +1,72 @@
1
- import { validate } from './L1JSONVarSubWithComments';
2
- var jsonSubUtil = require('azure-pipelines-tasks-webdeployment-common/jsonvariablesubstitutionutility.js');
1
+ import * as assert from 'assert';
3
2
 
4
- var envVarObject = jsonSubUtil.createEnvTree([
5
- { name: 'system.debug', value: 'true', secret: false},
6
- { name: 'data.ConnectionString', value: 'database_connection', secret: false},
7
- { name: 'data.userName', value: 'db_admin', secret: false},
8
- { name: 'data.password', value: 'db_pass', secret: true},
9
- { name: '&pl.ch@r@cter.k^y', value: '*.config', secret: false},
10
- { name: 'build.sourceDirectory', value: 'DefaultWorkingDirectory', secret: false},
11
- { name: 'user.profile.name.first', value: 'firstName', secret: false},
12
- { name: 'user.profile', value: 'replace_all', secret: false},
13
- { name: 'constructor.name', value: 'newConstructorName', secret: false},
14
- { name: 'constructor.valueOf', value: 'constructorNewValue', secret: false},
15
- { name: 'systemsettings.appurl', value: 'https://dev.azure.com/helloworld', secret: false}
16
- ]);
3
+ import { createEnvTree, substituteJsonVariable } from '../jsonvariablesubstitutionutility';
17
4
 
18
- var jsonObject = {
19
- 'User.Profile': 'do_not_replace',
20
- 'data': {
21
- 'ConnectionString' : 'connect_string',
22
- 'userName': 'name',
23
- 'password': 'pass'
24
- },
25
- '&pl': {
26
- 'ch@r@cter.k^y': 'v@lue'
27
- },
28
- 'system': {
29
- 'debug' : 'no_change'
30
- },
31
- 'user.profile': {
32
- 'name.first' : 'fname'
33
- },
34
- 'constructor.name': 'myconstructorname',
35
- 'constructor': {
36
- 'name': 'myconstructorname',
37
- 'valueOf': 'myconstructorvalue'
38
- },
39
- 'systemsettings': {
40
- 'appurl': 'https://helloworld.visualstudio.com'
41
- }
42
- }
43
- // Method to be checked for JSON variable substitution
44
- jsonSubUtil.substituteJsonVariable(jsonObject, envVarObject);
45
5
 
46
- if(typeof jsonObject['user.profile'] === 'object') {
47
- console.log('JSON - eliminating object variables validated');
48
- }
49
- if(jsonObject['data']['ConnectionString'] === 'database_connection'
50
- && jsonObject['data']['userName'] === 'db_admin'
51
- && jsonObject['systemsettings']['appurl'] == 'https://dev.azure.com/helloworld') {
52
- console.log('JSON - simple string change validated');
53
- }
54
- if(jsonObject['system']['debug'] === 'no_change') {
55
- console.log('JSON - system variable elimination validated');
56
- }
57
- if(jsonObject['&pl']['ch@r@cter.k^y'] === '*.config') {
58
- console.log('JSON - special variables validated');
59
- }
60
- if(jsonObject['user.profile']['name.first'] === 'firstName') {
61
- console.log('JSON - variables with dot character validated');
62
- }
63
- if(jsonObject['User.Profile'] === 'do_not_replace') {
64
- console.log('JSON - case sensitive variables validated');
65
- }
66
- if(jsonObject['constructor.name'] === 'newConstructorName' &&
67
- jsonObject['constructor']['name'] === 'newConstructorName' && jsonObject['constructor']['valueOf'] === 'constructorNewValue') {
68
- console.log('JSON - substitute inbuilt JSON attributes validated');
6
+ export function runL1JsonVarSubTests(): void {
7
+
8
+ it("Should substitute JSON variables", (done: Mocha.Done) => {
9
+ const envVarObject = createEnvTree([
10
+ { name: 'system.debug', value: 'true', secret: false },
11
+ { name: 'data.ConnectionString', value: 'database_connection', secret: false },
12
+ { name: 'data.userName', value: 'db_admin', secret: false },
13
+ { name: 'data.password', value: 'db_pass', secret: true },
14
+ { name: '&pl.ch@r@cter.k^y', value: '*.config', secret: false },
15
+ { name: 'build.sourceDirectory', value: 'DefaultWorkingDirectory', secret: false },
16
+ { name: 'user.profile.name.first', value: 'firstName', secret: false },
17
+ { name: 'user.profile', value: 'replace_all', secret: false },
18
+ { name: 'constructor.name', value: 'newConstructorName', secret: false },
19
+ { name: 'constructor.valueOf', value: 'constructorNewValue', secret: false },
20
+ { name: 'systemsettings.appurl', value: 'https://dev.azure.com/helloworld', secret: false }
21
+ ]);
22
+
23
+ const jsonObject = {
24
+ 'User.Profile': 'do_not_replace',
25
+ 'data': {
26
+ 'ConnectionString': 'connect_string',
27
+ 'userName': 'name',
28
+ 'password': 'pass'
29
+ },
30
+ '&pl': {
31
+ 'ch@r@cter.k^y': 'v@lue'
32
+ },
33
+ 'system': {
34
+ 'debug': 'no_change'
35
+ },
36
+ 'user.profile': {
37
+ 'name.first': 'fname'
38
+ },
39
+ 'constructor.name': 'myconstructorname',
40
+ 'constructor': {
41
+ 'name': 'myconstructorname',
42
+ 'valueOf': 'myconstructorvalue'
43
+ },
44
+ 'systemsettings': {
45
+ 'appurl': 'https://helloworld.visualstudio.com'
46
+ }
47
+ };
48
+
49
+ substituteJsonVariable(jsonObject, envVarObject);
50
+
51
+ assert.strictEqual(typeof jsonObject['user.profile'], 'object');
52
+ assert.strictEqual(jsonObject['data']['ConnectionString'], 'database_connection');
53
+ assert.strictEqual(jsonObject['data']['userName'], 'db_admin');
54
+ assert.strictEqual(jsonObject['systemsettings']['appurl'], 'https://dev.azure.com/helloworld');
55
+ assert.strictEqual(jsonObject['system']['debug'], 'no_change');
56
+ assert.strictEqual(jsonObject['&pl']['ch@r@cter.k^y'], '*.config');
57
+ assert.strictEqual(jsonObject['user.profile']['name.first'], 'firstName');
58
+ assert.strictEqual(jsonObject['User.Profile'], 'do_not_replace');
59
+ assert.strictEqual(jsonObject['constructor.name'], 'newConstructorName');
60
+ assert.strictEqual(jsonObject['constructor']['name'], 'newConstructorName');
61
+ assert.strictEqual(jsonObject['constructor']['valueOf'], 'constructorNewValue');
62
+
63
+ done();
64
+ });
65
+
69
66
  }
70
67
 
71
- validate();
68
+
69
+
70
+
71
+
72
+
@@ -1 +1 @@
1
- export {};
1
+ export declare function runL1JsonVarSubV2Tests(): void;
@@ -1,97 +1,86 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const L1JSONVarSubWithComments_1 = require("./L1JSONVarSubWithComments");
4
- var jsonSubUtil = require('azure-pipelines-tasks-webdeployment-common/jsonvariablesubstitutionutility.js');
5
- var envVarObject = jsonSubUtil.createEnvTree([
6
- { name: 'system.debug', value: 'true', secret: false },
7
- { name: 'data.ConnectionString', value: 'database_connection', secret: false },
8
- { name: 'data.userName', value: 'db_admin', secret: false },
9
- { name: 'data.password', value: 'db_pass', secret: true },
10
- { name: '&pl.ch@r@cter.k^y', value: '*.config', secret: false },
11
- { name: 'build.sourceDirectory', value: 'DefaultWorkingDirectory', secret: false },
12
- { name: 'user.profile.name.first', value: 'firstName', secret: false },
13
- { name: 'user.profile', value: 'replace_all', secret: false },
14
- { name: 'constructor.name', value: 'newConstructorName', secret: false },
15
- { name: 'constructor.valueOf', value: 'constructorNewValue', secret: false },
16
- { name: 'profile.users', value: '["suaggar","rok","asranja", "chaitanya"]', secret: false },
17
- { name: 'profile.enabled', value: 'false', secret: false },
18
- { name: 'profile.version', value: '1173', secret: false },
19
- { name: 'profile.somefloat', value: '97.75', secret: false },
20
- { name: 'profile.preimum_level', value: '{"suaggar": "V4", "rok": "V5", "asranja": { "type" : "V6"}}', secret: false },
21
- { name: 'systemsettings.appurl', value: 'https://dev.azure.com/helloworld', secret: false }
22
- ]);
23
- var jsonObject = {
24
- 'User.Profile': 'do_not_replace',
25
- 'data': {
26
- 'ConnectionString': 'connect_string',
27
- 'userName': 'name',
28
- 'password': 'pass'
29
- },
30
- '&pl': {
31
- 'ch@r@cter.k^y': 'v@lue'
32
- },
33
- 'system': {
34
- 'debug': 'no_change'
35
- },
36
- 'user.profile': {
37
- 'name.first': 'fname'
38
- },
39
- 'constructor.name': 'myconstructorname',
40
- 'constructor': {
41
- 'name': 'myconstructorname',
42
- 'valueOf': 'myconstructorvalue'
43
- },
44
- 'profile': {
45
- 'users': ['arjgupta', 'raagra', 'muthuk'],
46
- 'preimum_level': {
47
- 'arjgupta': 'V1',
48
- 'raagra': 'V2',
49
- 'muthuk': {
50
- 'type': 'V3'
3
+ exports.runL1JsonVarSubV2Tests = void 0;
4
+ const assert = require("assert");
5
+ const jsonvariablesubstitutionutility_1 = require("../jsonvariablesubstitutionutility");
6
+ function runL1JsonVarSubV2Tests() {
7
+ it("Should substitute JSON variables V2", (done) => {
8
+ const envVarObject = jsonvariablesubstitutionutility_1.createEnvTree([
9
+ { name: 'system.debug', value: 'true', secret: false },
10
+ { name: 'data.ConnectionString', value: 'database_connection', secret: false },
11
+ { name: 'data.userName', value: 'db_admin', secret: false },
12
+ { name: 'data.password', value: 'db_pass', secret: true },
13
+ { name: '&pl.ch@r@cter.k^y', value: '*.config', secret: false },
14
+ { name: 'build.sourceDirectory', value: 'DefaultWorkingDirectory', secret: false },
15
+ { name: 'user.profile.name.first', value: 'firstName', secret: false },
16
+ { name: 'user.profile', value: 'replace_all', secret: false },
17
+ { name: 'constructor.name', value: 'newConstructorName', secret: false },
18
+ { name: 'constructor.valueOf', value: 'constructorNewValue', secret: false },
19
+ { name: 'profile.users', value: '["suaggar","rok","asranja", "chaitanya"]', secret: false },
20
+ { name: 'profile.enabled', value: 'false', secret: false },
21
+ { name: 'profile.version', value: '1173', secret: false },
22
+ { name: 'profile.somefloat', value: '97.75', secret: false },
23
+ { name: 'profile.preimum_level', value: '{"suaggar": "V4", "rok": "V5", "asranja": { "type" : "V6"}}', secret: false },
24
+ { name: 'systemsettings.appurl', value: 'https://dev.azure.com/helloworld', secret: false }
25
+ ]);
26
+ const jsonObject = {
27
+ 'User.Profile': 'do_not_replace',
28
+ 'data': {
29
+ 'ConnectionString': 'connect_string',
30
+ 'userName': 'name',
31
+ 'password': 'pass'
32
+ },
33
+ '&pl': {
34
+ 'ch@r@cter.k^y': 'v@lue'
35
+ },
36
+ 'system': {
37
+ 'debug': 'no_change'
38
+ },
39
+ 'user.profile': {
40
+ 'name.first': 'fname'
41
+ },
42
+ 'constructor.name': 'myconstructorname',
43
+ 'constructor': {
44
+ 'name': 'myconstructorname',
45
+ 'valueOf': 'myconstructorvalue'
46
+ },
47
+ 'profile': {
48
+ 'users': ['arjgupta', 'raagra', 'muthuk'],
49
+ 'preimum_level': {
50
+ 'arjgupta': 'V1',
51
+ 'raagra': 'V2',
52
+ 'muthuk': {
53
+ 'type': 'V3'
54
+ }
55
+ },
56
+ "enabled": true,
57
+ "version": 2,
58
+ "somefloat": 2.3456
59
+ },
60
+ 'systemsettings': {
61
+ 'appurl': 'https://helloworld.visualstudio.com'
51
62
  }
52
- },
53
- "enabled": true,
54
- "version": 2,
55
- "somefloat": 2.3456
56
- },
57
- 'systemsettings': {
58
- 'appurl': 'https://helloworld.visualstudio.com'
59
- }
60
- };
61
- // Method to be checked for JSON variable substitution
62
- jsonSubUtil.substituteJsonVariableV2(jsonObject, envVarObject);
63
- if (jsonObject['data']['ConnectionString'] === 'database_connection'
64
- && jsonObject['data']['userName'] === 'db_admin'
65
- && jsonObject['systemsettings']['appurl'] == 'https://dev.azure.com/helloworld') {
66
- console.log('JSON - simple string change validated');
63
+ };
64
+ jsonvariablesubstitutionutility_1.substituteJsonVariableV2(jsonObject, envVarObject);
65
+ assert.strictEqual(jsonObject['data']['ConnectionString'], 'database_connection');
66
+ assert.strictEqual(jsonObject['data']['userName'], 'db_admin');
67
+ assert.strictEqual(jsonObject['systemsettings']['appurl'], 'https://dev.azure.com/helloworld');
68
+ assert.strictEqual(jsonObject['system']['debug'], 'no_change');
69
+ assert.strictEqual(jsonObject['&pl']['ch@r@cter.k^y'], '*.config');
70
+ assert.strictEqual(jsonObject['User.Profile'], 'do_not_replace');
71
+ assert.strictEqual(jsonObject['constructor.name'], 'newConstructorName');
72
+ assert.strictEqual(jsonObject['constructor']['name'], 'newConstructorName');
73
+ assert.strictEqual(jsonObject['constructor']['valueOf'], 'constructorNewValue');
74
+ assert.strictEqual(jsonObject['profile']['users'].length, 4);
75
+ assert.notStrictEqual(jsonObject['profile']['users'].indexOf('suaggar'), -1);
76
+ assert.notStrictEqual(jsonObject['profile']['users'].indexOf('rok'), -1);
77
+ assert.notStrictEqual(jsonObject['profile']['users'].indexOf('asranja'), -1);
78
+ assert.notStrictEqual(jsonObject['profile']['users'].indexOf('chaitanya'), -1);
79
+ assert.strictEqual(jsonObject['profile']['enabled'], false);
80
+ assert.strictEqual(jsonObject['profile']['somefloat'], 97.75);
81
+ assert.strictEqual(jsonObject['profile']['version'], 1173);
82
+ assert.deepStrictEqual(jsonObject['profile']['preimum_level'], { suaggar: "V4", rok: "V5", asranja: { type: "V6" } });
83
+ done();
84
+ });
67
85
  }
68
- if (jsonObject['system']['debug'] === 'no_change') {
69
- console.log('JSON - system variable elimination validated');
70
- }
71
- if (jsonObject['&pl']['ch@r@cter.k^y'] === '*.config') {
72
- console.log('JSON - special variables validated');
73
- }
74
- if (jsonObject['User.Profile'] === 'do_not_replace') {
75
- console.log('JSON - case sensitive variables validated');
76
- }
77
- if (jsonObject['constructor.name'] === 'newConstructorName' &&
78
- jsonObject['constructor']['name'] === 'newConstructorName' && jsonObject['constructor']['valueOf'] === 'constructorNewValue') {
79
- console.log('JSON - substitute inbuilt JSON attributes validated');
80
- }
81
- let newArray = ["suaggar", "rok", "asranja", "chaitanya"];
82
- if (jsonObject['profile']['users'].length == 4 && (jsonObject['profile']['users']).every((value, index) => { return value == newArray[index]; })) {
83
- console.log('JSON - Array Object validated');
84
- }
85
- if (jsonObject['profile']['enabled'] == false) {
86
- console.log('JSON - Boolean validated');
87
- }
88
- if (jsonObject['profile']['somefloat'] == 97.75) {
89
- console.log('JSON - Number(float) validated');
90
- }
91
- if (jsonObject['profile']['version'] == 1173) {
92
- console.log('JSON - Number(int) validated');
93
- }
94
- if (JSON.stringify(jsonObject['profile']['preimum_level']) == JSON.stringify({ "suaggar": "V4", "rok": "V5", "asranja": { "type": "V6" } })) {
95
- console.log('JSON - Object validated');
96
- }
97
- L1JSONVarSubWithComments_1.validate();
86
+ exports.runL1JsonVarSubV2Tests = runL1JsonVarSubV2Tests;