@workos/oagen-emitters 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { parsePathTemplate, hasPathParams } from '../../src/shared/path-template.js';
3
+
4
+ describe('parsePathTemplate', () => {
5
+ it('splits a path with a single param', () => {
6
+ expect(parsePathTemplate('/orgs/{id}')).toEqual([
7
+ { kind: 'literal', value: '/orgs/' },
8
+ { kind: 'param', name: 'id' },
9
+ ]);
10
+ });
11
+
12
+ it('splits a path with multiple params', () => {
13
+ expect(parsePathTemplate('/orgs/{id}/users/{uid}')).toEqual([
14
+ { kind: 'literal', value: '/orgs/' },
15
+ { kind: 'param', name: 'id' },
16
+ { kind: 'literal', value: '/users/' },
17
+ { kind: 'param', name: 'uid' },
18
+ ]);
19
+ });
20
+
21
+ it('handles a path that ends in a param', () => {
22
+ expect(parsePathTemplate('/foo/{id}')).toEqual([
23
+ { kind: 'literal', value: '/foo/' },
24
+ { kind: 'param', name: 'id' },
25
+ ]);
26
+ });
27
+
28
+ it('handles a path that starts with a param', () => {
29
+ expect(parsePathTemplate('{id}/foo')).toEqual([
30
+ { kind: 'param', name: 'id' },
31
+ { kind: 'literal', value: '/foo' },
32
+ ]);
33
+ });
34
+
35
+ it('returns a single literal segment for paths with no params', () => {
36
+ expect(parsePathTemplate('/health')).toEqual([{ kind: 'literal', value: '/health' }]);
37
+ });
38
+
39
+ it('returns empty for an empty string', () => {
40
+ expect(parsePathTemplate('')).toEqual([]);
41
+ });
42
+
43
+ it('strips a single leading slash when requested', () => {
44
+ expect(parsePathTemplate('/orgs/{id}', { stripLeadingSlash: true })).toEqual([
45
+ { kind: 'literal', value: 'orgs/' },
46
+ { kind: 'param', name: 'id' },
47
+ ]);
48
+ });
49
+
50
+ it('preserves snake_case param names verbatim', () => {
51
+ expect(parsePathTemplate('/audit_logs/exports/{audit_log_export_id}')).toEqual([
52
+ { kind: 'literal', value: '/audit_logs/exports/' },
53
+ { kind: 'param', name: 'audit_log_export_id' },
54
+ ]);
55
+ });
56
+ });
57
+
58
+ describe('hasPathParams', () => {
59
+ it('returns true when any segment is a param', () => {
60
+ expect(hasPathParams(parsePathTemplate('/orgs/{id}'))).toBe(true);
61
+ });
62
+
63
+ it('returns false for paths with no params', () => {
64
+ expect(hasPathParams(parsePathTemplate('/health'))).toBe(false);
65
+ });
66
+
67
+ it('returns false for empty paths', () => {
68
+ expect(hasPathParams(parsePathTemplate(''))).toBe(false);
69
+ });
70
+ });