@atproto/ozone 0.2.8 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/package.json +25 -21
- package/bin/migration-create.ts +0 -38
- package/jest.config.cjs +0 -22
- package/src/api/chat/getActorMetadata.ts +0 -23
- package/src/api/chat/getConvo.ts +0 -23
- package/src/api/chat/getConvoMembers.ts +0 -23
- package/src/api/chat/getConvos.ts +0 -23
- package/src/api/chat/getMessageContext.ts +0 -42
- package/src/api/chat/index.ts +0 -16
- package/src/api/communication/createTemplate.ts +0 -51
- package/src/api/communication/deleteTemplate.ts +0 -23
- package/src/api/communication/listTemplates.ts +0 -31
- package/src/api/communication/updateTemplate.ts +0 -51
- package/src/api/health.ts +0 -27
- package/src/api/index.ts +0 -146
- package/src/api/label/fetchLabels.ts +0 -32
- package/src/api/label/queryLabels.ts +0 -57
- package/src/api/label/subscribeLabels.ts +0 -25
- package/src/api/moderation/cancelScheduledActions.ts +0 -72
- package/src/api/moderation/emitEvent.ts +0 -475
- package/src/api/moderation/getAccountTimeline.ts +0 -160
- package/src/api/moderation/getEvent.ts +0 -19
- package/src/api/moderation/getRecord.ts +0 -40
- package/src/api/moderation/getRecords.ts +0 -50
- package/src/api/moderation/getRepo.ts +0 -34
- package/src/api/moderation/getReporterStats.ts +0 -18
- package/src/api/moderation/getRepos.ts +0 -41
- package/src/api/moderation/getSubjects.ts +0 -101
- package/src/api/moderation/listScheduledActions.ts +0 -45
- package/src/api/moderation/queryEvents.ts +0 -72
- package/src/api/moderation/queryStatuses.ts +0 -23
- package/src/api/moderation/scheduleAction.ts +0 -129
- package/src/api/moderation/searchRepos.ts +0 -46
- package/src/api/moderation/util.ts +0 -96
- package/src/api/proxied.ts +0 -327
- package/src/api/queue/assignModerator.ts +0 -31
- package/src/api/queue/createQueue.ts +0 -62
- package/src/api/queue/deleteQueue.ts +0 -56
- package/src/api/queue/getAssignments.ts +0 -19
- package/src/api/queue/listQueues.ts +0 -39
- package/src/api/queue/routeReports.ts +0 -44
- package/src/api/queue/unassignModerator.ts +0 -26
- package/src/api/queue/updateQueue.ts +0 -54
- package/src/api/report/assignModerator.ts +0 -36
- package/src/api/report/createActivity.ts +0 -57
- package/src/api/report/createReport.ts +0 -93
- package/src/api/report/getAssignments.ts +0 -20
- package/src/api/report/getHistoricalStats.ts +0 -41
- package/src/api/report/getLatestReport.ts +0 -44
- package/src/api/report/getLiveStats.ts +0 -26
- package/src/api/report/getReport.ts +0 -55
- package/src/api/report/listActivities.ts +0 -37
- package/src/api/report/queryActivities.ts +0 -64
- package/src/api/report/queryReports.ts +0 -44
- package/src/api/report/reassignQueue.ts +0 -68
- package/src/api/report/refreshStats.ts +0 -27
- package/src/api/report/unassignModerator.ts +0 -21
- package/src/api/safelink/addRule.ts +0 -48
- package/src/api/safelink/queryEvents.ts +0 -32
- package/src/api/safelink/queryRules.ts +0 -58
- package/src/api/safelink/removeRule.ts +0 -42
- package/src/api/safelink/updateRule.ts +0 -48
- package/src/api/server/getConfig.ts +0 -35
- package/src/api/set/addValues.ts +0 -28
- package/src/api/set/deleteSet.ts +0 -34
- package/src/api/set/deleteValues.ts +0 -31
- package/src/api/set/getValues.ts +0 -42
- package/src/api/set/querySets.ts +0 -36
- package/src/api/set/upsertSet.ts +0 -38
- package/src/api/setting/listOptions.ts +0 -44
- package/src/api/setting/removeOptions.ts +0 -64
- package/src/api/setting/upsertOption.ts +0 -156
- package/src/api/team/addMember.ts +0 -51
- package/src/api/team/deleteMember.ts +0 -29
- package/src/api/team/listMembers.ts +0 -20
- package/src/api/team/updateMember.ts +0 -47
- package/src/api/util.ts +0 -265
- package/src/api/verification/grantVerifications.ts +0 -90
- package/src/api/verification/listVerifications.ts +0 -44
- package/src/api/verification/revokeVerifications.ts +0 -43
- package/src/api/well-known.ts +0 -46
- package/src/assignment/index.ts +0 -728
- package/src/auth-verifier.ts +0 -227
- package/src/background.ts +0 -183
- package/src/communication-service/template.ts +0 -110
- package/src/communication-service/util.ts +0 -8
- package/src/config/config.ts +0 -211
- package/src/config/env.ts +0 -95
- package/src/config/index.ts +0 -3
- package/src/config/secrets.ts +0 -17
- package/src/context.ts +0 -399
- package/src/daemon/blob-diverter.ts +0 -186
- package/src/daemon/context.ts +0 -247
- package/src/daemon/event-pusher.ts +0 -363
- package/src/daemon/event-reverser.ts +0 -128
- package/src/daemon/index.ts +0 -33
- package/src/daemon/job-cursor.ts +0 -33
- package/src/daemon/materialized-view-refresher.ts +0 -33
- package/src/daemon/queue-router.ts +0 -101
- package/src/daemon/scheduled-action-processor.ts +0 -304
- package/src/daemon/stats-computer.ts +0 -101
- package/src/daemon/strike-expiry-processor.ts +0 -95
- package/src/daemon/team-profile-synchronizer.ts +0 -15
- package/src/daemon/verification-listener.ts +0 -169
- package/src/db/index.ts +0 -203
- package/src/db/migrations/20231219T205730722Z-init.ts +0 -170
- package/src/db/migrations/20240116T085607200Z-communication-template.ts +0 -23
- package/src/db/migrations/20240201T051104136Z-mod-event-blobs.ts +0 -15
- package/src/db/migrations/20240208T213404429Z-add-tags-column-to-moderation-subject.ts +0 -31
- package/src/db/migrations/20240228T003647759Z-add-label-sigs.ts +0 -25
- package/src/db/migrations/20240408T192432676Z-mute-reporting.ts +0 -15
- package/src/db/migrations/20240506T225055595Z-message-subject.ts +0 -21
- package/src/db/migrations/20240521T211332580Z-member.ts +0 -17
- package/src/db/migrations/20240814T003647759Z-event-created-at-index.ts +0 -13
- package/src/db/migrations/20240903T205730722Z-add-template-lang.ts +0 -12
- package/src/db/migrations/20240904T205730722Z-add-subject-did-index.ts +0 -13
- package/src/db/migrations/20241001T205730722Z-subject-status-review-state-index.ts +0 -15
- package/src/db/migrations/20241008T205730722Z-sets.ts +0 -53
- package/src/db/migrations/20241018T205730722Z-setting.ts +0 -27
- package/src/db/migrations/20241026T205730722Z-add-hosting-status-to-subject-status.ts +0 -57
- package/src/db/migrations/20241220T144630860Z-stats-materialized-views.ts +0 -215
- package/src/db/migrations/20250204T003647759Z-add-subject-priority-score.ts +0 -22
- package/src/db/migrations/20250211T003647759Z-add-reporter-stats-index.ts +0 -38
- package/src/db/migrations/20250211T132135150Z-moderation-event-message-partial-idx.ts +0 -26
- package/src/db/migrations/20250221T132135150Z-member-details.ts +0 -14
- package/src/db/migrations/20250404T201720309Z-subject-status-sort-idxs.ts +0 -18
- package/src/db/migrations/20250415T201720309Z-verification.ts +0 -34
- package/src/db/migrations/20250417T201720309Z-firehose-cursor.ts +0 -16
- package/src/db/migrations/20250609T110704000Z-safelink.ts +0 -53
- package/src/db/migrations/20250618T180246000Z-add-mod-tool-to-moderation-event.ts +0 -18
- package/src/db/migrations/20250701T000000000Z-add-age-assurance-state.ts +0 -25
- package/src/db/migrations/20250715T000000000Z-add-mod-event-external-id.ts +0 -15
- package/src/db/migrations/20250718T150931000Z-update-appeal-reason-stats.ts +0 -310
- package/src/db/migrations/20250813T000000000Z-mod-tool-batch-id-index.ts +0 -14
- package/src/db/migrations/20250923T000000000Z-scheduled-actions.ts +0 -56
- package/src/db/migrations/20251008T120000000Z-add-strike-system.ts +0 -87
- package/src/db/migrations/20260210T154806448Z-mod-event-created-by-indexes.ts +0 -22
- package/src/db/migrations/20260219T164523000Z-create-report-table.ts +0 -155
- package/src/db/migrations/20260219T165302248Z-moderator-assignment.ts +0 -42
- package/src/db/migrations/20260225T000000000Z-add-report-queue-table.ts +0 -41
- package/src/db/migrations/20260313T000000000Z-add-report-activity-table.ts +0 -48
- package/src/db/migrations/20260318T152058935Z-add-report-stat.ts +0 -35
- package/src/db/migrations/20260428T000000000Z-add-expiring-tag-table.ts +0 -32
- package/src/db/migrations/20260513T202941104Z-add-subject-convo-id.ts +0 -114
- package/src/db/migrations/20260602T120000000Z-add-report-activity-created-index.ts +0 -17
- package/src/db/migrations/index.ts +0 -44
- package/src/db/migrations/provider.ts +0 -26
- package/src/db/pagination.ts +0 -335
- package/src/db/schema/account_events_stats.ts +0 -16
- package/src/db/schema/account_record_events_stats.ts +0 -15
- package/src/db/schema/account_record_status_stats.ts +0 -15
- package/src/db/schema/account_strike.ts +0 -13
- package/src/db/schema/blob_push_event.ts +0 -21
- package/src/db/schema/communication_template.ts +0 -19
- package/src/db/schema/expiring_tag.ts +0 -18
- package/src/db/schema/firehose_cursor.ts +0 -13
- package/src/db/schema/index.ts +0 -60
- package/src/db/schema/job_cursor.ts +0 -13
- package/src/db/schema/label.ts +0 -22
- package/src/db/schema/member.ts +0 -22
- package/src/db/schema/moderation_event.ts +0 -61
- package/src/db/schema/moderation_subject_status.ts +0 -52
- package/src/db/schema/moderator_assignment.ts +0 -16
- package/src/db/schema/ozone_set.ts +0 -24
- package/src/db/schema/record_events_stats.ts +0 -15
- package/src/db/schema/record_push_event.ts +0 -21
- package/src/db/schema/repo_push_event.ts +0 -19
- package/src/db/schema/report.ts +0 -28
- package/src/db/schema/report_activity.ts +0 -22
- package/src/db/schema/report_queue.ts +0 -21
- package/src/db/schema/report_stat.ts +0 -27
- package/src/db/schema/safelink.ts +0 -39
- package/src/db/schema/scheduled-action.ts +0 -25
- package/src/db/schema/setting.ts +0 -24
- package/src/db/schema/signing_key.ts +0 -10
- package/src/db/schema/verification.ts +0 -21
- package/src/db/types.ts +0 -24
- package/src/error.ts +0 -12
- package/src/image-invalidator.ts +0 -7
- package/src/index.ts +0 -154
- package/src/jetstream/service.ts +0 -107
- package/src/logger.ts +0 -29
- package/src/mod-service/expiring-tags.ts +0 -104
- package/src/mod-service/index.ts +0 -1842
- package/src/mod-service/profile.ts +0 -139
- package/src/mod-service/report.ts +0 -429
- package/src/mod-service/status.ts +0 -549
- package/src/mod-service/strike.ts +0 -96
- package/src/mod-service/subject.ts +0 -311
- package/src/mod-service/types.ts +0 -96
- package/src/mod-service/util.ts +0 -99
- package/src/mod-service/views.ts +0 -912
- package/src/queue/service.ts +0 -603
- package/src/report/activity.ts +0 -281
- package/src/report/handle-report-update.ts +0 -209
- package/src/report/reassign.ts +0 -109
- package/src/report/stats.ts +0 -852
- package/src/report/views.ts +0 -239
- package/src/safelink/service.ts +0 -304
- package/src/scheduled-action/service.ts +0 -281
- package/src/scheduled-action/types.ts +0 -17
- package/src/sequencer/index.ts +0 -2
- package/src/sequencer/outbox.ts +0 -123
- package/src/sequencer/sequencer.ts +0 -147
- package/src/set/service.ts +0 -230
- package/src/setting/constants.ts +0 -3
- package/src/setting/service.ts +0 -148
- package/src/setting/types.ts +0 -3
- package/src/setting/validators.ts +0 -333
- package/src/tag-service/content-tagger.ts +0 -30
- package/src/tag-service/embed-tagger.ts +0 -70
- package/src/tag-service/index.ts +0 -70
- package/src/tag-service/language-data.ts +0 -561
- package/src/tag-service/language-tagger.ts +0 -101
- package/src/tag-service/util.ts +0 -13
- package/src/team/index.ts +0 -296
- package/src/util.ts +0 -230
- package/src/verification/issuer.ts +0 -146
- package/src/verification/service.ts +0 -208
- package/src/verification/util.ts +0 -53
- package/test.env +0 -2
- package/tests/3p-labeler.test.ts +0 -288
- package/tests/__snapshots__/account-strikes.test.ts.snap +0 -159
- package/tests/__snapshots__/age-assurance.test.ts.snap +0 -66
- package/tests/__snapshots__/blob-divert.test.ts.snap +0 -219
- package/tests/__snapshots__/get-account-timeline.test.ts.snap +0 -36
- package/tests/__snapshots__/get-record.test.ts.snap +0 -271
- package/tests/__snapshots__/get-records.test.ts.snap +0 -175
- package/tests/__snapshots__/get-repo.test.ts.snap +0 -91
- package/tests/__snapshots__/get-repos.test.ts.snap +0 -127
- package/tests/__snapshots__/get-starter-pack.test.ts.snap +0 -535
- package/tests/__snapshots__/get-subjects.test.ts.snap +0 -529
- package/tests/__snapshots__/moderation-events.test.ts.snap +0 -347
- package/tests/__snapshots__/moderation-statuses.test.ts.snap +0 -276
- package/tests/__snapshots__/moderation.test.ts.snap +0 -85
- package/tests/__snapshots__/report-reason.test.ts.snap +0 -14
- package/tests/__snapshots__/safelink.test.ts.snap +0 -179
- package/tests/__snapshots__/scheduled-action.test.ts.snap +0 -61
- package/tests/__snapshots__/sets.test.ts.snap +0 -46
- package/tests/__snapshots__/settings.test.ts.snap +0 -52
- package/tests/__snapshots__/team.test.ts.snap +0 -374
- package/tests/__snapshots__/verification-listener.test.ts.snap +0 -152
- package/tests/__snapshots__/verification.test.ts.snap +0 -302
- package/tests/_util.ts +0 -242
- package/tests/account-strikes.test.ts +0 -184
- package/tests/ack-all-subjects-of-account.test.ts +0 -177
- package/tests/age-assurance.test.ts +0 -372
- package/tests/blob-divert.test.ts +0 -106
- package/tests/communication-templates.test.ts +0 -149
- package/tests/content-tagger.test.ts +0 -170
- package/tests/db.test.ts +0 -184
- package/tests/expiring-label.test.ts +0 -72
- package/tests/expiring-tags.test.ts +0 -232
- package/tests/get-account-timeline.test.ts +0 -85
- package/tests/get-config.test.ts +0 -55
- package/tests/get-lists.test.ts +0 -111
- package/tests/get-profiles.test.ts +0 -70
- package/tests/get-record.test.ts +0 -130
- package/tests/get-records.test.ts +0 -91
- package/tests/get-repo.test.ts +0 -171
- package/tests/get-report.test.ts +0 -136
- package/tests/get-reporter-stats.test.ts +0 -132
- package/tests/get-repos.test.ts +0 -91
- package/tests/get-starter-pack.test.ts +0 -115
- package/tests/get-subjects.test.ts +0 -81
- package/tests/mod-tool.test.ts +0 -268
- package/tests/moderation-appeals.test.ts +0 -260
- package/tests/moderation-events.test.ts +0 -756
- package/tests/moderation-status-tags.test.ts +0 -140
- package/tests/moderation-statuses.test.ts +0 -495
- package/tests/moderation.test.ts +0 -992
- package/tests/protected-tags.test.ts +0 -218
- package/tests/query-labels.test.ts +0 -238
- package/tests/query-reports.test.ts +0 -608
- package/tests/queue-assignment.test.ts +0 -428
- package/tests/queue-router.test.ts +0 -306
- package/tests/queues.test.ts +0 -690
- package/tests/record-and-account-events.test.ts +0 -197
- package/tests/repo-search.test.ts +0 -136
- package/tests/report-action.test.ts +0 -308
- package/tests/report-activity.test.ts +0 -711
- package/tests/report-assignment.test.ts +0 -517
- package/tests/report-muting.test.ts +0 -100
- package/tests/report-reason.test.ts +0 -154
- package/tests/report-reassign-queue.test.ts +0 -340
- package/tests/report-routing.test.ts +0 -245
- package/tests/report-stats.test.ts +0 -545
- package/tests/revoke-account-credentials.test.ts +0 -54
- package/tests/safelink.test.ts +0 -534
- package/tests/scheduled-action-processor.test.ts +0 -488
- package/tests/scheduled-action.test.ts +0 -334
- package/tests/sequencer.test.ts +0 -227
- package/tests/server.test.ts +0 -62
- package/tests/sets.test.ts +0 -246
- package/tests/settings.test.ts +0 -308
- package/tests/strike-expiry-processor.test.ts +0 -299
- package/tests/subject-priority-score.test.ts +0 -96
- package/tests/takedown.test.ts +0 -105
- package/tests/team.test.ts +0 -216
- package/tests/verification-listener.test.ts +0 -129
- package/tests/verification.test.ts +0 -186
- package/tsconfig.build.json +0 -9
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -8
|
@@ -1,711 +0,0 @@
|
|
|
1
|
-
import AtpAgent from '@atproto/api'
|
|
2
|
-
import { SeedClient, TestNetwork, basicSeed } from '@atproto/dev-env'
|
|
3
|
-
import { ids } from '../src/lexicon/lexicons.js'
|
|
4
|
-
import { REASONSPAM } from '../src/lexicon/types/com/atproto/moderation/defs.js'
|
|
5
|
-
|
|
6
|
-
const DEFS = 'tools.ozone.report.defs'
|
|
7
|
-
|
|
8
|
-
describe('report-activity', () => {
|
|
9
|
-
let network: TestNetwork
|
|
10
|
-
let agent: AtpAgent
|
|
11
|
-
let sc: SeedClient
|
|
12
|
-
|
|
13
|
-
const modHeaders = async (nsid: string) =>
|
|
14
|
-
network.ozone.modHeaders(nsid, 'admin')
|
|
15
|
-
|
|
16
|
-
const createReport = async (subjectDid: string) => {
|
|
17
|
-
await sc.createReport({
|
|
18
|
-
reasonType: REASONSPAM,
|
|
19
|
-
subject: {
|
|
20
|
-
$type: 'com.atproto.admin.defs#repoRef',
|
|
21
|
-
did: subjectDid,
|
|
22
|
-
},
|
|
23
|
-
reportedBy: sc.dids.bob,
|
|
24
|
-
})
|
|
25
|
-
await network.processAll()
|
|
26
|
-
|
|
27
|
-
const { data } = await agent.tools.ozone.report.queryReports(
|
|
28
|
-
{ status: 'open', subject: subjectDid },
|
|
29
|
-
{ headers: await modHeaders(ids.ToolsOzoneReportQueryReports) },
|
|
30
|
-
)
|
|
31
|
-
const report = data.reports[0]
|
|
32
|
-
if (!report) throw new Error(`No report found for subject ${subjectDid}`)
|
|
33
|
-
return report
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const createActivity = async (
|
|
37
|
-
input: {
|
|
38
|
-
reportId: number
|
|
39
|
-
activity: { $type: string; [k: string]: unknown }
|
|
40
|
-
internalNote?: string
|
|
41
|
-
publicNote?: string
|
|
42
|
-
isAutomated?: boolean
|
|
43
|
-
},
|
|
44
|
-
role: 'admin' | 'triage' = 'admin',
|
|
45
|
-
) => {
|
|
46
|
-
return agent.tools.ozone.report.createActivity(input, {
|
|
47
|
-
encoding: 'application/json',
|
|
48
|
-
headers: await network.ozone.modHeaders(
|
|
49
|
-
ids.ToolsOzoneReportCreateActivity,
|
|
50
|
-
role,
|
|
51
|
-
),
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const listActivities = async (
|
|
56
|
-
params: { reportId: number; limit?: number; cursor?: string },
|
|
57
|
-
role: 'admin' | 'triage' = 'admin',
|
|
58
|
-
) => {
|
|
59
|
-
return agent.tools.ozone.report.listActivities(params, {
|
|
60
|
-
headers: await network.ozone.modHeaders(
|
|
61
|
-
ids.ToolsOzoneReportListActivities,
|
|
62
|
-
role,
|
|
63
|
-
),
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
beforeAll(async () => {
|
|
68
|
-
network = await TestNetwork.create({
|
|
69
|
-
dbPostgresSchema: 'ozone_report_activity',
|
|
70
|
-
})
|
|
71
|
-
agent = network.ozone.getAgent()
|
|
72
|
-
sc = network.getSeedClient()
|
|
73
|
-
await basicSeed(sc)
|
|
74
|
-
await network.processAll()
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
afterAll(async () => {
|
|
78
|
-
await network?.close()
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
describe('createActivity — noteActivity', () => {
|
|
82
|
-
it('creates an internal note', async () => {
|
|
83
|
-
const report = await createReport(sc.dids.alice)
|
|
84
|
-
const { data } = await createActivity({
|
|
85
|
-
reportId: report.id,
|
|
86
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
87
|
-
internalNote: 'Looks like this may be a bot account.',
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
expect(data.activity.reportId).toBe(report.id)
|
|
91
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#noteActivity`)
|
|
92
|
-
expect(data.activity.internalNote).toBe(
|
|
93
|
-
'Looks like this may be a bot account.',
|
|
94
|
-
)
|
|
95
|
-
expect(data.activity.publicNote).toBeUndefined()
|
|
96
|
-
expect(data.activity.isAutomated).toBe(false)
|
|
97
|
-
expect(data.activity.createdBy).toBeDefined()
|
|
98
|
-
expect(data.activity.createdAt).toBeDefined()
|
|
99
|
-
expect(data.activity.id).toBeDefined()
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('creates a public note', async () => {
|
|
103
|
-
const report = await createReport(sc.dids.alice)
|
|
104
|
-
const { data } = await createActivity({
|
|
105
|
-
reportId: report.id,
|
|
106
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
107
|
-
publicNote: 'We have reviewed your report.',
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#noteActivity`)
|
|
111
|
-
expect(data.activity.publicNote).toBe('We have reviewed your report.')
|
|
112
|
-
expect(data.activity.internalNote).toBeUndefined()
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
it('creates a note without text', async () => {
|
|
116
|
-
const report = await createReport(sc.dids.alice)
|
|
117
|
-
const { data } = await createActivity({
|
|
118
|
-
reportId: report.id,
|
|
119
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#noteActivity`)
|
|
123
|
-
expect(data.activity.internalNote).toBeUndefined()
|
|
124
|
-
expect(data.activity.publicNote).toBeUndefined()
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it('does not change report status', async () => {
|
|
128
|
-
const report = await createReport(sc.dids.alice)
|
|
129
|
-
await createActivity({
|
|
130
|
-
reportId: report.id,
|
|
131
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
132
|
-
internalNote: 'Just noting this.',
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
const { data: updated } = await agent.tools.ozone.report.getReport(
|
|
136
|
-
{ id: report.id },
|
|
137
|
-
{ headers: await modHeaders(ids.ToolsOzoneReportGetReport) },
|
|
138
|
-
)
|
|
139
|
-
expect(updated.status).toBe('open')
|
|
140
|
-
})
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
describe('createActivity — state-change activities (valid transitions)', () => {
|
|
144
|
-
it('open → closed (closeActivity)', async () => {
|
|
145
|
-
const report = await createReport(sc.dids.alice)
|
|
146
|
-
const { data } = await createActivity({
|
|
147
|
-
reportId: report.id,
|
|
148
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#closeActivity`)
|
|
152
|
-
if ('previousStatus' in data.activity.activity) {
|
|
153
|
-
expect(data.activity.activity.previousStatus).toBe('open')
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const { data: updated } = await agent.tools.ozone.report.getReport(
|
|
157
|
-
{ id: report.id },
|
|
158
|
-
{ headers: await modHeaders(ids.ToolsOzoneReportGetReport) },
|
|
159
|
-
)
|
|
160
|
-
expect(updated.status).toBe('closed')
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
it('open → escalated (escalationActivity)', async () => {
|
|
164
|
-
const report = await createReport(sc.dids.alice)
|
|
165
|
-
const { data } = await createActivity({
|
|
166
|
-
reportId: report.id,
|
|
167
|
-
activity: { $type: `${DEFS}#escalationActivity` },
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#escalationActivity`)
|
|
171
|
-
if ('previousStatus' in data.activity.activity) {
|
|
172
|
-
expect(data.activity.activity.previousStatus).toBe('open')
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
it('open → queued (queueActivity)', async () => {
|
|
177
|
-
const report = await createReport(sc.dids.alice)
|
|
178
|
-
const { data } = await createActivity({
|
|
179
|
-
reportId: report.id,
|
|
180
|
-
activity: { $type: `${DEFS}#queueActivity` },
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#queueActivity`)
|
|
184
|
-
if ('previousStatus' in data.activity.activity) {
|
|
185
|
-
expect(data.activity.activity.previousStatus).toBe('open')
|
|
186
|
-
}
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
it('open → assigned (assignmentActivity)', async () => {
|
|
190
|
-
const report = await createReport(sc.dids.alice)
|
|
191
|
-
const { data } = await createActivity({
|
|
192
|
-
reportId: report.id,
|
|
193
|
-
activity: { $type: `${DEFS}#assignmentActivity` },
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#assignmentActivity`)
|
|
197
|
-
if ('previousStatus' in data.activity.activity) {
|
|
198
|
-
expect(data.activity.activity.previousStatus).toBe('open')
|
|
199
|
-
}
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
it('queued → assigned (assignmentActivity)', async () => {
|
|
203
|
-
const report = await createReport(sc.dids.alice)
|
|
204
|
-
await createActivity({
|
|
205
|
-
reportId: report.id,
|
|
206
|
-
activity: { $type: `${DEFS}#queueActivity` },
|
|
207
|
-
})
|
|
208
|
-
const { data } = await createActivity({
|
|
209
|
-
reportId: report.id,
|
|
210
|
-
activity: { $type: `${DEFS}#assignmentActivity` },
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
if ('previousStatus' in data.activity.activity) {
|
|
214
|
-
expect(data.activity.activity.previousStatus).toBe('queued')
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
it('escalated → closed (closeActivity)', async () => {
|
|
219
|
-
const report = await createReport(sc.dids.alice)
|
|
220
|
-
await createActivity({
|
|
221
|
-
reportId: report.id,
|
|
222
|
-
activity: { $type: `${DEFS}#escalationActivity` },
|
|
223
|
-
})
|
|
224
|
-
const { data } = await createActivity({
|
|
225
|
-
reportId: report.id,
|
|
226
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
if ('previousStatus' in data.activity.activity) {
|
|
230
|
-
expect(data.activity.activity.previousStatus).toBe('escalated')
|
|
231
|
-
}
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
it('assigned → closed (closeActivity)', async () => {
|
|
235
|
-
const report = await createReport(sc.dids.alice)
|
|
236
|
-
await createActivity({
|
|
237
|
-
reportId: report.id,
|
|
238
|
-
activity: { $type: `${DEFS}#assignmentActivity` },
|
|
239
|
-
})
|
|
240
|
-
const { data } = await createActivity({
|
|
241
|
-
reportId: report.id,
|
|
242
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
if ('previousStatus' in data.activity.activity) {
|
|
246
|
-
expect(data.activity.activity.previousStatus).toBe('assigned')
|
|
247
|
-
}
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it('assigned → escalated (escalationActivity)', async () => {
|
|
251
|
-
const report = await createReport(sc.dids.alice)
|
|
252
|
-
await createActivity({
|
|
253
|
-
reportId: report.id,
|
|
254
|
-
activity: { $type: `${DEFS}#assignmentActivity` },
|
|
255
|
-
})
|
|
256
|
-
const { data } = await createActivity({
|
|
257
|
-
reportId: report.id,
|
|
258
|
-
activity: { $type: `${DEFS}#escalationActivity` },
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
if ('previousStatus' in data.activity.activity) {
|
|
262
|
-
expect(data.activity.activity.previousStatus).toBe('assigned')
|
|
263
|
-
}
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
it('closed → open (reopenActivity)', async () => {
|
|
267
|
-
const report = await createReport(sc.dids.alice)
|
|
268
|
-
await createActivity({
|
|
269
|
-
reportId: report.id,
|
|
270
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
271
|
-
})
|
|
272
|
-
const { data } = await createActivity({
|
|
273
|
-
reportId: report.id,
|
|
274
|
-
activity: { $type: `${DEFS}#reopenActivity` },
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#reopenActivity`)
|
|
278
|
-
if ('previousStatus' in data.activity.activity) {
|
|
279
|
-
expect(data.activity.activity.previousStatus).toBe('closed')
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const { data: updated } = await agent.tools.ozone.report.getReport(
|
|
283
|
-
{ id: report.id },
|
|
284
|
-
{ headers: await modHeaders(ids.ToolsOzoneReportGetReport) },
|
|
285
|
-
)
|
|
286
|
-
expect(updated.status).toBe('open')
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
it('attaches internalNote and publicNote alongside a state-change', async () => {
|
|
290
|
-
const report = await createReport(sc.dids.alice)
|
|
291
|
-
const { data } = await createActivity({
|
|
292
|
-
reportId: report.id,
|
|
293
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
294
|
-
internalNote: 'Confirmed spam internally.',
|
|
295
|
-
publicNote: 'We have closed your report.',
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
expect(data.activity.activity.$type).toBe(`${DEFS}#closeActivity`)
|
|
299
|
-
expect(data.activity.internalNote).toBe('Confirmed spam internally.')
|
|
300
|
-
expect(data.activity.publicNote).toBe('We have closed your report.')
|
|
301
|
-
})
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
describe('createActivity — AlreadyInTargetState', () => {
|
|
305
|
-
it('rejects when report is already in the target status', async () => {
|
|
306
|
-
const report = await createReport(sc.dids.alice)
|
|
307
|
-
// Report starts as 'open', closeActivity targets 'closed'
|
|
308
|
-
await createActivity({
|
|
309
|
-
reportId: report.id,
|
|
310
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
311
|
-
})
|
|
312
|
-
await expect(
|
|
313
|
-
createActivity({
|
|
314
|
-
reportId: report.id,
|
|
315
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
316
|
-
}),
|
|
317
|
-
).rejects.toMatchObject({ error: 'AlreadyInTargetState' })
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
it('does not record an activity when AlreadyInTargetState is thrown', async () => {
|
|
321
|
-
const report = await createReport(sc.dids.alice)
|
|
322
|
-
// queueActivity targets 'queued' — report already starts 'open' so first one works
|
|
323
|
-
await createActivity({
|
|
324
|
-
reportId: report.id,
|
|
325
|
-
activity: { $type: `${DEFS}#queueActivity` },
|
|
326
|
-
})
|
|
327
|
-
await expect(
|
|
328
|
-
createActivity({
|
|
329
|
-
reportId: report.id,
|
|
330
|
-
activity: { $type: `${DEFS}#queueActivity` },
|
|
331
|
-
}),
|
|
332
|
-
).rejects.toMatchObject({ error: 'AlreadyInTargetState' })
|
|
333
|
-
|
|
334
|
-
const { data } = await listActivities({ reportId: report.id })
|
|
335
|
-
expect(data.activities).toHaveLength(1)
|
|
336
|
-
})
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
describe('createActivity — InvalidStateTransition', () => {
|
|
340
|
-
it('rejects closed → escalated', async () => {
|
|
341
|
-
const report = await createReport(sc.dids.alice)
|
|
342
|
-
await createActivity({
|
|
343
|
-
reportId: report.id,
|
|
344
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
345
|
-
})
|
|
346
|
-
await expect(
|
|
347
|
-
createActivity({
|
|
348
|
-
reportId: report.id,
|
|
349
|
-
activity: { $type: `${DEFS}#escalationActivity` },
|
|
350
|
-
}),
|
|
351
|
-
).rejects.toMatchObject({ error: 'InvalidStateTransition' })
|
|
352
|
-
})
|
|
353
|
-
|
|
354
|
-
it('rejects closed → queued', async () => {
|
|
355
|
-
const report = await createReport(sc.dids.alice)
|
|
356
|
-
await createActivity({
|
|
357
|
-
reportId: report.id,
|
|
358
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
359
|
-
})
|
|
360
|
-
await expect(
|
|
361
|
-
createActivity({
|
|
362
|
-
reportId: report.id,
|
|
363
|
-
activity: { $type: `${DEFS}#queueActivity` },
|
|
364
|
-
}),
|
|
365
|
-
).rejects.toMatchObject({ error: 'InvalidStateTransition' })
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
it('rejects escalated → queued', async () => {
|
|
369
|
-
const report = await createReport(sc.dids.alice)
|
|
370
|
-
await createActivity({
|
|
371
|
-
reportId: report.id,
|
|
372
|
-
activity: { $type: `${DEFS}#escalationActivity` },
|
|
373
|
-
})
|
|
374
|
-
await expect(
|
|
375
|
-
createActivity({
|
|
376
|
-
reportId: report.id,
|
|
377
|
-
activity: { $type: `${DEFS}#queueActivity` },
|
|
378
|
-
}),
|
|
379
|
-
).rejects.toMatchObject({ error: 'InvalidStateTransition' })
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
it('rejects queued → closed', async () => {
|
|
383
|
-
const report = await createReport(sc.dids.alice)
|
|
384
|
-
await createActivity({
|
|
385
|
-
reportId: report.id,
|
|
386
|
-
activity: { $type: `${DEFS}#queueActivity` },
|
|
387
|
-
})
|
|
388
|
-
await expect(
|
|
389
|
-
createActivity({
|
|
390
|
-
reportId: report.id,
|
|
391
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
392
|
-
}),
|
|
393
|
-
).rejects.toMatchObject({ error: 'InvalidStateTransition' })
|
|
394
|
-
})
|
|
395
|
-
|
|
396
|
-
it('rejects reopenActivity on open report', async () => {
|
|
397
|
-
const report = await createReport(sc.dids.alice)
|
|
398
|
-
// report starts as 'open', reopenActivity only valid from 'closed'
|
|
399
|
-
await expect(
|
|
400
|
-
createActivity({
|
|
401
|
-
reportId: report.id,
|
|
402
|
-
activity: { $type: `${DEFS}#reopenActivity` },
|
|
403
|
-
}),
|
|
404
|
-
).rejects.toMatchObject({ error: 'InvalidStateTransition' })
|
|
405
|
-
})
|
|
406
|
-
|
|
407
|
-
it('rejects reopenActivity on escalated report', async () => {
|
|
408
|
-
const report = await createReport(sc.dids.alice)
|
|
409
|
-
await createActivity({
|
|
410
|
-
reportId: report.id,
|
|
411
|
-
activity: { $type: `${DEFS}#escalationActivity` },
|
|
412
|
-
})
|
|
413
|
-
await expect(
|
|
414
|
-
createActivity({
|
|
415
|
-
reportId: report.id,
|
|
416
|
-
activity: { $type: `${DEFS}#reopenActivity` },
|
|
417
|
-
}),
|
|
418
|
-
).rejects.toMatchObject({ error: 'InvalidStateTransition' })
|
|
419
|
-
})
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
describe('createActivity — input validation errors', () => {
|
|
423
|
-
it('rejects unknown activity type', async () => {
|
|
424
|
-
const report = await createReport(sc.dids.alice)
|
|
425
|
-
await expect(
|
|
426
|
-
createActivity({
|
|
427
|
-
reportId: report.id,
|
|
428
|
-
activity: { $type: `${DEFS}#unknownActivity` },
|
|
429
|
-
}),
|
|
430
|
-
).rejects.toMatchObject({ error: 'InvalidActivityType' })
|
|
431
|
-
})
|
|
432
|
-
|
|
433
|
-
it('rejects unknown reportId', async () => {
|
|
434
|
-
await expect(
|
|
435
|
-
createActivity({
|
|
436
|
-
reportId: 999999,
|
|
437
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
438
|
-
internalNote: 'Ghost report',
|
|
439
|
-
}),
|
|
440
|
-
).rejects.toMatchObject({ error: 'ReportNotFound' })
|
|
441
|
-
})
|
|
442
|
-
})
|
|
443
|
-
|
|
444
|
-
describe('listActivities', () => {
|
|
445
|
-
it('returns empty list for report with no activities', async () => {
|
|
446
|
-
const report = await createReport(sc.dids.alice)
|
|
447
|
-
const { data } = await listActivities({ reportId: report.id })
|
|
448
|
-
|
|
449
|
-
expect(data.activities).toEqual([])
|
|
450
|
-
expect(data.cursor).toBeUndefined()
|
|
451
|
-
})
|
|
452
|
-
|
|
453
|
-
it('returns activities sorted most-recent-first', async () => {
|
|
454
|
-
const report = await createReport(sc.dids.alice)
|
|
455
|
-
|
|
456
|
-
await createActivity({
|
|
457
|
-
reportId: report.id,
|
|
458
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
459
|
-
internalNote: 'First note',
|
|
460
|
-
})
|
|
461
|
-
await createActivity({
|
|
462
|
-
reportId: report.id,
|
|
463
|
-
activity: { $type: `${DEFS}#escalationActivity` },
|
|
464
|
-
})
|
|
465
|
-
await createActivity({
|
|
466
|
-
reportId: report.id,
|
|
467
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
468
|
-
internalNote: 'Third note',
|
|
469
|
-
})
|
|
470
|
-
|
|
471
|
-
const { data } = await listActivities({ reportId: report.id })
|
|
472
|
-
|
|
473
|
-
expect(data.activities).toHaveLength(3)
|
|
474
|
-
expect(data.activities[0].id).toBeGreaterThan(data.activities[1].id)
|
|
475
|
-
expect(data.activities[1].id).toBeGreaterThan(data.activities[2].id)
|
|
476
|
-
expect(data.activities[0].internalNote).toBe('Third note')
|
|
477
|
-
expect(data.activities[2].internalNote).toBe('First note')
|
|
478
|
-
})
|
|
479
|
-
|
|
480
|
-
it('returns correct shape for each activity type', async () => {
|
|
481
|
-
const report = await createReport(sc.dids.alice)
|
|
482
|
-
|
|
483
|
-
await createActivity({
|
|
484
|
-
reportId: report.id,
|
|
485
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
486
|
-
internalNote: 'n',
|
|
487
|
-
})
|
|
488
|
-
await createActivity({
|
|
489
|
-
reportId: report.id,
|
|
490
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
491
|
-
})
|
|
492
|
-
|
|
493
|
-
const { data } = await listActivities({ reportId: report.id })
|
|
494
|
-
const [closeAct, noteAct] = data.activities // most-recent first
|
|
495
|
-
|
|
496
|
-
expect(closeAct.activity.$type).toBe(`${DEFS}#closeActivity`)
|
|
497
|
-
if ('previousStatus' in closeAct.activity) {
|
|
498
|
-
expect(closeAct.activity.previousStatus).toBe('open')
|
|
499
|
-
}
|
|
500
|
-
expect(closeAct.internalNote).toBeUndefined()
|
|
501
|
-
expect(closeAct.isAutomated).toBe(false)
|
|
502
|
-
|
|
503
|
-
expect(noteAct.activity.$type).toBe(`${DEFS}#noteActivity`)
|
|
504
|
-
expect('previousStatus' in noteAct.activity).toBe(false)
|
|
505
|
-
expect(noteAct.internalNote).toBe('n')
|
|
506
|
-
})
|
|
507
|
-
|
|
508
|
-
it('paginates correctly', async () => {
|
|
509
|
-
const report = await createReport(sc.dids.alice)
|
|
510
|
-
|
|
511
|
-
for (let i = 0; i < 5; i++) {
|
|
512
|
-
await createActivity({
|
|
513
|
-
reportId: report.id,
|
|
514
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
515
|
-
internalNote: `Note ${i}`,
|
|
516
|
-
})
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
const firstPage = await listActivities({ reportId: report.id, limit: 2 })
|
|
520
|
-
expect(firstPage.data.activities).toHaveLength(2)
|
|
521
|
-
expect(firstPage.data.cursor).toBeDefined()
|
|
522
|
-
|
|
523
|
-
const secondPage = await listActivities({
|
|
524
|
-
reportId: report.id,
|
|
525
|
-
limit: 2,
|
|
526
|
-
cursor: firstPage.data.cursor,
|
|
527
|
-
})
|
|
528
|
-
expect(secondPage.data.activities).toHaveLength(2)
|
|
529
|
-
expect(secondPage.data.cursor).toBeDefined()
|
|
530
|
-
|
|
531
|
-
const thirdPage = await listActivities({
|
|
532
|
-
reportId: report.id,
|
|
533
|
-
limit: 2,
|
|
534
|
-
cursor: secondPage.data.cursor,
|
|
535
|
-
})
|
|
536
|
-
expect(thirdPage.data.activities).toHaveLength(1)
|
|
537
|
-
expect(thirdPage.data.cursor).toBeUndefined()
|
|
538
|
-
|
|
539
|
-
const allIds = [
|
|
540
|
-
...firstPage.data.activities,
|
|
541
|
-
...secondPage.data.activities,
|
|
542
|
-
...thirdPage.data.activities,
|
|
543
|
-
].map((a) => a.id)
|
|
544
|
-
expect(new Set(allIds).size).toBe(5)
|
|
545
|
-
})
|
|
546
|
-
|
|
547
|
-
it('only returns activities for the requested report', async () => {
|
|
548
|
-
const reportA = await createReport(sc.dids.alice)
|
|
549
|
-
const reportB = await createReport(sc.dids.bob)
|
|
550
|
-
|
|
551
|
-
await createActivity({
|
|
552
|
-
reportId: reportA.id,
|
|
553
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
554
|
-
internalNote: 'Note on A',
|
|
555
|
-
})
|
|
556
|
-
await createActivity({
|
|
557
|
-
reportId: reportB.id,
|
|
558
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
559
|
-
internalNote: 'Note on B',
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
const { data } = await listActivities({ reportId: reportA.id })
|
|
563
|
-
expect(data.activities.every((a) => a.reportId === reportA.id)).toBe(true)
|
|
564
|
-
expect(data.activities.some((a) => a.reportId === reportB.id)).toBe(false)
|
|
565
|
-
})
|
|
566
|
-
})
|
|
567
|
-
|
|
568
|
-
describe('queryActivities', () => {
|
|
569
|
-
const queryActivities = async (
|
|
570
|
-
params: {
|
|
571
|
-
activityTypes?: string[]
|
|
572
|
-
createdAfter?: string
|
|
573
|
-
createdBefore?: string
|
|
574
|
-
sortDirection?: 'asc' | 'desc'
|
|
575
|
-
limit?: number
|
|
576
|
-
cursor?: string
|
|
577
|
-
},
|
|
578
|
-
role: 'admin' | 'triage' = 'admin',
|
|
579
|
-
) => {
|
|
580
|
-
return agent.tools.ozone.report.queryActivities(params, {
|
|
581
|
-
headers: await network.ozone.modHeaders(
|
|
582
|
-
ids.ToolsOzoneReportQueryActivities,
|
|
583
|
-
role,
|
|
584
|
-
),
|
|
585
|
-
})
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
it('hydrates the report on each activity', async () => {
|
|
589
|
-
const report = await createReport(sc.dids.alice)
|
|
590
|
-
await createActivity({
|
|
591
|
-
reportId: report.id,
|
|
592
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
593
|
-
})
|
|
594
|
-
|
|
595
|
-
const { data } = await queryActivities({
|
|
596
|
-
activityTypes: ['closeActivity'],
|
|
597
|
-
sortDirection: 'desc',
|
|
598
|
-
limit: 100,
|
|
599
|
-
})
|
|
600
|
-
const hit = data.activities.find((a) => a.reportId === report.id)
|
|
601
|
-
expect(hit).toBeDefined()
|
|
602
|
-
expect(hit!.report).toBeDefined()
|
|
603
|
-
expect(hit!.report!.id).toBe(report.id)
|
|
604
|
-
expect(hit!.report!.subject).toBeDefined()
|
|
605
|
-
})
|
|
606
|
-
|
|
607
|
-
it('filters by activity types across reports', async () => {
|
|
608
|
-
const reportA = await createReport(sc.dids.alice)
|
|
609
|
-
const reportB = await createReport(sc.dids.bob)
|
|
610
|
-
await createActivity({
|
|
611
|
-
reportId: reportA.id,
|
|
612
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
613
|
-
internalNote: 'note',
|
|
614
|
-
})
|
|
615
|
-
await createActivity({
|
|
616
|
-
reportId: reportA.id,
|
|
617
|
-
activity: { $type: `${DEFS}#closeActivity` },
|
|
618
|
-
})
|
|
619
|
-
await createActivity({
|
|
620
|
-
reportId: reportB.id,
|
|
621
|
-
activity: { $type: `${DEFS}#escalationActivity` },
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
const { data } = await queryActivities({
|
|
625
|
-
activityTypes: ['closeActivity', 'escalationActivity'],
|
|
626
|
-
sortDirection: 'asc',
|
|
627
|
-
})
|
|
628
|
-
|
|
629
|
-
const types = new Set(data.activities.map((a) => a.activity.$type))
|
|
630
|
-
expect(types.has(`${DEFS}#noteActivity`)).toBe(false)
|
|
631
|
-
expect(types.has(`${DEFS}#closeActivity`)).toBe(true)
|
|
632
|
-
expect(types.has(`${DEFS}#escalationActivity`)).toBe(true)
|
|
633
|
-
const reportIds = new Set(data.activities.map((a) => a.reportId))
|
|
634
|
-
expect(reportIds.has(reportA.id)).toBe(true)
|
|
635
|
-
expect(reportIds.has(reportB.id)).toBe(true)
|
|
636
|
-
})
|
|
637
|
-
|
|
638
|
-
it('paginates ascending across multiple reports with stable cursor', async () => {
|
|
639
|
-
const reportA = await createReport(sc.dids.alice)
|
|
640
|
-
const reportB = await createReport(sc.dids.bob)
|
|
641
|
-
const created: number[] = []
|
|
642
|
-
for (let i = 0; i < 3; i++) {
|
|
643
|
-
const r = await createActivity({
|
|
644
|
-
reportId: i % 2 === 0 ? reportA.id : reportB.id,
|
|
645
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
646
|
-
internalNote: `n-${i}`,
|
|
647
|
-
})
|
|
648
|
-
created.push(r.data.activity.id)
|
|
649
|
-
}
|
|
650
|
-
const minId = Math.min(...created)
|
|
651
|
-
|
|
652
|
-
const seen: number[] = []
|
|
653
|
-
let cursor: string | undefined
|
|
654
|
-
let pages = 0
|
|
655
|
-
do {
|
|
656
|
-
const { data } = await queryActivities({
|
|
657
|
-
sortDirection: 'asc',
|
|
658
|
-
limit: 2,
|
|
659
|
-
cursor,
|
|
660
|
-
})
|
|
661
|
-
for (const a of data.activities) {
|
|
662
|
-
if (a.id >= minId) seen.push(a.id)
|
|
663
|
-
}
|
|
664
|
-
cursor = data.cursor
|
|
665
|
-
pages++
|
|
666
|
-
if (pages > 50) break // safety net for runaway loops
|
|
667
|
-
} while (cursor)
|
|
668
|
-
|
|
669
|
-
// The created activities should appear in ascending ID order, no dupes.
|
|
670
|
-
const sortedCreated = [...created].sort((a, b) => a - b)
|
|
671
|
-
const seenForCreated = seen.filter((id) => created.includes(id))
|
|
672
|
-
expect(seenForCreated).toEqual(sortedCreated)
|
|
673
|
-
})
|
|
674
|
-
|
|
675
|
-
it('respects createdBefore and createdAfter bounds', async () => {
|
|
676
|
-
const report = await createReport(sc.dids.alice)
|
|
677
|
-
const before = await createActivity({
|
|
678
|
-
reportId: report.id,
|
|
679
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
680
|
-
internalNote: 'before',
|
|
681
|
-
})
|
|
682
|
-
// Small wait so the next activity's createdAt is strictly later.
|
|
683
|
-
await new Promise((r) => setTimeout(r, 50))
|
|
684
|
-
const cutoff = new Date().toISOString()
|
|
685
|
-
await new Promise((r) => setTimeout(r, 50))
|
|
686
|
-
const after = await createActivity({
|
|
687
|
-
reportId: report.id,
|
|
688
|
-
activity: { $type: `${DEFS}#noteActivity` },
|
|
689
|
-
internalNote: 'after',
|
|
690
|
-
})
|
|
691
|
-
|
|
692
|
-
const beforeRes = await queryActivities({
|
|
693
|
-
createdBefore: cutoff,
|
|
694
|
-
sortDirection: 'asc',
|
|
695
|
-
limit: 100,
|
|
696
|
-
})
|
|
697
|
-
const beforeIds = new Set(beforeRes.data.activities.map((a) => a.id))
|
|
698
|
-
expect(beforeIds.has(before.data.activity.id)).toBe(true)
|
|
699
|
-
expect(beforeIds.has(after.data.activity.id)).toBe(false)
|
|
700
|
-
|
|
701
|
-
const afterRes = await queryActivities({
|
|
702
|
-
createdAfter: cutoff,
|
|
703
|
-
sortDirection: 'asc',
|
|
704
|
-
limit: 100,
|
|
705
|
-
})
|
|
706
|
-
const afterIds = new Set(afterRes.data.activities.map((a) => a.id))
|
|
707
|
-
expect(afterIds.has(before.data.activity.id)).toBe(false)
|
|
708
|
-
expect(afterIds.has(after.data.activity.id)).toBe(true)
|
|
709
|
-
})
|
|
710
|
-
})
|
|
711
|
-
})
|