CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/separation-of-concerns

Enforce strict three-layer architecture: thin HTTP routes, pure service logic with domain errors, isolated data access with dependency injection.

94

1.08x
Quality

93%

Does it follow best practices?

Impact

97%

1.08x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-2/

Notification Service — Unit Test Setup

Problem/Feature Description

A SaaS platform sends email notifications when users complete certain actions (password reset, subscription renewal, account suspension). The engineering team is trying to increase test coverage but is hitting a wall: the notification service directly imports a SendGrid client module at the top of the file, which means every test that touches notification logic actually tries to send real emails (or fails trying to connect). Similarly, the service imports the user repository directly, requiring a live database connection in tests.

A developer has been asked to refactor the notification service so that it can be fully unit tested without any real email sending or database access. They should also write a small set of unit tests demonstrating that the service works correctly with mocked dependencies.

The notifications being covered are:

  • sendPasswordReset(userId) — looks up the user, sends a password reset email
  • sendSubscriptionRenewal(userId, planName) — looks up the user, sends a renewal confirmation email
  • suspendAccount(userId, reason) — looks up the user, marks the account suspended in the database, sends a suspension notification email

Output Specification

Produce:

  • src/services/notificationService.ts — Refactored notification service
  • src/repositories/userRepo.ts — User data access interface and a stub/in-memory implementation
  • src/routes/notifications.ts — Thin HTTP handlers for triggering the notifications above
  • tests/notificationService.test.ts — Unit tests for the three notification methods using mocked dependencies (use any test framework you prefer)
  • wiring.ts — Shows how the service would be constructed with real dependencies for production use

The tests should pass without requiring network access or a real database.

evals

tile.json