Skip to content

Commit

Permalink
fix/service-node-graph-metadata (#964)
Browse files Browse the repository at this point in the history
* fix: replace getCollection by custom getter utilities

It replaces the astro's getCollection by custom getter collection
utilities (`getEvents`, `getCommands`, etc) which in turn hydrate
the message metadata such as consumers and producers needed by the
service node graph.

Resolve #842

* fix: add objectContaining to message nodes into domains node graph

* Create proud-jars-cough.md

---------

Co-authored-by: David Boyne <boyneyy123@gmail.com>
  • Loading branch information
carlosallexandre and boyney123 authored Nov 21, 2024
1 parent 848c654 commit 2ad9561
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-jars-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

fix(core): fixed issues with node graphs for services and metadata in the nodes
14 changes: 7 additions & 7 deletions src/utils/__tests__/domains/node-graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Domains NodeGraph', () => {
id: 'OrderPlaced-0.0.1',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[0] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[0].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
};
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('Domains NodeGraph', () => {
id: 'PlaceOrder-1.7.7',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockCommands[2] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockCommands[2].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'commands',
},
Expand All @@ -114,7 +114,7 @@ describe('Domains NodeGraph', () => {
id: 'OrderPlaced-0.0.1',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[0] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[0].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
},
Expand All @@ -134,31 +134,31 @@ describe('Domains NodeGraph', () => {
id: 'PaymentPaid-0.0.1',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[1] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[1].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
},
{
id: 'PaymentPaid-0.0.2',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[2] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[2].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
},
{
id: 'PaymentRefunded-1.0.0',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[4] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[4].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
},
{
id: 'PaymentFailed-1.0.0',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[6] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[6].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
},
Expand Down
14 changes: 14 additions & 0 deletions src/utils/__tests__/services/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const mockServices = [

export const mockEvents = [
{
id: 'events/OrderCreatedEvent/versioned/0.0.1/index.mdx',
slug: 'OrderCreatedEvent',
collection: 'events',
data: {
Expand All @@ -101,6 +102,7 @@ export const mockEvents = [
},
},
{
id: 'events/OrderCreatedEvent/versioned/1.0.0/index.mdx',
slug: 'OrderCreatedEvent',
collection: 'events',
data: {
Expand All @@ -109,6 +111,7 @@ export const mockEvents = [
},
},
{
id: 'events/OrderCreatedEvent/versioned/1.3.9/index.mdx',
slug: 'OrderCreatedEvent',
collection: 'events',
data: {
Expand All @@ -117,6 +120,7 @@ export const mockEvents = [
},
},
{
id: 'events/OrderCreatedEvent/index.mdx',
slug: 'OrderCreatedEvent',
collection: 'events',
data: {
Expand All @@ -125,6 +129,7 @@ export const mockEvents = [
},
},
{
id: 'events/OrderDeletedEvent/index.mdx',
slug: 'OrderDeletedEvent',
collection: 'events',
data: {
Expand All @@ -139,6 +144,7 @@ export const mockEvents = [
},
},
{
id: 'events/InventoryAdjusted/versioned/0.0.1/index.mdx',
slug: 'InventoryAdjusted',
collection: 'events',
data: {
Expand All @@ -147,6 +153,7 @@ export const mockEvents = [
},
},
{
id: 'events/InventoryAdjusted/versioned/1.0.0/index.mdx',
slug: 'InventoryAdjusted',
collection: 'events',
data: {
Expand All @@ -155,6 +162,7 @@ export const mockEvents = [
},
},
{
id: 'events/InventoryAdjusted/index.mdx',
slug: 'InventoryAdjusted',
collection: 'events',
data: {
Expand All @@ -164,6 +172,7 @@ export const mockEvents = [
},
// 7
{
id: 'events/PaymentPaid/versioned/1.0.0/index.mdx',
slug: 'PaymentPaid',
collection: 'events',
data: {
Expand All @@ -173,6 +182,7 @@ export const mockEvents = [
},
// 9
{
id: 'events/PaymentPaid/index.mdx',
slug: 'PaymentPaid',
collection: 'events',
data: {
Expand All @@ -182,6 +192,7 @@ export const mockEvents = [
},
// 10
{
id: 'events/PaymentFailed/versioned/1.0.0/index.mdx',
slug: 'PaymentFailed',
collection: 'events',
data: {
Expand All @@ -191,6 +202,7 @@ export const mockEvents = [
},
// 11
{
id: 'events/PaymentFailed/1.2.3/index.mdx',
slug: 'PaymentFailed',
collection: 'events',
data: {
Expand Down Expand Up @@ -218,6 +230,7 @@ export const mockEvents = [

export const mockCommands = [
{
id: 'commands/PaymentProcessed/index.mdx',
slug: 'PaymentProcessed',
collection: 'commands',
data: {
Expand All @@ -228,6 +241,7 @@ export const mockCommands = [
];
export const mockQueries = [
{
id: 'queries/GetOrder/index.mdx',
slug: 'GetOrder',
collection: 'queries',
data: {
Expand Down
52 changes: 46 additions & 6 deletions src/utils/__tests__/services/node-graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Services NodeGraph', () => {
type: 'commands',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockCommands[0] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockCommands[0].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
};

Expand All @@ -59,7 +59,7 @@ describe('Services NodeGraph', () => {
id: 'OrderCreatedEvent-0.0.1',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[0] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[0].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
};
Expand Down Expand Up @@ -115,6 +115,46 @@ describe('Services NodeGraph', () => {
expect(edges).toEqual(expectedEdges);
});

it('should return message nodes with producers and consumers for a given service', async () => {
const { nodes } = await getNodesAndEdges({ id: 'OrderService', version: '1.0.0' });

const expectedRecivesNode = {
id: 'PaymentProcessed-0.0.1',
type: 'commands',
data: expect.objectContaining({
message: expect.objectContaining({
data: expect.objectContaining({
consumers: [expect.objectContaining(mockServices[0])],
producers: expect.any(Array),
}),
}),
}),
};

const expectedSendsNode = {
id: 'OrderCreatedEvent-0.0.1',
type: 'events',
data: expect.objectContaining({
message: expect.objectContaining({
data: expect.objectContaining({
consumers: expect.any(Array),
producers: [expect.objectContaining(mockServices[0])],
}),
}),
}),
};

expect(nodes).toEqual(
expect.arrayContaining([
// Nodes on the left
expect.objectContaining(expectedRecivesNode),

// Nodes on the right
expect.objectContaining(expectedSendsNode),
])
);
});

it('if a message is sent and received by the same service it will render a custom edge', async () => {
const { nodes, edges } = await getNodesAndEdges({ id: 'NotificationsService', version: '1.0.0' });

Expand All @@ -134,7 +174,7 @@ describe('Services NodeGraph', () => {
type: 'events',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[3] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[3].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
};

Expand All @@ -143,7 +183,7 @@ describe('Services NodeGraph', () => {
id: 'OrderCreatedEvent-2.0.0',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[3] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[3].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
};
Expand Down Expand Up @@ -223,7 +263,7 @@ describe('Services NodeGraph', () => {
type: 'events',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[2] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[2].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
};

Expand All @@ -232,7 +272,7 @@ describe('Services NodeGraph', () => {
id: 'InventoryAdjusted-2.0.0',
sourcePosition: 'right',
targetPosition: 'left',
data: { mode: 'simple', message: mockEvents[7] },
data: { mode: 'simple', message: expect.objectContaining({ id: mockEvents[7].id }) },
position: { x: expect.any(Number), y: expect.any(Number) },
type: 'events',
};
Expand Down
12 changes: 8 additions & 4 deletions src/utils/node-graphs/services-node-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
import { findMatchingNodes, getItemsFromCollectionByIdAndSemverOrLatest } from '@utils/collections/util';
import { MarkerType } from 'reactflow';
import type { CollectionMessageTypes } from '@types';
import { getCommands } from '@utils/commands';
import { getEvents } from '@utils/events';
import { getQueries } from '@utils/queries';
import { getChannels } from '@utils/channels';

type DagreGraph = any;

Expand Down Expand Up @@ -67,10 +71,10 @@ export const getNodesAndEdges = async ({ id, defaultFlow, version, mode = 'simpl
const receivesRaw = service?.data.receives || [];
const sendsRaw = service?.data.sends || [];

const events = await getCollection('events');
const commands = await getCollection('commands');
const queries = await getCollection('queries');
const channels = await getCollection('channels');
const events = await getEvents();
const commands = await getCommands();
const queries = await getQueries();
const channels = await getChannels();

const messages = [...events, ...commands, ...queries];

Expand Down

0 comments on commit 2ad9561

Please sign in to comment.