d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
111 lines
3.8 KiB
TypeScript
111 lines
3.8 KiB
TypeScript
import { beforeAll, describe, expect, it } from 'vitest'
|
|
import { requestTool } from '@/tools/http/request'
|
|
import type { RequestParams } from '@/tools/http/types'
|
|
|
|
beforeAll(() => {
|
|
process.env.NEXT_PUBLIC_APP_URL = 'http://localhost:3000'
|
|
})
|
|
|
|
describe('HTTP Request Tool - Stringified Params Fix', () => {
|
|
it('should handle stringified params from UI storage', () => {
|
|
const stringifiedParams = JSON.stringify([
|
|
{ id: 'test-1', cells: { Key: 'id', Value: '311861947611' } },
|
|
{ id: 'test-2', cells: { Key: 'language', Value: 'tr' } },
|
|
])
|
|
|
|
const stringifiedHeaders = JSON.stringify([
|
|
{ id: 'test-3', cells: { Key: 'Authorization', Value: 'Bearer token' } },
|
|
])
|
|
|
|
const params = {
|
|
url: 'https://api.example.com/tracking',
|
|
method: 'GET' as const,
|
|
params: stringifiedParams,
|
|
headers: stringifiedHeaders,
|
|
}
|
|
|
|
const url = (requestTool.request.url as (params: RequestParams) => string)(params)
|
|
expect(url).toBe('https://api.example.com/tracking?id=311861947611&language=tr')
|
|
|
|
const headers = (
|
|
requestTool.request.headers as (params: RequestParams) => Record<string, string>
|
|
)(params)
|
|
expect(headers.Authorization).toBe('Bearer token')
|
|
})
|
|
|
|
it('should still handle normal array params', () => {
|
|
const params = {
|
|
url: 'https://api.example.com/tracking',
|
|
method: 'GET' as const,
|
|
params: [
|
|
{ id: 'test-1', cells: { Key: 'id', Value: '311861947611' } },
|
|
{ id: 'test-2', cells: { Key: 'language', Value: 'tr' } },
|
|
],
|
|
headers: [{ id: 'test-3', cells: { Key: 'Authorization', Value: 'Bearer token' } }],
|
|
}
|
|
|
|
const url = (requestTool.request.url as (params: RequestParams) => string)(params)
|
|
expect(url).toBe('https://api.example.com/tracking?id=311861947611&language=tr')
|
|
|
|
const headers = (
|
|
requestTool.request.headers as (params: RequestParams) => Record<string, string>
|
|
)(params)
|
|
expect(headers.Authorization).toBe('Bearer token')
|
|
})
|
|
|
|
it('should handle null and undefined params gracefully', () => {
|
|
const params = {
|
|
url: 'https://api.example.com/test',
|
|
method: 'GET' as const,
|
|
}
|
|
|
|
const url = (requestTool.request.url as (params: RequestParams) => string)(params)
|
|
expect(url).toBe('https://api.example.com/test')
|
|
|
|
const headers = (
|
|
requestTool.request.headers as (params: RequestParams) => Record<string, string>
|
|
)(params)
|
|
expect(headers).toBeDefined()
|
|
})
|
|
|
|
it('should handle stringified object params and headers', () => {
|
|
const params = {
|
|
url: 'https://api.example.com/oauth/token',
|
|
method: 'POST' as const,
|
|
body: { grant_type: 'client_credentials' },
|
|
params: JSON.stringify({ q: 'test' }),
|
|
headers: JSON.stringify({ 'Content-Type': 'application/x-www-form-urlencoded' }),
|
|
}
|
|
|
|
const url = (requestTool.request.url as (input: RequestParams) => string)(params)
|
|
expect(url).toBe('https://api.example.com/oauth/token?q=test')
|
|
|
|
const headers = (
|
|
requestTool.request.headers as (input: RequestParams) => Record<string, string>
|
|
)(params)
|
|
expect(headers['Content-Type']).toBe('application/x-www-form-urlencoded')
|
|
|
|
const body = (
|
|
requestTool.request.body as (input: RequestParams) => Record<string, any> | string | FormData
|
|
)(params)
|
|
expect(body).toBe('grant_type=client_credentials')
|
|
})
|
|
|
|
it('should handle invalid JSON strings gracefully', () => {
|
|
const params = {
|
|
url: 'https://api.example.com/test',
|
|
method: 'GET' as const,
|
|
params: 'not-valid-json',
|
|
headers: '{broken',
|
|
}
|
|
|
|
const url = (requestTool.request.url as (input: RequestParams) => string)(params)
|
|
expect(url).toBe('https://api.example.com/test')
|
|
|
|
const headers = (
|
|
requestTool.request.headers as (input: RequestParams) => Record<string, string>
|
|
)(params)
|
|
expect(headers).toBeDefined()
|
|
})
|
|
})
|