-
Notifications
You must be signed in to change notification settings - Fork 507
Expand file tree
/
Copy pathmakeImmutable-shared-refs.js
More file actions
84 lines (71 loc) · 2.22 KB
/
makeImmutable-shared-refs.js
File metadata and controls
84 lines (71 loc) · 2.22 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
'use strict';
const { describe, it, beforeEach } = require('node:test');
const assert = require('assert');
const util = require('../lib/config.js').util;
/**
* <p>Unit tests for makeImmutable shared reference cases</p>
*
* @module test
*/
describe('Tests for makeImmutable shared reference handling', function() {
describe('makeImmutable with arrays containing shared objects', function() {
let data;
beforeEach(function () {
// Create a object that will get get shared.
const sharedNetworkObject = {
_id: "12345",
name: "Test Network",
capabilities: {
primaryNetwork: true,
}
};
// Pattern where same object appears in multiple arrays within the configuration
data = {
// This simulates scheduled tasks with shared network references
scheduledTasks: [
{
name: 'task1',
options: {
networks: [sharedNetworkObject] // First reference
}
},
{
name: 'task2',
options: {
networks: [sharedNetworkObject] // Same object, second reference!
}
}
]
};
});
it('Should not throw error with shared objects in arrays', function () {
assert.doesNotThrow(function () {
util.makeImmutable(data);
}, /Cannot redefine property/);
});
it('Shared objects in arrays should be immutable', function () {
util.makeImmutable(data);
const firstTask = data.scheduledTasks[0];
assert.throws(function () {
firstTask.options.networks[0].capabilities.primaryNetwork = false;
}, /Can not update runtime configuration property/);
});
});
describe('makeImmutable idempotency', function() {
let data;
beforeEach(function() {
data = {
config: { name: "test" },
capabilities: { setting: true }
};
});
it('Should not throw error when called twice on same object', function() {
// First call
util.makeImmutable(data);
// Second call should not throw "Cannot redefine property"
assert.doesNotThrow(function() {
util.makeImmutable(data);
}, /Cannot redefine property/);
});
});
});