Skip to content

Commit 0e58ba0

Browse files
committed
test: update tests for new template structure
- Add tests for new placeholder replacements - Add tests for template structure with collapsible sections - Add tests for TemplateSectionCleaner with <details> blocks - Update existing tests to match new template format - Remove trace_id related tests
1 parent d2bc86a commit 0e58ba0

File tree

6 files changed

+303
-26
lines changed

6 files changed

+303
-26
lines changed

tests/Issues/Formatters/IssueFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
expect($formatted)
1616
->toBeInstanceOf(Formatted::class)
1717
->and($formatted->title)->toContain('[ERROR] Test error message')
18-
->and($formatted->body)->toContain('**Log Level:** ERROR')
18+
->and($formatted->body)->toContain('**Level:** ERROR')
1919
->and($formatted->body)->toContain('Test error message');
2020
});
2121

@@ -29,7 +29,7 @@
2929
->toContain('.php:')
3030
->and($formatted->body)
3131
->toContain('Test exception')
32-
->toContain('Stack Trace');
32+
->toContain('<summary>📋 Stack Trace</summary>');
3333
});
3434

3535
test('it truncates long titles', function () {

tests/Issues/TemplateRendererContextTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
// Assert - Context section should exist and contain the data
3838
// Note: The section cleaner removes empty sections, so if context exists, the section should be present
39-
expect($rendered)->toContain('## Context');
39+
expect($rendered)->toContain('<summary>📦 Context</summary>');
4040

4141
// Extract context section (it might be cleaned if empty, so check if it exists first)
4242
if (preg_match('/<!-- context:start -->(.*?)<!-- context:end -->/s', $rendered, $contextMatches)) {
@@ -92,7 +92,7 @@
9292
}
9393

9494
// Verify user data IS in User section (not context section, as it's now in its own section)
95-
expect($rendered)->toContain('## User');
95+
expect($rendered)->toContain('<summary>👤 User Details</summary>');
9696
// User data should be present in the rendered output
9797
expect($rendered)->toContain('456');
9898
});

tests/Issues/TemplateRendererNewSectionsTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
3030

3131
expect($rendered)
32-
->toContain('## Environment')
32+
->toContain('<summary>🌍 Environment</summary>')
3333
->toContain('"app_env": "testing"')
3434
->toContain('"laravel_version": "11.0.0"')
3535
->toContain('"php_version": "8.2.0"');
@@ -53,7 +53,7 @@
5353
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
5454

5555
expect($rendered)
56-
->toContain('## Request')
56+
->toContain('<summary>📥 Request</summary>')
5757
->toContain('example.com')
5858
->toContain('"method": "POST"');
5959
});
@@ -72,7 +72,7 @@
7272
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
7373

7474
expect($rendered)
75-
->toContain('## Route')
75+
->toContain('<summary>🛣️ Route Details</summary>')
7676
->toContain('users.show')
7777
->toContain('UserController@show')
7878
->toContain('middleware');
@@ -91,7 +91,7 @@
9191
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
9292

9393
expect($rendered)
94-
->toContain('## User')
94+
->toContain('<summary>👤 User Details</summary>')
9595
->toContain('"id": 123')
9696
->toContain('"email": "user@example.com"')
9797
->toContain('"authenticated": true');
@@ -113,7 +113,7 @@
113113
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
114114

115115
expect($rendered)
116-
->toContain('## Recent Queries')
116+
->toContain('<summary>🗄️ Recent Queries</summary>')
117117
->toContain('SELECT * FROM users WHERE id = ?')
118118
->toContain('mysql')
119119
->toContain('10.5');
@@ -132,7 +132,7 @@
132132
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
133133

134134
expect($rendered)
135-
->toContain('## Job Context')
135+
->toContain('<summary>⚙️ Job Context</summary>')
136136
->toContain('ProcessOrder')
137137
->toContain('default')
138138
->toContain('2');
@@ -151,7 +151,7 @@
151151
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
152152

153153
expect($rendered)
154-
->toContain('## Command Context')
154+
->toContain('<summary>💻 Command Context</summary>')
155155
->toContain('"name": "test:command"')
156156
->toContain('"arguments"')
157157
->toContain('"options"');
@@ -173,7 +173,7 @@
173173
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
174174

175175
expect($rendered)
176-
->toContain('## Outgoing Requests')
176+
->toContain('<summary>📤 Outgoing Requests</summary>')
177177
->toContain('GET https://api.example.com/test')
178178
->toContain('200')
179179
->toContain('150.5');
@@ -191,7 +191,7 @@
191191
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
192192

193193
expect($rendered)
194-
->toContain('## Session')
194+
->toContain('<summary>🔐 Session</summary>')
195195
->toContain('"data"')
196196
->toContain('"flash"');
197197
});

tests/Issues/TemplateRendererRouteTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757

5858
// Assert
5959
expect($rendered)
60-
->toContain('## Request')
61-
->toContain('## Route')
60+
->toContain('<summary>📥 Request</summary>')
61+
->toContain('<summary>🛣️ Route Details</summary>')
6262
->toContain('"name": "api.users.index"')
6363
->toContain('"url"')
6464
->toContain('"method": "GET"');
@@ -100,9 +100,9 @@
100100

101101
// Assert - All should be in their respective sections
102102
expect($rendered)
103-
->toContain('## User')
104-
->toContain('## Request')
105-
->toContain('## Route')
103+
->toContain('<summary>👤 User Details</summary>')
104+
->toContain('<summary>📥 Request</summary>')
105+
->toContain('<summary>🛣️ Route Details</summary>')
106106
->toContain('"id": 123')
107107
->toContain('"email": "user@example.com"')
108108
->toContain('"name": "api.posts.store"')

tests/Issues/TemplateRendererTest.php

Lines changed: 200 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
1515

1616
expect($rendered)
17-
->toContain('**Log Level:** ERROR')
18-
->toContain('**Message:** Test message');
17+
->toContain('**Level:** ERROR')
18+
->toContain('**Message:** Test message')
19+
->toContain('## Triage Information');
1920
});
2021

2122
test('it renders title without exception', function () {
@@ -40,7 +41,7 @@
4041
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
4142

4243
expect($rendered)
43-
->toContain('## Context')
44+
->toContain('<summary>📦 Context</summary>')
4445
->toContain('"user_id": 123');
4546
});
4647

@@ -50,7 +51,7 @@
5051
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
5152

5253
expect($rendered)
53-
->toContain('## Extra Data')
54+
->toContain('<summary>➕ Extra Data</summary>')
5455
->toContain('"request_id": "abc123"');
5556
});
5657

@@ -119,14 +120,205 @@
119120
->not->toContain('Stack trace:')
120121
->not->toContain('#0 /path/to/app/Services/PaymentService.php');
121122

122-
// Should have class populated (even if generic)
123+
// Should have exception class populated (even if generic)
123124
expect($rendered)
124-
->toContain('**Class:**')
125-
->toMatch('/\*\*Class:\*\* .+/'); // Class should have a value
125+
->toContain('**Exception:**')
126+
->toMatch('/\*\*Exception:\*\* .+/'); // Exception should have a value
126127

127128
// Should have stack traces populated
128129
expect($rendered)
129-
->toContain('## Stack Trace')
130+
->toContain('<summary>📋 Stack Trace</summary>')
130131
->toContain('[stacktrace]')
131132
->toContain('App\\Calculations\\Calculator->calculate()');
132133
});
134+
135+
test('it formats timestamp placeholder correctly', function () {
136+
$record = createLogRecord('Test message');
137+
138+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
139+
140+
expect($rendered)
141+
->toContain('**Timestamp:**')
142+
->toMatch('/\*\*Timestamp:\*\* \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/');
143+
});
144+
145+
test('it formats route summary as method and path', function () {
146+
$record = createLogRecord('Test message', [
147+
'request' => [
148+
'method' => 'POST',
149+
'url' => 'https://example.com/api/users',
150+
],
151+
]);
152+
153+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
154+
155+
expect($rendered)
156+
->toContain('**Route:** POST /api/users');
157+
});
158+
159+
test('it returns empty string for route summary when request data is missing', function () {
160+
$record = createLogRecord('Test message');
161+
162+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
163+
164+
expect($rendered)
165+
->toContain('**Route:**');
166+
});
167+
168+
test('it formats user summary with user id', function () {
169+
$record = createLogRecord('Test message', [
170+
'user' => [
171+
'id' => 123,
172+
],
173+
]);
174+
175+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
176+
177+
expect($rendered)
178+
->toContain('**User:** User ID: 123');
179+
});
180+
181+
test('it formats user summary as unauthenticated when user data is missing', function () {
182+
$record = createLogRecord('Test message');
183+
184+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
185+
186+
expect($rendered)
187+
->toContain('**User:** Unauthenticated');
188+
});
189+
190+
test('it formats user summary as unauthenticated when user id is missing', function () {
191+
$record = createLogRecord('Test message', [
192+
'user' => [
193+
'name' => 'John Doe',
194+
],
195+
]);
196+
197+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
198+
199+
expect($rendered)
200+
->toContain('**User:** Unauthenticated');
201+
});
202+
203+
test('it extracts environment name from environment context', function () {
204+
$record = createLogRecord('Test message', [
205+
'environment' => [
206+
'APP_ENV' => 'production',
207+
],
208+
]);
209+
210+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
211+
212+
expect($rendered)
213+
->toContain('**Environment:** production');
214+
});
215+
216+
test('it extracts environment name from lowercase app_env key', function () {
217+
$record = createLogRecord('Test message', [
218+
'environment' => [
219+
'app_env' => 'staging',
220+
],
221+
]);
222+
223+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
224+
225+
expect($rendered)
226+
->toContain('**Environment:** staging');
227+
});
228+
229+
test('it returns empty string for environment name when not available', function () {
230+
$record = createLogRecord('Test message');
231+
232+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
233+
234+
expect($rendered)
235+
->toContain('**Environment:**');
236+
});
237+
238+
test('issue template renders triage header with all fields', function () {
239+
$record = createLogRecord('Test message', [
240+
'request' => [
241+
'method' => 'GET',
242+
'url' => 'https://example.com/test',
243+
'headers' => ['X-Request-ID' => 'test123'],
244+
],
245+
'user' => ['id' => 456],
246+
'environment' => ['APP_ENV' => 'testing'],
247+
]);
248+
249+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record, 'sig123');
250+
251+
expect($rendered)
252+
->toContain('## Triage Information')
253+
->toContain('**Level:** ERROR')
254+
->toContain('**Exception:**')
255+
->toContain('**Signature:** sig123')
256+
->toContain('**Timestamp:**')
257+
->toContain('**Environment:** testing')
258+
->toContain('**Route:** GET /test')
259+
->toContain('**User:** User ID: 456')
260+
->toContain('**Message:** Test message');
261+
});
262+
263+
test('issue template wraps verbose sections in details blocks', function () {
264+
$record = createLogRecord('Test message', [
265+
'environment' => ['APP_ENV' => 'testing'],
266+
'request' => ['method' => 'GET', 'url' => 'https://example.com'],
267+
'user' => ['id' => 123],
268+
'custom_context' => 'test',
269+
], extra: ['extra_key' => 'extra_value']);
270+
271+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record);
272+
273+
expect($rendered)
274+
->toContain('<details>')
275+
->toContain('<summary>🌍 Environment</summary>')
276+
->toContain('<summary>📥 Request</summary>')
277+
->toContain('<summary>👤 User Details</summary>')
278+
->toContain('<summary>📦 Context</summary>')
279+
->toContain('<summary>➕ Extra Data</summary>');
280+
});
281+
282+
test('comment template always includes request section', function () {
283+
$record = createLogRecord('Test message', [
284+
'request' => [
285+
'method' => 'POST',
286+
'url' => 'https://example.com/api',
287+
'headers' => ['X-Request-ID' => 'req456'],
288+
],
289+
]);
290+
291+
$rendered = $this->renderer->render($this->stubLoader->load('comment'), $record);
292+
293+
expect($rendered)
294+
->toContain('<summary>📥 Request</summary>')
295+
->toContain('**Route:** POST /api');
296+
});
297+
298+
test('comment template does not include environment section', function () {
299+
$record = createLogRecord('Test message', [
300+
'environment' => ['APP_ENV' => 'production'],
301+
]);
302+
303+
$rendered = $this->renderer->render($this->stubLoader->load('comment'), $record);
304+
305+
expect($rendered)
306+
->not->toContain('<summary>🌍 Environment</summary>')
307+
->not->toContain('<!-- environment:start -->');
308+
});
309+
310+
test('triage header renders correctly with missing optional data', function () {
311+
$record = createLogRecord('Test message');
312+
313+
$rendered = $this->renderer->render($this->stubLoader->load('issue'), $record, 'sig789');
314+
315+
expect($rendered)
316+
->toContain('## Triage Information')
317+
->toContain('**Level:** ERROR')
318+
->toContain('**Signature:** sig789')
319+
->toContain('**Timestamp:**')
320+
->toContain('**Environment:**')
321+
->toContain('**Route:**')
322+
->toContain('**User:** Unauthenticated')
323+
->toContain('**Message:** Test message');
324+
});

0 commit comments

Comments
 (0)