Files
simstudioai--sim/apps/sim/tools/google_appsheet/utils.test.ts
T
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

51 lines
1.7 KiB
TypeScript

/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest'
import { buildAppsheetActionUrl, readAppsheetResponseBody } from '@/tools/google_appsheet/utils'
describe('buildAppsheetActionUrl', () => {
it('defaults to the global www region when unset', () => {
expect(buildAppsheetActionUrl('app-1', 'Orders')).toBe(
'https://www.appsheet.com/api/v2/apps/app-1/tables/Orders/Action'
)
})
it('builds the URL for a valid non-default region', () => {
expect(buildAppsheetActionUrl('app-1', 'Orders', 'eu')).toBe(
'https://eu.appsheet.com/api/v2/apps/app-1/tables/Orders/Action'
)
})
it('trims and URL-encodes appId and tableName', () => {
expect(buildAppsheetActionUrl(' app 1 ', ' My Table ')).toBe(
'https://www.appsheet.com/api/v2/apps/app%201/tables/My%20Table/Action'
)
})
it('rejects a region outside the known AppSheet regions', () => {
expect(() => buildAppsheetActionUrl('app-1', 'Orders', 'attacker.example.com')).toThrow(
/Invalid AppSheet region/
)
})
})
describe('readAppsheetResponseBody', () => {
it('parses a JSON body', async () => {
const response = new Response('{"Rows":[{"id":"1"}]}')
expect(await readAppsheetResponseBody(response)).toEqual({ Rows: [{ id: '1' }] })
})
it('returns an empty object for an empty body', async () => {
const response = new Response('')
expect(await readAppsheetResponseBody(response)).toEqual({})
})
it('wraps a non-JSON body as a message instead of throwing', async () => {
const response = new Response('<html>502 Bad Gateway</html>')
expect(await readAppsheetResponseBody(response)).toEqual({
message: '<html>502 Bad Gateway</html>',
})
})
})