BJ-14: Unit tests — Bitbucket + Jira services#
Summary#
Add unit test coverage for BitbucketService (#548) and JiraService (#549) on branch rc/atlassian-integration. Tests assert URL/method/body per public method, cover 429 Retry-After retry, 401 token-refresh retry, 5xx bubble-up, and Bearer auth header — all with no real network calls.
Files#
| Path | Action | Purpose |
|---|---|---|
package.json | modify | Add nock to devDependencies (acceptance criterion mandates nock) |
src/bitbucket/bitbucket.service.spec.ts | create | Tests for all 18 public methods on BitbucketService |
src/jira/jira.service.spec.ts | create | Tests for all 11 public methods on JiraService |
Steps#
- Add
nocktodevDependenciesinpackage.jsonand runnpm install. - Author
src/bitbucket/bitbucket.service.spec.ts: NestTestingModulewith a mockedPLATFORM_AUTH_PROVIDER(getTokenreturns'bb_test_token'); stub internalsleepto avoid real delays; enablenock.disableNetConnect()inbeforeAll,nock.cleanAll()inafterEach; one happy-path test per public method asserting URL, HTTP method, request body; shared cross-cutting tests:Bearerheader sourced fromauthProvider.getToken(), 429 withRetry-After: 2waits then retries, 401 triggersgetToken()refresh then retries once (second 401 bubbles up), 5xx throws without retry. - Author
src/jira/jira.service.spec.ts: same test scaffold as step 2 against base URLhttps://api.atlassian.com/ex/jira/${JIRA_CLOUD_ID}; setJIRA_CLOUD_IDviaprocess.envinbeforeEachand restore inafterEach; one happy-path test per public method (postComment,editComment,transitionIssue,getTransitions,addLabel,removeLabel,setAssignee,setPriority,linkIssues,searchJql,getIssue) plus the four shared cross-cutting tests. - Run
npm run lint(zero warnings) andnpm run test— both spec files pass;nock.isDone()passes on every test.
Verification#
npm run test -- bitbucket.service.specandnpm run test -- jira.service.specboth green.npm run lintproduces no warnings for the new files.authProvider.getTokenmock is called at least once per request test; no real HTTP is allowed throughnock.disableNetConnect().
Risks#
- Dependency order: #548 and #549 are still OPEN. These specs import the real services; if the service APIs diverge from the issue contracts, tests will fail until signatures are reconciled. Mitigation: author on top of the same
rc/atlassian-integrationbranch once #548/#549 land, or rebase after they merge. - Convention deviation: existing
github.service.spec.tsusesjest.spyOn(globalThis, 'fetch')rather thannock. The issue's acceptance criteria explicitly namesnock, so we follow the issue and accept the new test dependency.
Open Questions#
- On a second consecutive 401 after a token refresh, does the service bubble up or keep retrying? Assumption: bubble up (matches edge-case note in issue).
- Does
Retry-Aftersupport HTTP-date format, or only integer seconds? Assumption: integer seconds only (matchesGitHubService.request()atgithub.service.ts:549).