Skip to content

Commit e5f31b2

Browse files
Copilotd-gubert
authored andcommitted
chore: convert Utilities test from Alsatian to NodeJS (#37683)
1 parent 7bf9ca1 commit e5f31b2

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import * as assert from 'node:assert';
2+
import { describe, it } from 'node:test';
3+
4+
import { Utilities } from '../../../../src/server/misc/Utilities';
5+
6+
describe('Utilities', () => {
7+
const expectedInfo = {
8+
id: '614055e2-3dba-41fb-be48-c1ff146f5932',
9+
name: 'Testing App',
10+
nameSlug: 'testing-app',
11+
description: 'A Rocket.Chat Application used to test out the various features.',
12+
version: '0.0.8',
13+
requiredApiVersion: '>=0.9.6',
14+
author: {
15+
name: 'Bradley Hilton',
16+
homepage: 'https://github.com/RocketChat/Rocket.Chat.Apps-ts-definitions',
17+
support: 'https://github.com/RocketChat/Rocket.Chat.Apps-ts-definitions/issues',
18+
},
19+
classFile: 'TestingApp.ts',
20+
iconFile: 'testing.jpg',
21+
};
22+
23+
it('testDeepClone', () => {
24+
assert.doesNotThrow(() => Utilities.deepClone(expectedInfo));
25+
const info = Utilities.deepClone(expectedInfo);
26+
27+
assert.deepStrictEqual(info, expectedInfo);
28+
info.name = 'New Testing App';
29+
assert.strictEqual(info.name, 'New Testing App');
30+
assert.strictEqual(info.author.name, expectedInfo.author.name);
31+
});
32+
33+
it('testDeepFreeze', () => {
34+
const testInfo = {
35+
id: '614055e2-3dba-41fb-be48-c1ff146f5932',
36+
name: 'Testing App',
37+
nameSlug: 'testing-app',
38+
description: 'A Rocket.Chat Application used to test out the various features.',
39+
version: '0.0.8',
40+
requiredApiVersion: '>=0.9.6',
41+
author: {
42+
name: 'Bradley Hilton',
43+
homepage: 'https://github.com/RocketChat/Rocket.Chat.Apps-ts-definitions',
44+
support: 'https://github.com/RocketChat/Rocket.Chat.Apps-ts-definitions/issues',
45+
},
46+
classFile: 'TestingApp.ts',
47+
iconFile: 'testing.jpg',
48+
};
49+
50+
assert.doesNotThrow(() => {
51+
testInfo.name = 'New Testing App';
52+
});
53+
assert.doesNotThrow(() => {
54+
testInfo.author.name = 'Bradley H';
55+
});
56+
assert.strictEqual(testInfo.name, 'New Testing App');
57+
assert.strictEqual(testInfo.author.name, 'Bradley H');
58+
59+
assert.doesNotThrow(() => Utilities.deepFreeze(testInfo));
60+
61+
assert.throws(() => {
62+
testInfo.name = 'Old Testing App';
63+
});
64+
assert.throws(() => {
65+
testInfo.author.name = 'Bradley';
66+
});
67+
assert.strictEqual(testInfo.name, 'New Testing App');
68+
assert.strictEqual(testInfo.author.name, 'Bradley H');
69+
});
70+
71+
it('testDeepCloneAndFreeze', () => {
72+
const testInfo = {
73+
id: '614055e2-3dba-41fb-be48-c1ff146f5932',
74+
name: 'Testing App',
75+
nameSlug: 'testing-app',
76+
description: 'A Rocket.Chat Application used to test out the various features.',
77+
version: '0.0.8',
78+
requiredApiVersion: '>=0.9.6',
79+
author: {
80+
name: 'Bradley H',
81+
homepage: 'https://github.com/RocketChat/Rocket.Chat.Apps-ts-definitions',
82+
support: 'https://github.com/RocketChat/Rocket.Chat.Apps-ts-definitions/issues',
83+
},
84+
classFile: 'TestingApp.ts',
85+
iconFile: 'testing.jpg',
86+
};
87+
88+
assert.doesNotThrow(() => Utilities.deepCloneAndFreeze({}));
89+
90+
const info = Utilities.deepCloneAndFreeze(testInfo);
91+
assert.deepStrictEqual(info, testInfo);
92+
assert.notStrictEqual(info, testInfo);
93+
assert.strictEqual(info.author.name, testInfo.author.name);
94+
assert.strictEqual(info.author.name, 'Bradley H');
95+
assert.throws(() => {
96+
info.author.name = 'Bradley Hilton';
97+
});
98+
});
99+
});

0 commit comments

Comments
 (0)