-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathrender-serverlogic-plan.test.js
More file actions
120 lines (115 loc) · 4.16 KB
/
Copy pathrender-serverlogic-plan.test.js
File metadata and controls
120 lines (115 loc) · 4.16 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
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
test('render-serverlogic-plan renders HTML from JSON data', () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'serverlogic-plan-'));
const dataPath = path.join(tempDir, 'data.json');
const outputPath = path.join(tempDir, 'serverlogic-plan.html');
const scriptPath = path.join(
__dirname,
'..',
'render-serverlogic-plan.js'
);
fs.writeFileSync(
dataPath,
JSON.stringify(
{
SITE_NAME: 'Contoso Portal',
PLAN_TITLE: 'Server Logic Plan',
SUMMARY: 'Create multiple server logic items for the support portal while keeping role assignment and function design visible in one reviewable plan.',
WEB_ROLES_DATA: [
{
id: 'authenticated-users',
name: 'Authenticated Users',
desc: 'Built-in role for signed-in users.',
builtin: true,
isNew: false,
color: '#8890a4',
},
{
id: 'support-managers',
name: 'Support Managers',
desc: 'Custom role for elevated support dashboards.',
builtin: false,
isNew: true,
color: '#4a7ce8',
},
],
SERVER_LOGICS_DATA: [
{
id: 'dashboard-summary',
name: 'dashboard-summary',
displayName: 'Dashboard Summary',
status: 'create',
apiUrl: 'https://contoso.powerappsportals.com/_api/serverlogics/dashboard-summary',
webRoles: [
{
id: 'authenticated-users',
reasoning: 'Authenticated users need the dashboard because it surfaces their assigned work and queue metrics.',
},
{
id: 'support-managers',
reasoning: 'Support managers need the same endpoint to review queue-wide workload and escalations.',
},
],
rationale: 'This endpoint centralizes support dashboard aggregation on the server.',
functions: [
{
name: 'get',
purpose: 'Return dashboard summary data',
reasoning: 'The dashboard only reads data, so GET is the right fit.',
},
],
},
{
id: 'case-export',
name: 'case-export',
displayName: 'Case Export',
status: 'reuse',
apiUrl: 'https://contoso.powerappsportals.com/_api/serverlogics/case-export',
webRoles: [
{
id: 'support-managers',
reasoning: 'Only support managers should initiate exports because the payload includes sensitive case data.',
},
],
rationale: 'This existing endpoint is being reused as-is for the export workflow.',
functions: [
{
name: 'post',
purpose: 'Start export job',
reasoning: 'Export initiation changes state, so POST is required.',
},
],
},
],
RATIONALE_DATA: [
{
icon: '🛡️',
title: 'Why this structure',
desc: 'The plan separates reusable endpoints from newly proposed endpoints so review can focus on real changes.',
},
],
},
null,
2
),
'utf8'
);
const result = spawnSync(process.execPath, [scriptPath, '--output', outputPath, '--data', dataPath], {
encoding: 'utf8',
});
assert.equal(result.status, 0, result.stderr || result.stdout);
assert.ok(fs.existsSync(outputPath));
const html = fs.readFileSync(outputPath, 'utf8');
assert.match(html, /Contoso Portal/);
assert.match(html, /dashboard-summary/);
assert.match(html, /Authenticated Users/);
assert.match(html, /Support Managers/);
assert.match(html, /Case Export/);
assert.match(html, /assigned work and queue metrics/);
assert.match(html, /Export initiation changes state/);
});