Skip to content

test: add comprehensive Context model tests (fixes #2016)#2169

Open
gavin913427-hash wants to merge 1 commit intoasyncapi:masterfrom
gavin913427-hash:feat/improve-model-test-coverage
Open

test: add comprehensive Context model tests (fixes #2016)#2169
gavin913427-hash wants to merge 1 commit intoasyncapi:masterfrom
gavin913427-hash:feat/improve-model-test-coverage

Conversation

@gavin913427-hash
Copy link
Copy Markdown

What

Add comprehensive tests for the Context model to improve test coverage.

Why

The Context model (lib/domains/models/Context.ts) had low test coverage. Many helper methods and error-handling branches were not exercised by the existing test suite.

How

  • Created test/unit/models/context.test.ts with 14 test cases
  • Covers all public functions: initContext, loadContext, addContext, removeContext, setCurrentContext, getContext, loadContextFile
  • Tests both success paths and error paths (not found, already exists, empty file)
  • Tests edge cases (~, ., ./ paths for initContext)

Changes

File Change
test/unit/models/context.test.ts NEW: 14 tests for Context model

Test Coverage

  • initContext(): 3 tests (~, ., normal path)
  • loadContext(): 4 tests (named, current, not found, missing current)
  • addContext(): 2 tests (success, duplicate)
  • removeContext(): 2 tests (success, not found)
  • setCurrentContext(): 2 tests (success, not found)
  • getContext(): 2 tests (success, not found)
  • loadContextFile(): 2 tests (success, empty file)

Fixes #2016

Add tests for Context model covering:
- initContext() with different paths (~, .)
- loadContext() with named and current contexts
- addContext() with duplicate detection
- removeContext() with not-found handling
- setCurrentContext() validation
- getContext() retrieval
- loadContextFile() with empty file handling

Improves test coverage for lib/domains/models/Context.ts

Fixes asyncapi#2016
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 4, 2026

⚠️ No Changeset found

Latest commit: 502838c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

[TEST] : low coverage in lib/domains/models

1 participant