appwrite/tests/unit
Jake Barnby 5404bfec75
refactor(insights): promote CTAs to own collection with backref
Embedding CTAs as a 16384-byte JSON blob on `insights` was the wrong
shape — they're real documents with their own lifecycle. Move them out.

Schema:
- New platform `ctas` collection. Each row carries `projectInternalId`,
  `projectId`, `insightInternalId`, `insightId` (backref), plus the
  CTA fields: `key`, `label`, `service`, `method`, `params`.
- Indexes: `(projectInternalId, insightInternalId)` for the subquery
  lookup and a UNIQUE `(insightInternalId, key)` so the per-insight
  uniqueness invariant lives at the DB layer (not just in PHP).
- The `ctas` field on `insights` becomes a virtual attribute backed by
  a new `subQueryInsightCTAs` filter that joins child docs at read
  time. Consumers still get CTAs embedded on the insight response —
  one round-trip from their perspective.
- The CTA descriptor's within-insight identifier renamed `id` → `key`
  (clashed with the document `$id`). Validator updated.

Endpoints:
- Manager Create now persists CTAs as separate `ctas` documents after
  the parent insight, then re-fetches the insight so the response
  carries the freshly-joined CTA list.
- User Update trimmed to user-controlled state only (`severity`,
  `status`). `title`, `summary`, `payload`, `ctas`, and `analyzedAt`
  are analyzer-controlled — analyzers re-ingest by deleting and
  POSTing again to the manager endpoint.
- Insight Delete cascades to CTAs.
- Report Delete cascades through Insights → CTAs.

Response model:
- InsightCTA gains the standard document headers (`$id`,
  `$createdAt`, `$updatedAt`) and an `insightId` backref. The
  caller-supplied identifier is now `key`.

Tests:
- E2E sampleCTA factory uses `key` everywhere; testCreate asserts the
  freshly-created CTA carries `$id`, `$createdAt`, `insightId`, and
  the right shape.
- Dropped the testUpdate*CTA* tests — user Update no longer accepts
  CTAs. testDismissViaUpdate now depends on testUpdate directly.
- Unit tests rewritten to validate `key` instead of `id`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-06 18:07:49 +12:00
..
Auth Rename from dynamic key to ephemeral key (api keys) 2026-04-28 17:18:06 +02:00
Detector tests: fix unit tests 2022-08-01 12:22:04 +02:00
Docker feat: worker executions 2026-02-09 20:20:44 +00:00
Event fix unit tests 2026-04-15 17:49:33 +05:30
Filter Sync 1.8.x 2026-02-26 18:50:29 +13:00
Functions/Validator chore: remove phpstan baseline 2026-04-01 23:01:11 +05:30
General Remove opcache test 2024-02-24 01:06:53 +13:00
GraphQL Fix GraphQL 15 static analysis 2026-04-14 10:26:59 +05:30
Insights/Validator refactor(insights): promote CTAs to own collection with backref 2026-05-06 18:07:49 +12:00
Messaging test(Messaging): validate that bare functions channel is not emitted in published channels 2026-04-27 18:46:04 +05:30
Migration Fix otp user 2026-01-11 02:49:28 +13:00
Network chore: bump PHPStan to level 4 and fix all new errors 2026-04-19 17:31:20 +05:30
OpenSSL tests: fix unit tests 2022-08-01 12:22:04 +02:00
Platform/Modules chore: bump PHPStan to level 4 and fix all new errors 2026-04-19 17:31:20 +05:30
SDK/Specification Remove scopes spec override, now fixed at source in #11839 2026-04-13 10:33:46 +05:30
Task/Validator Review updates for role helper usage 2022-08-19 16:04:33 +12:00
Template tests: fix unit tests 2022-08-01 12:22:04 +02:00
Transformation Update transformation lib structure 2025-02-14 10:01:27 +01:00
URL chore: bump PHPStan to level 4 and fix all new errors 2026-04-19 17:31:20 +05:30
Utopia test: add unit coverage for Request::getHeader non-string coercion 2026-04-28 04:15:00 +00:00