|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | | -import { extractServerFunctionSha256 } from '../../src/server/utils'; |
| 2 | +import { getMiddlewareSpanOptions } from '../../src/server/utils'; |
3 | 3 |
|
4 | | -describe('extractServerFunctionSha256', () => { |
5 | | - it('extracts SHA256 hash from valid server function pathname', () => { |
6 | | - const pathname = '/_serverFn/1ac31c23f613ec7e58631cf789642e2feb86c58e3128324cf00d746474a044bf'; |
7 | | - const result = extractServerFunctionSha256(pathname); |
8 | | - expect(result).toBe('1ac31c23f613ec7e58631cf789642e2feb86c58e3128324cf00d746474a044bf'); |
9 | | - }); |
10 | | - |
11 | | - it('extracts SHA256 hash from valid server function pathname that is a subpath', () => { |
12 | | - const pathname = '/api/_serverFn/1ac31c23f613ec7e58631cf789642e2feb86c58e3128324cf00d746474a044bf'; |
13 | | - const result = extractServerFunctionSha256(pathname); |
14 | | - expect(result).toBe('1ac31c23f613ec7e58631cf789642e2feb86c58e3128324cf00d746474a044bf'); |
15 | | - }); |
16 | | - |
17 | | - it('extracts SHA256 hash from valid server function pathname with query parameters', () => { |
18 | | - const pathname = '/_serverFn/1ac31c23f613ec7e58631cf789642e2feb86c58e3128324cf00d746474a044bf?param=value'; |
19 | | - const result = extractServerFunctionSha256(pathname); |
20 | | - expect(result).toBe('1ac31c23f613ec7e58631cf789642e2feb86c58e3128324cf00d746474a044bf'); |
21 | | - }); |
22 | | - |
23 | | - it('extracts SHA256 hash with uppercase hex characters', () => { |
24 | | - const pathname = '/_serverFn/1AC31C23F613EC7E58631CF789642E2FEB86C58E3128324CF00D746474A044BF'; |
25 | | - const result = extractServerFunctionSha256(pathname); |
26 | | - expect(result).toBe('1AC31C23F613EC7E58631CF789642E2FEB86C58E3128324CF00D746474A044BF'); |
27 | | - }); |
28 | | - |
29 | | - it('returns unknown for pathname without server function pattern', () => { |
30 | | - const pathname = '/api/users/123'; |
31 | | - const result = extractServerFunctionSha256(pathname); |
32 | | - expect(result).toBe('unknown'); |
33 | | - }); |
34 | | - |
35 | | - it('returns unknown for pathname with incomplete hash', () => { |
36 | | - // Hash is too short (only 32 chars instead of 64) |
37 | | - const pathname = '/_serverFn/1ac31c23f613ec7e58631cf789642e2f'; |
38 | | - const result = extractServerFunctionSha256(pathname); |
39 | | - expect(result).toBe('unknown'); |
| 4 | +describe('getMiddlewareSpanOptions', () => { |
| 5 | + it('returns correct span options', () => { |
| 6 | + const options = getMiddlewareSpanOptions('testMiddleware'); |
| 7 | + expect(options).toEqual({ |
| 8 | + op: 'middleware.tanstackstart', |
| 9 | + name: 'testMiddleware', |
| 10 | + attributes: { |
| 11 | + 'sentry.op': 'middleware.tanstackstart', |
| 12 | + 'sentry.origin': 'auto.middleware.tanstackstart', |
| 13 | + }, |
| 14 | + }); |
40 | 15 | }); |
41 | 16 | }); |
0 commit comments