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
91 lines
3.1 KiB
TypeScript
91 lines
3.1 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import { parseGraphErrorMessage } from '@/tools/microsoft_excel/utils'
|
|
|
|
describe('parseGraphErrorMessage', () => {
|
|
it('extracts top-level error.message', () => {
|
|
const body = JSON.stringify({
|
|
error: { code: 'badRequest', message: 'Uploaded fragment overlaps with existing data.' },
|
|
})
|
|
expect(parseGraphErrorMessage(400, 'Bad Request', body)).toBe(
|
|
'Uploaded fragment overlaps with existing data.'
|
|
)
|
|
})
|
|
|
|
it('combines top-level and innerError messages with em-dash separator', () => {
|
|
const body = JSON.stringify({
|
|
error: {
|
|
code: 'invalidRequest',
|
|
message: 'The request is invalid.',
|
|
innerError: { code: 'invalidRange', message: 'Range A1:Z9999 is out of bounds.' },
|
|
},
|
|
})
|
|
expect(parseGraphErrorMessage(400, 'Bad Request', body)).toBe(
|
|
'The request is invalid. — Range A1:Z9999 is out of bounds.'
|
|
)
|
|
})
|
|
|
|
it('walks nested innerError chain (lowercase spec form)', () => {
|
|
const body = JSON.stringify({
|
|
error: {
|
|
message: 'Outer message.',
|
|
innererror: {
|
|
message: 'Middle message.',
|
|
innererror: { message: 'Innermost message.' },
|
|
},
|
|
},
|
|
})
|
|
expect(parseGraphErrorMessage(500, 'Internal Server Error', body)).toBe(
|
|
'Outer message. — Middle message. — Innermost message.'
|
|
)
|
|
})
|
|
|
|
it('appends details[].message entries', () => {
|
|
const body = JSON.stringify({
|
|
error: {
|
|
message: 'Multiple problems.',
|
|
details: [{ message: 'Cell A1 invalid.' }, { message: 'Cell B2 invalid.' }],
|
|
},
|
|
})
|
|
expect(parseGraphErrorMessage(400, 'Bad Request', body)).toBe(
|
|
'Multiple problems. — Cell A1 invalid. — Cell B2 invalid.'
|
|
)
|
|
})
|
|
|
|
it('falls back to error.code when no messages present', () => {
|
|
const body = JSON.stringify({ error: { code: 'itemNotFound' } })
|
|
expect(parseGraphErrorMessage(404, 'Not Found', body)).toBe('itemNotFound (404 Not Found)')
|
|
})
|
|
|
|
it('returns raw text when body is not JSON', () => {
|
|
expect(parseGraphErrorMessage(502, 'Bad Gateway', 'upstream timeout')).toBe('upstream timeout')
|
|
})
|
|
|
|
it('falls back to status text when body is empty', () => {
|
|
expect(parseGraphErrorMessage(503, 'Service Unavailable', '')).toBe('503 Service Unavailable')
|
|
})
|
|
|
|
it('handles deeply nested chain without infinite loop', () => {
|
|
let nested: Record<string, unknown> = { message: 'leaf' }
|
|
for (let i = 0; i < 50; i++) {
|
|
nested = { message: `level-${i}`, innerError: nested }
|
|
}
|
|
const body = JSON.stringify({ error: nested })
|
|
const result = parseGraphErrorMessage(500, 'Internal Server Error', body)
|
|
// Should include outer plus capped nested messages, not blow up.
|
|
expect(result.startsWith('level-49')).toBe(true)
|
|
})
|
|
|
|
it('deduplicates identical inner messages', () => {
|
|
const body = JSON.stringify({
|
|
error: {
|
|
message: 'Same message.',
|
|
innerError: { message: 'Same message.' },
|
|
},
|
|
})
|
|
expect(parseGraphErrorMessage(400, 'Bad Request', body)).toBe('Same message.')
|
|
})
|
|
})
|