AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-554
  5. plan
  6. plan.md
plan.md(3.1 KB)· Apr 23, 2026· 2 min read
  • Summary
  • Files
  • Steps
  • Verification
  • Risks
  • Open Questions

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#

PathActionPurpose
package.jsonmodifyAdd nock to devDependencies (acceptance criterion mandates nock)
src/bitbucket/bitbucket.service.spec.tscreateTests for all 18 public methods on BitbucketService
src/jira/jira.service.spec.tscreateTests for all 11 public methods on JiraService

Steps#

  1. Add nock to devDependencies in package.json and run npm install.
  2. Author src/bitbucket/bitbucket.service.spec.ts: Nest TestingModule with a mocked PLATFORM_AUTH_PROVIDER (getToken returns 'bb_test_token'); stub internal sleep to avoid real delays; enable nock.disableNetConnect() in beforeAll, nock.cleanAll() in afterEach; one happy-path test per public method asserting URL, HTTP method, request body; shared cross-cutting tests: Bearer header sourced from authProvider.getToken(), 429 with Retry-After: 2 waits then retries, 401 triggers getToken() refresh then retries once (second 401 bubbles up), 5xx throws without retry.
  3. Author src/jira/jira.service.spec.ts: same test scaffold as step 2 against base URL https://api.atlassian.com/ex/jira/${JIRA_CLOUD_ID}; set JIRA_CLOUD_ID via process.env in beforeEach and restore in afterEach; 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.
  4. Run npm run lint (zero warnings) and npm run test — both spec files pass; nock.isDone() passes on every test.

Verification#

  • npm run test -- bitbucket.service.spec and npm run test -- jira.service.spec both green.
  • npm run lint produces no warnings for the new files.
  • authProvider.getToken mock is called at least once per request test; no real HTTP is allowed through nock.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-integration branch once #548/#549 land, or rebase after they merge.
  • Convention deviation: existing github.service.spec.ts uses jest.spyOn(globalThis, 'fetch') rather than nock. The issue's acceptance criteria explicitly names nock, 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-After support HTTP-date format, or only integer seconds? Assumption: integer seconds only (matches GitHubService.request() at github.service.ts:549).
ContextPrd