Skip to content

add tests for workspace booking contract functionality#641

Merged
yusuftomilola merged 2 commits intoDistinctCodes:mainfrom
Tinna23:test/WorkspaceRegistrationTests
Mar 9, 2026
Merged

add tests for workspace booking contract functionality#641
yusuftomilola merged 2 commits intoDistinctCodes:mainfrom
Tinna23:test/WorkspaceRegistrationTests

Conversation

@Tinna23
Copy link
Contributor

@Tinna23 Tinna23 commented Mar 8, 2026

closes #608

Description:
This PR builds upon the foundational test setup to introduce comprehensive test coverage for the workspace registration flow in the workspace_booking smart contract. It verifies the happy path for creating a workspace, as well as the expected failure modes for duplicate entries and unauthorized access.

Key Changes:

  • Added test_register_workspace_success: * Initializes the contract and successfully registers a new workspace ("ws-001", "Hot Desk A", WorkspaceType::HotDesk, capacity 1, rate 500).

  • Verifies the state by querying get_workspace and asserting that all fields (name, workspace_type, capacity, hourly_rate, is_available) are correctly stored.

  • Asserts that get_all_workspaces().len() == 1.

  • Added test_register_workspace_duplicate_id_fails: * Verifies that attempting to register the exact same workspace ID ("ws-001") twice triggers a panic with the expected WorkspaceAlreadyExists = 5 error (Error(Contract, #5)).

  • Added test_register_workspace_non_admin_fails: * Generates a separate non_admin address and attempts to call register_workspace.

  • Ensures the contract panics with the expected Unauthorized = 2 error (Error(Contract, #2)).

  • Environment Setup: Utilized env.mock_all_auths() across tests to uniformly bypass authorization checks during testing.

Files Modified:

  • contracts/workspace_booking/src/test.rs

Acceptance Criteria Met:

  • All 5 tests (2 initialization + 3 registration) pass successfully using cargo test -p workspace_booking.
  • test_register_workspace_success correctly asserts all workspace fields.
  • test_register_workspace_duplicate_id_fails correctly catches the Error(Contract, #5) panic.
  • test_register_workspace_non_admin_fails correctly catches the Error(Contract, #2) panic.

@vercel
Copy link

vercel bot commented Mar 8, 2026

@Tinna23 is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@yusuftomilola yusuftomilola merged commit d4a038d into DistinctCodes:main Mar 9, 2026
2 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue #8 — Workspace Registration Tests

2 participants