Skip to content

Commit a90d06d

Browse files
[TEST] Fix version handler issue
1 parent 7219f94 commit a90d06d

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

src/Request/Init.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ private function deriveAction(): string
261261

262262
// Remove version information from the path
263263
// (e.g., /v2023.1.lts/itembank/items -> /itembank/items, /v1/sessions -> /sessions, /developer/items -> /items)
264-
$path = preg_replace('/\/(v\d+(\.\d+)*(\.[a-zA-Z]+)?|latest(-lts)?|developer)/', '', $path);
264+
// Supports: v1, v1.85.0, v2023.1.lts, v2025.3.LTS, v2022.3.preview1, latest, latest-lts, developer
265+
$path = preg_replace('/\/(v\d+(\.\d+)*(\.[a-zA-Z0-9]+)?|latest(-lts)?|developer)/', '', $path);
265266

266267
// Ensure path starts with /
267268
if (!empty($path) && $path[0] !== '/') {

tests/Request/InitTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,84 @@ public function testDataApiActionMetadata()
307307
'endpoint' => 'https://data.learnosity.com/v2023.1.lts/session_scores',
308308
'action' => null, // should default to 'get'
309309
'expected' => 'get_/session_scores'
310+
],
311+
// Test uppercase LTS
312+
[
313+
'endpoint' => 'https://data.learnosity.com/v2025.3.LTS/itembank/items',
314+
'action' => 'get',
315+
'expected' => 'get_/itembank/items'
316+
],
317+
// Test v2025.2.LTS
318+
[
319+
'endpoint' => 'https://data.learnosity.com/v2025.2.LTS/sessions',
320+
'action' => 'get',
321+
'expected' => 'get_/sessions'
322+
],
323+
// Test simple v1
324+
[
325+
'endpoint' => 'https://data.learnosity.com/v1/items',
326+
'action' => 'get',
327+
'expected' => 'get_/items'
328+
],
329+
// Test v1.85.0
330+
[
331+
'endpoint' => 'https://data.learnosity.com/v1.85.0/itembank/items',
332+
'action' => 'get',
333+
'expected' => 'get_/itembank/items'
334+
],
335+
// Test latest
336+
[
337+
'endpoint' => 'https://data.learnosity.com/latest/itembank/items',
338+
'action' => 'get',
339+
'expected' => 'get_/itembank/items'
340+
],
341+
// Test latest-lts
342+
[
343+
'endpoint' => 'https://data.learnosity.com/latest-lts/sessions',
344+
'action' => 'get',
345+
'expected' => 'get_/sessions'
346+
],
347+
// Test developer
348+
[
349+
'endpoint' => 'https://data.learnosity.com/developer/items',
350+
'action' => 'get',
351+
'expected' => 'get_/items'
352+
],
353+
// Test preview1 (alphanumeric suffix)
354+
[
355+
'endpoint' => 'https://data.learnosity.com/v2022.3.preview1/items',
356+
'action' => 'get',
357+
'expected' => 'get_/items'
358+
],
359+
// Test preview2
360+
[
361+
'endpoint' => 'https://data.learnosity.com/v2022.2.preview2/sessions',
362+
'action' => 'get',
363+
'expected' => 'get_/sessions'
364+
],
365+
// Test beta2
366+
[
367+
'endpoint' => 'https://data.learnosity.com/v1.2.3.beta2/test',
368+
'action' => 'get',
369+
'expected' => 'get_/test'
370+
],
371+
// Test alpha1
372+
[
373+
'endpoint' => 'https://data.learnosity.com/v2024.1.alpha1/items',
374+
'action' => 'get',
375+
'expected' => 'get_/items'
376+
],
377+
// Test URL with no version
378+
[
379+
'endpoint' => 'https://data.learnosity.com/items',
380+
'action' => 'get',
381+
'expected' => 'get_/items'
382+
],
383+
// Test false positive: path starting with 'v' but not a version
384+
[
385+
'endpoint' => 'https://data.learnosity.com/validate/items',
386+
'action' => 'get',
387+
'expected' => 'get_/validate/items'
310388
]
311389
];
312390

0 commit comments

Comments
 (0)