Skip to content

Add comprehensive test suite (374 tests)#276

Merged
hhvrc merged 17 commits intodevelopfrom
feature/integration-tests
Apr 28, 2026
Merged

Add comprehensive test suite (374 tests)#276
hhvrc merged 17 commits intodevelopfrom
feature/integration-tests

Conversation

@hhvrc
Copy link
Copy Markdown
Contributor

@hhvrc hhvrc commented Feb 11, 2026

Summary

  • 126 integration tests across 16 test files covering all major API endpoints: account signup/login, devices, shockers, tokens, sessions, users, shares, SignalR hub negotiate, authorization/isolation
  • 248 unit tests with new coverage for HashingUtils, MathUtils, StringUtils, PermissionUtils, CryptoUtils, GravatarUtils, and expanded UsernameValidator boundary tests
  • Test infrastructure: TestHelper with direct DB/Redis user creation, auth helpers for session cookie/API token/hub token clients, rate limiting disabled in test host, Turnstile mock fix

Test plan

  • All 126 integration tests pass (dotnet test --project API.IntegrationTests)
  • All 248 unit tests pass (dotnet test --project Common.Tests)
  • Both projects build with zero warnings
  • CI pipeline passes

🤖 Generated with Claude Code

hhvrc and others added 2 commits February 11, 2026 13:18
New test files covering all major API endpoints:
- AccountSignup, AccountLogin, AccountAuthenticated
- Devices CRUD, Shockers CRUD, Tokens CRUD
- Sessions, Users, DeviceEndpoint (hub auth)
- Public endpoints, Authorization/isolation, RateLimiter

Infrastructure improvements:
- TestHelper with direct DB/Redis user creation (bypasses endpoints)
- Auth helpers for session cookie, API token, and hub token clients
- Rate limiting disabled in test host
- Cookie domain includes localhost for test server
- Fixed Turnstile mock DTO JSON property names

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unit tests (Common.Tests):
- MathUtils: Haversine distance calculations
- StringUtils: Truncate edge cases
- PermissionUtils: IsAllowed with all ControlType/permission combos
- CryptoUtils: random string length, charset, uniqueness
- GravatarUtils: URL format and email hashing
- HashingUtils: password hash/verify roundtrip, token hashing, algorithm detection
- UsernameValidator: boundary values, special characters

Integration tests (API.IntegrationTests):
- SignalRUserHubTests: negotiate endpoint auth (session, API token, hub token, invalid)
- ShareLinksTests: public share link CRUD, cross-user isolation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a comprehensive test suite with 374 tests covering both unit and integration testing for the OpenShock API. The PR implements test infrastructure including database/Redis helpers, authentication client factories, and Turnstile mock handling to enable efficient, isolated testing.

Changes:

  • Added 248 unit tests for utility classes (HashingUtils, MathUtils, StringUtils, PermissionUtils, CryptoUtils, GravatarUtils, UsernameValidator)
  • Added 126 integration tests covering all major API endpoints including account management, devices, shockers, tokens, sessions, users, shares, and SignalR
  • Implemented test infrastructure with TestHelper for direct DB/Redis operations, authentication client factories, and rate limiting disabled in test environment

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Directory.Packages.props Added SignalR.Client package for SignalR integration tests
API.IntegrationTests/API.IntegrationTests.csproj Added SignalR.Client package reference
Common.Tests/Validation/UsernameValidatorTests.cs Added 11 boundary tests for username validation edge cases
Common.Tests/Utils/StringUtilsTests.cs New test file with 6 tests for string truncation utility
Common.Tests/Utils/PermissionUtilsTests.cs New test file with 13 tests for permission checking logic
Common.Tests/Utils/MathUtilsTests.cs New test file with 7 tests for Haversine distance calculations
Common.Tests/Utils/HashingUtilsTests.cs Expanded with 165 new tests for password/token hashing
Common.Tests/Utils/GravatarUtilsTests.cs New test file with 5 tests for Gravatar URL generation
Common.Tests/Utils/CryptoUtilsTests.cs New test file with 6 tests for random string generation
API.IntegrationTests/WebApplicationFactory.cs Updated to disable rate limiting and add localhost to cookie domains
API.IntegrationTests/HttpMessageHandlers/InterceptedHttpMessageHandler.cs Added JSON property name attributes for Turnstile mock DTO
API.IntegrationTests/Helpers/TestHelper.cs New helper class providing user/device/token creation and authenticated client factories
API.IntegrationTests/Tests/AccountSignupTests.cs 9 tests for V1/V2 signup, validation, and duplicate handling
API.IntegrationTests/Tests/AccountLoginTests.cs 12 tests for V1/V2 login, Turnstile validation, and logout
API.IntegrationTests/Tests/AccountAuthenticatedTests.cs 6 tests for password/username changes
API.IntegrationTests/Tests/UsersTests.cs 5 tests for user self-retrieval and lookup endpoints
API.IntegrationTests/Tests/TokensTests.cs 13 tests for API token CRUD and authentication
API.IntegrationTests/Tests/SessionsTests.cs 5 tests for session management
API.IntegrationTests/Tests/DevicesTests.cs 14 tests for device CRUD, token regeneration, and cross-user isolation
API.IntegrationTests/Tests/DeviceEndpointTests.cs 6 tests for hub/device-authenticated endpoints
API.IntegrationTests/Tests/ShockersTests.cs 12 tests for shocker CRUD, pause/unpause functionality
API.IntegrationTests/Tests/ShareLinksTests.cs 9 tests for share link CRUD and cross-user isolation
API.IntegrationTests/Tests/SignalRUserHubTests.cs 7 tests for SignalR hub negotiate endpoint with various auth methods
API.IntegrationTests/Tests/AuthorizationTests.cs 13 tests for cross-cutting authorization and isolation
API.IntegrationTests/Tests/RateLimiterTests.cs 2 smoke tests verifying rate limiter middleware registration
API.IntegrationTests/Tests/PublicTests.cs 3 tests for public API endpoints

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread API.IntegrationTests/Tests/DeviceEndpointTests.cs Outdated
Comment thread API.IntegrationTests/Tests/AccountAuthenticatedTests.cs Outdated
Comment thread API.IntegrationTests/Tests/PublicTests.cs Outdated
Comment thread API.IntegrationTests/Tests/AccountAuthenticatedTests.cs Outdated
Comment thread API.IntegrationTests/Tests/DeviceEndpointTests.cs Outdated
Comment thread API.IntegrationTests/Tests/TokensTests.cs Outdated
hhvrc and others added 7 commits February 11, 2026 13:52
Cache BCrypt password hashes in TestHelper so each unique password is
only hashed once instead of ~100+ times. Add 30s per-test timeout as
a safety net.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Limit parallel test execution to ProcessorCount*2 (min 8) to prevent
thread pool starvation from synchronous BCrypt in login/signup endpoints.
Also bump per-test timeout to 60s and add coverage gitignore entries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@LucHeart
Copy link
Copy Markdown
Member

should have claude fix these at some point

hhvrc added 7 commits April 28, 2026 10:31
- Bump package versions to match develop (Microsoft.AspNetCore.* 10.0.7,
  Hangfire.PostgreSql 1.21.1, MailKit 4.16.0, Testcontainers 4.11.0,
  TUnit 1.39.0, and others)
- Bump Microsoft.Testing.Extensions.CodeCoverage to 18.6.2 (required by TUnit 1.39.0)
- Keep Microsoft.AspNetCore.SignalR.Client 10.0.7 from this branch
- Keep Microsoft.Testing.Extensions.CodeCoverage from this branch
- Keep integration-test rate-limiter disable logic in OpenShockServiceHelper.cs
- Add InMemoryMailpit Testcontainers helper (axllent/mailpit image)
- Add MailpitHelper for polling the Mailpit HTTP API
- Add TestSmtpEmailService: synchronous IEmailService replacing the
  fire-and-forget SmtpEmailService so API endpoints return only after
  email delivery, making assertions deterministic; also fixes the
  MemoryStream position bug (buffer.Position = 0 before MimeContent)
- Add MailTests with 5 tests: signup activation email sent, full
  activation-via-email-link flow, V1/V2 password reset email sent,
  full password-reset-via-email-link flow
- Remove dead Mailjet mock from InterceptedHttpMessageHandler
- Switch WebApplicationFactory from MAILJET type to SMTP pointing at
  Mailpit container; inject TestSmtpEmailService in ConfigureTestServices

All 131 integration tests pass (126 original + 5 new mail tests).
- Remove fire-and-forget (SendMailAndForget / OsTask.Run); all three
  public methods now directly await SendMail so callers only return
  after the email has been handed off to the SMTP server
- Reset buffer.Position = 0 before passing the MemoryStream to
  MimeContent, fixing the empty-body bug (stream was at end after
  template rendering)
- Skip AuthenticateAsync when the server does not advertise AUTH
  capability (e.g. Mailpit), avoiding an unnecessary error
- Remove TestSmtpEmailService workaround from integration tests since
  the production service now behaves correctly
CI cold-start (Docker image pull + EF migrations) can consume most of the
60-second window before any test logic runs, causing the first test to
time out. 3 minutes gives enough headroom for slow CI runners.
@hhvrc hhvrc requested a review from Copilot April 28, 2026 11:43
@hhvrc hhvrc merged commit 1e386d0 into develop Apr 28, 2026
11 of 12 checks passed
@hhvrc hhvrc deleted the feature/integration-tests branch April 28, 2026 11:48
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.

3 participants