-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.test.js
More file actions
63 lines (49 loc) · 1.87 KB
/
code.test.js
File metadata and controls
63 lines (49 loc) · 1.87 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
import { test, describe } from 'node:test';
import assert from 'node:assert';
import { run } from './code.js';
describe('run function', () => {
test('should return an object with required fields', async () => {
const input = { foo: 'bar' };
const result = await run(input);
assert.ok(result.id);
assert.ok(result.timestamp);
assert.ok(result.futureDate);
assert.ok(result.oneWeek);
assert.ok(result.originalInput);
assert.ok(result.processedData);
assert.ok(typeof result.hasChanged === 'boolean');
});
test('should preserve original input', async () => {
const input = { foo: 'bar', number: 42 };
const result = await run(input);
assert.deepStrictEqual(result.originalInput, input);
});
test('should uppercase string values', async () => {
const input = { foo: 'bar', baz: 'qux' };
const result = await run(input);
assert.strictEqual(result.processedData.foo, 'BAR');
assert.strictEqual(result.processedData.baz, 'QUX');
});
test('should preserve non-string values', async () => {
const input = { name: 'test', count: 42, active: true };
const result = await run(input);
assert.strictEqual(result.processedData.count, 42);
assert.strictEqual(result.processedData.active, true);
});
test('should detect changes in processed data', async () => {
const input = { foo: 'bar' };
const result = await run(input);
assert.strictEqual(result.hasChanged, true);
});
test('should return oneWeek as milliseconds', async () => {
const input = {};
const result = await run(input);
assert.strictEqual(result.oneWeek, 604800000); // 7 days in milliseconds
});
test('should generate unique IDs', async () => {
const input = { test: 'data' };
const result1 = await run(input);
const result2 = await run(input);
assert.notStrictEqual(result1.id, result2.id);
});
});