Skip to content

Add @WebMvcTest slice test for FlashSaleController #5

Description

@piush365

Background

FlashSaleController is only covered today by the full-stack FlashSaleIntegrationTest. A @WebMvcTest slice test is much faster (< 1 s vs. > 30 s) and pinpoints controller-layer bugs — validation, HTTP status mapping, response body shape — without needing Redis, Kafka, or a database.

What to Test

@WebMvcTest(FlashSaleController.class)
class FlashSaleControllerTest {

    @MockBean FlashSaleService flashSaleService;

    @Test void buy_returns202_whenAccepted() { ... }
    @Test void buy_returns410_whenSoldOut() { ... }
    @Test void buy_returns429_whenRateLimited() { ... }
    @Test void buy_returns409_whenConcurrentBlock() { ... }
    @Test void buy_returns503_whenCircuitOpen() { ... }
    @Test void buy_returns500_whenError() { ... }
    @Test void buy_returns400_withBlankUserId() { ... }
    @Test void buy_returns401_withoutApiKey() { ... }
    @Test void responseBody_containsCorrelationId() { ... }
}

Notes

  • Mock FlashSaleService — no infrastructure needed.
  • ApiKeyAuthFilter must still be wired in (use the test API key from TestPropertySource).
  • Assert response JSON shape using jsonPath assertions.
  • This is a good first contribution — the controller logic is straightforward and well-documented.

Acceptance Criteria

  • All 9 test methods above are implemented and pass
  • Test runs in under 5 seconds
  • No real Redis, Kafka, or database connections made

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomers to the codebasetestingUnit, integration, concurrency, or load tests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions