Skip to content

Commit

Permalink
more tests...
Browse files Browse the repository at this point in the history
  • Loading branch information
idugalic committed Nov 1, 2024
1 parent 6434c0f commit 624373f
Showing 1 changed file with 97 additions and 1 deletion.
98 changes: 97 additions & 1 deletion lib/domain_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ const changeRestaurantMenuCommandJson = `
}
`;

const placeOrderCommandJson = `
{
"commandId": "691490bb-c4d3-45b8-99d0-efcf20e353ag",
"decider": "Restaurant",
"kind": "PlaceOrderCommand",
"id": "691490bb-c4d3-45b8-99d0-efcf20e353ao",
"orderId": "691490bb-c4d3-45b8-99d0-efcf20e353ag",
"menuItems": [
{"menuItemId": "1", "name": "Salad2", "price": "18.59"},
{"menuItemId": "2", "name": "Soup2", "price": "16.94"},
{"menuItemId": "3", "name": "Steak2", "price": "19.89"}
]
}
`;

// Json representation of the expected event(s)
const restaurantMenuChangedEventJson = `
{
Expand All @@ -88,6 +103,38 @@ const restaurantMenuChangedEventJson = `
}
`;

const restaurantOrderPlacedEventJson = `
{
"version": 1,
"decider": "Restaurant",
"kind": "RestaurantOrderPlacedEvent",
"id": "691490bb-c4d3-45b8-99d0-efcf20e353ao",
"orderId": "691490bb-c4d3-45b8-99d0-efcf20e353ag",
"menuItems": [
{"menuItemId": "1", "name": "Salad2", "price": "18.59"},
{"menuItemId": "2", "name": "Soup2", "price": "16.94"},
{"menuItemId": "3", "name": "Steak2", "price": "19.89"}
],
"final": false
}
`;
const restaurantOrderNotPlacedEventJson = `
{
"version": 1,
"decider": "Restaurant",
"kind": "RestaurantOrderNotPlacedEvent",
"id": "691490bb-c4d3-45b8-99d0-efcf20e353ao",
"orderId": "691490bb-c4d3-45b8-99d0-efcf20e353ag",
"menuItems": [
{"menuItemId": "1", "name": "Salad2", "price": "18.59"},
{"menuItemId": "2", "name": "Soup2", "price": "16.94"},
{"menuItemId": "3", "name": "Steak2", "price": "19.89"}
],
"final": false,
"reason": "Restaurant does not exist!"
}
`;

// The Decider test for the restaurant create command
Deno.test(function createRestaurantDeciderTest() {
// Parse the restaurant command from the request / Zod validation/parsing
Expand Down Expand Up @@ -136,6 +183,55 @@ Deno.test(function changeRestaurantMenuDeciderTest() {
.then([restaurantMenuChangedEvent]);
});

// The Decider test for the restaurant place order command
Deno.test(function placeOrderAtRestaurantDeciderTest() {
// Parse the restaurant command from the request / Zod validation/parsing
const placeOrderCommand: RestaurantCommand = restaurantCommandSchema
.parse(
JSON.parse(placeOrderCommandJson),
);

// Parse the restaurant event.
const restaurantCreatedEvent: RestaurantEvent = restaurantEventSchema
.parse(
JSON.parse(restaurantCreatedEventJson),
);

// Parse the restaurant event.
const restaurantOrderPlacedEvent: RestaurantEvent = restaurantEventSchema
.parse(
JSON.parse(restaurantOrderPlacedEventJson),
);

// Run the second test specification for the restaurant decider
DeciderSpecification.for(restaurantDecider)
.given([restaurantCreatedEvent])
.when(placeOrderCommand)
.then([restaurantOrderPlacedEvent]);
});

// The Decider test for the restaurant place order command
Deno.test(function placeOrderAtRestaurantWithErrorDeciderTest() {
// Parse the restaurant command from the request / Zod validation/parsing
const placeOrderCommand: RestaurantCommand = restaurantCommandSchema
.parse(
JSON.parse(placeOrderCommandJson),
);

// Parse the restaurant event.
const restaurantOrderNotPlacedEvent: RestaurantEvent = restaurantEventSchema
.parse(
JSON.parse(restaurantOrderNotPlacedEventJson),
);

// Run the second test specification for the restaurant decider
DeciderSpecification.for(restaurantDecider)
// Given NO restaurant previously created!!!
.given([])
.when(placeOrderCommand)
.then([restaurantOrderNotPlacedEvent]);
});

Deno.test(function reastaurantCreatedViewTest() {
// Parse the restaurant event.
const restaurantCreatedEvent: RestaurantEvent = restaurantEventSchema
Expand All @@ -160,7 +256,7 @@ Deno.test(function reastaurantCreatedViewTest() {
});
});

Deno.test(function rrestaurantMenuChangedViewTest() {
Deno.test(function restaurantMenuChangedViewTest() {
// Parse the restaurant event.
const restaurantCreatedEvent: RestaurantEvent = restaurantEventSchema
.parse(
Expand Down

0 comments on commit 624373f

Please sign in to comment.