BJ-13: Unit tests — Bitbucket + Jira adapters#
Summary#
Add Jest unit specs for BitbucketAdapter and JiraAdapter covering verifySignature(), normalize() for every supported event, bot-self filtering, and /agentsde directive detection. Mirror the structure of github.adapter.spec.ts.
Files#
| Path | Action | Purpose |
|---|---|---|
src/webhook/adapters/__fixtures__/bitbucket/*.json | create | Realistic payloads from Atlassian docs — one per event key (7 files) |
src/webhook/adapters/__fixtures__/jira/*.json | create | Realistic payloads from Atlassian docs — one per webhookEvent (5 files) |
src/webhook/adapters/bitbucket.adapter.spec.ts | create | Full spec for Bitbucket adapter |
src/webhook/adapters/jira.adapter.spec.ts | create | Full spec for Jira adapter |
src/webhook/adapters/github.adapter.spec.ts | inspect | Reference for structure, DI wiring, and assertion style |
Steps#
- Author Bitbucket fixture JSON files for the 7 supported
X-Event-Keys:pullrequest:created,pullrequest:updated,pullrequest:approved,pullrequest:changes_request_created,pullrequest:fulfilled,pullrequest:comment_created,repo:push. Source from Atlassian webhook docs. - Write
bitbucket.adapter.spec.tswith aTestingModulethat providesConfigService+PLATFORM_AUTH_PROVIDERmock returningAGENT_USERNAME. Cover: (a)verifySignature()— valid?secret=query, missing secret, wrong secret, disallowed IP whenBITBUCKET_WEBHOOK_IP_ALLOWLISTis set; (b)normalize()— oneitper event key asserting resultingeventType/issueNumber/prNumber/actor; (c)pullrequest:comment_createdby bot →{ event: null }with reason mentioningAGENT_USERNAME; (d)/agentsdedirective and legacy/agentdetection; (e) unsupportedX-Event-Key→{ event: null, reason }. - Author Jira fixture JSON files for the 5 supported
webhookEventvalues:jira:issue_created,jira:issue_updated(withchangelog),jira:issue_deleted,comment_created,jira:issuelink_created. Source from Atlassian webhook docs. - Write
jira.adapter.spec.tswith identical DI wiring. Cover: (a)verifySignature()— valid HMAC, missing header, bad signature, tampered body via the sharedverifyHmacSha256helper insrc/webhook/crypto.ts; (b)normalize()— oneitperwebhookEventasserting correcteventType; (c)jira:issue_updatedinspectschangelogfor label transitions; (d)comment_createdby bot →{ event: null }; (e)/agentsdedirective detection on comment events; (f) unsupportedwebhookEvent→{ event: null, reason }. - Run
npm run lintandnpm run test -- --testPathPattern 'adapters/(bitbucket|jira)'until green (zero warnings, all specs pass).
Verification#
- Every switch-case branch in both adapters has at least one dedicated spec.
npm run testpasses;npm run lintreports zero warnings.- Bot-self filter,
/agentsdedetection, and unsupported-event fallbacks are each exercised by a named test.
Risks#
- Depends on #546 and #547 merging first — without the adapter files, tests cannot compile. Delivery phase must wait until those adapters land on
rc/atlassian-integration. - Fixture shape drift: if the adapter implementations diverge from the documented event maps, specs will fail. Mitigate by sourcing fixtures from Atlassian docs rather than inventing fields.
Assumptions#
- Branch target is
rc/atlassian-integration(per issue). verifyHmacSha256helper exists atsrc/webhook/crypto.tsby the time tests run (extracted in #547).- Bot-self filter reads username from
PLATFORM_AUTH_PROVIDER.getBotUsername(), matching the pattern ingithub.adapter.ts:22.