or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

Order Service Mock Responses

Build a helper that defines mock HTTP responses for an order API at a given base URL. Each priming method should affect the next matching request only. cleanup() removes any remaining interceptors.

Capabilities

Health check success

  • After priming a health check response, the next GET request to /health returns status 200, JSON body {"status":"ok"}, and includes header x-mock: health. @test

Dynamic order creation

  • Priming an order creation reply with amount and currency causes the next POST to /orders with a JSON body including those fields to return status 201 and a JSON body containing a generated non-empty id plus the provided amount and currency. @test

Request-level failure

  • Priming an order creation error with a message causes the next POST to /orders missing the amount to fail at the request layer with that message (no HTTP status code is received). @test

Service outage response

  • Priming an outage for a specific order id causes the next GET to /orders/{id} to return status 503, a JSON body {"error":"outage"}, and a retry-after header of 120. @test

Implementation

@generates

API

export interface OrderReplyInput {
  amount: number;
  currency: string;
}

export interface OrderReply extends OrderReplyInput {
  id: string;
}

export interface MockOrderService {
  prepareHealthCheck(): void;
  queueOrderReply(payload: OrderReplyInput): void;
  queueOrderError(message: string): void;
  queueOutage(orderId: string): void;
  cleanup(): void;
}

export function createMockOrderService(baseUrl: string): MockOrderService;

Dependencies { .dependencies }

nock { .dependency }

Provides HTTP interception and mock responses.