Skip to content

This repository contains an exercise to practice the Command-Query separation (CQS) design principle.

Notifications You must be signed in to change notification settings

lean-mind/cqs-booking-system

Repository files navigation

CQS Booking System

This repository contains an exercise to practice the Command-Query separation (CQS) design principle.

Purpose of the exercise

The objective of the exercise is to apply CQS in the use case of creating a hotel reservation: Modules\Booking\Application\Create\CreateBookingUseCase.ts. The Booking (Modules\Booking\Domain\Booking.ts) domain model is contaminated with data used in the view to display a booking confirmation message.

The view is an E2E test that can be found at Applications\__tests__\E2E\api\booking.test.ts. The E2E test represents the view and into it you will find the following assertion:

expect(
      `
      ${body.UserName}, Gracias por reservar con nosotros.
      Tu reserva en hotel ${body.HotelName} ha sido confirmada.

      Tu código de reserva es: ${body.Id}.

      Para cualquier consulta, puedes ponerte en contacto con el hotel llamando al ${body.HotelPhoneNumber}.
    `
    ).toEqual(
      `
      Luis, Gracias por reservar con nosotros.
      Tu reserva en hotel Palacio Real ha sido confirmada.

      Tu código de reserva es: booking-123.

      Para cualquier consulta, puedes ponerte en contacto con el hotel llamando al +34 954 987 321.
    `
    );

The E2E test cannot be changed and the confirmation message must always be the same.

Refactor the use case to decontaminate the domain model with data that is specifically for the view without breaking the view.

The use case and the controller are covered by unit tests, update them as necesary.

How to start

  • Install npm dependencies: npm install
  • Start the API using the command: npm run start
  • Run the tests: npm run test

About

This repository contains an exercise to practice the Command-Query separation (CQS) design principle.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published