Files
simstudioai--sim/apps/sim/lib/webhooks/polling/hubspot.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

96 lines
3.2 KiB
TypeScript

/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest'
import { buildUserFilters } from '@/lib/webhooks/polling/hubspot'
describe('buildUserFilters', () => {
it('translates pipeline/stage/owner shortcuts into EQ filters', () => {
const filters = buildUserFilters({
objectType: 'deal',
pipelineId: 'pipeline-1',
stageId: 'stage-1',
ownerId: 'owner-1',
})
expect(filters).toEqual([
{ propertyName: 'pipeline', operator: 'EQ', value: 'pipeline-1' },
{ propertyName: 'dealstage', operator: 'EQ', value: 'stage-1' },
{ propertyName: 'hubspot_owner_id', operator: 'EQ', value: 'owner-1' },
])
})
it('uses ticket-specific pipeline/stage property names', () => {
const filters = buildUserFilters({
objectType: 'ticket',
pipelineId: 'pipeline-1',
stageId: 'stage-1',
})
expect(filters).toEqual([
{ propertyName: 'hs_pipeline', operator: 'EQ', value: 'pipeline-1' },
{ propertyName: 'hs_pipeline_stage', operator: 'EQ', value: 'stage-1' },
])
})
it('parses advanced JSON filters and preserves values arrays', () => {
const filters = buildUserFilters({
filters: JSON.stringify([
{ propertyName: 'lifecyclestage', operator: 'EQ', value: 'customer' },
{ propertyName: 'dealstage', operator: 'IN', values: ['a', 'b'] },
]),
})
expect(filters).toEqual([
{ propertyName: 'lifecyclestage', operator: 'EQ', value: 'customer' },
{ propertyName: 'dealstage', operator: 'IN', values: ['a', 'b'] },
])
})
it('drops filter entries with an unrecognized operator', () => {
const filters = buildUserFilters({
filters: JSON.stringify([
{ propertyName: 'amount', operator: 'STARTS_WITH', value: '1' },
{ propertyName: 'amount', operator: 'GT', value: '1' },
]),
})
expect(filters).toEqual([{ propertyName: 'amount', operator: 'GT', value: '1' }])
})
it('ignores malformed JSON filters without throwing', () => {
expect(() => buildUserFilters({ filters: 'not json' })).not.toThrow()
expect(buildUserFilters({ filters: 'not json' })).toEqual([])
})
it('allows exactly the HubSpot per-group limit of combined filters', () => {
const filters = buildUserFilters({
objectType: 'deal',
pipelineId: 'pipeline-1',
stageId: 'stage-1',
ownerId: 'owner-1',
filters: JSON.stringify([{ propertyName: 'amount', operator: 'GT', value: '1000' }]),
})
// 3 shortcuts + 1 advanced = 4, exactly MAX_USER_FILTERS.
expect(filters).toHaveLength(4)
})
it('throws rather than silently dropping filters when the combined count exceeds the limit', () => {
// Filters within a filterGroup are AND-combined, so silently dropping one would widen
// the match set instead of narrowing it — throwing surfaces the misconfiguration loudly.
expect(() =>
buildUserFilters({
objectType: 'deal',
pipelineId: 'pipeline-1',
stageId: 'stage-1',
ownerId: 'owner-1',
filters: JSON.stringify([
{ propertyName: 'amount', operator: 'GT', value: '1000' },
{ propertyName: 'lifecyclestage', operator: 'EQ', value: 'customer' },
]),
})
).toThrow(/exceeding the 4-filter limit/)
})
})