diff --git a/.changeset/proud-jars-cough.md b/.changeset/proud-jars-cough.md new file mode 100644 index 00000000..7def984e --- /dev/null +++ b/.changeset/proud-jars-cough.md @@ -0,0 +1,5 @@ +--- +"@eventcatalog/core": patch +--- + +fix(core): fixed issues with node graphs for services and metadata in the nodes diff --git a/src/utils/__tests__/domains/node-graph.spec.ts b/src/utils/__tests__/domains/node-graph.spec.ts index 6de3a459..2b3d46b7 100644 --- a/src/utils/__tests__/domains/node-graph.spec.ts +++ b/src/utils/__tests__/domains/node-graph.spec.ts @@ -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', }; @@ -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', }, @@ -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', }, @@ -134,7 +134,7 @@ 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', }, @@ -142,7 +142,7 @@ describe('Domains NodeGraph', () => { 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', }, @@ -150,7 +150,7 @@ describe('Domains NodeGraph', () => { 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', }, @@ -158,7 +158,7 @@ describe('Domains NodeGraph', () => { 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', }, diff --git a/src/utils/__tests__/services/mocks.ts b/src/utils/__tests__/services/mocks.ts index ccbdd6ff..18dc450b 100644 --- a/src/utils/__tests__/services/mocks.ts +++ b/src/utils/__tests__/services/mocks.ts @@ -93,6 +93,7 @@ export const mockServices = [ export const mockEvents = [ { + id: 'events/OrderCreatedEvent/versioned/0.0.1/index.mdx', slug: 'OrderCreatedEvent', collection: 'events', data: { @@ -101,6 +102,7 @@ export const mockEvents = [ }, }, { + id: 'events/OrderCreatedEvent/versioned/1.0.0/index.mdx', slug: 'OrderCreatedEvent', collection: 'events', data: { @@ -109,6 +111,7 @@ export const mockEvents = [ }, }, { + id: 'events/OrderCreatedEvent/versioned/1.3.9/index.mdx', slug: 'OrderCreatedEvent', collection: 'events', data: { @@ -117,6 +120,7 @@ export const mockEvents = [ }, }, { + id: 'events/OrderCreatedEvent/index.mdx', slug: 'OrderCreatedEvent', collection: 'events', data: { @@ -125,6 +129,7 @@ export const mockEvents = [ }, }, { + id: 'events/OrderDeletedEvent/index.mdx', slug: 'OrderDeletedEvent', collection: 'events', data: { @@ -139,6 +144,7 @@ export const mockEvents = [ }, }, { + id: 'events/InventoryAdjusted/versioned/0.0.1/index.mdx', slug: 'InventoryAdjusted', collection: 'events', data: { @@ -147,6 +153,7 @@ export const mockEvents = [ }, }, { + id: 'events/InventoryAdjusted/versioned/1.0.0/index.mdx', slug: 'InventoryAdjusted', collection: 'events', data: { @@ -155,6 +162,7 @@ export const mockEvents = [ }, }, { + id: 'events/InventoryAdjusted/index.mdx', slug: 'InventoryAdjusted', collection: 'events', data: { @@ -164,6 +172,7 @@ export const mockEvents = [ }, // 7 { + id: 'events/PaymentPaid/versioned/1.0.0/index.mdx', slug: 'PaymentPaid', collection: 'events', data: { @@ -173,6 +182,7 @@ export const mockEvents = [ }, // 9 { + id: 'events/PaymentPaid/index.mdx', slug: 'PaymentPaid', collection: 'events', data: { @@ -182,6 +192,7 @@ export const mockEvents = [ }, // 10 { + id: 'events/PaymentFailed/versioned/1.0.0/index.mdx', slug: 'PaymentFailed', collection: 'events', data: { @@ -191,6 +202,7 @@ export const mockEvents = [ }, // 11 { + id: 'events/PaymentFailed/1.2.3/index.mdx', slug: 'PaymentFailed', collection: 'events', data: { @@ -218,6 +230,7 @@ export const mockEvents = [ export const mockCommands = [ { + id: 'commands/PaymentProcessed/index.mdx', slug: 'PaymentProcessed', collection: 'commands', data: { @@ -228,6 +241,7 @@ export const mockCommands = [ ]; export const mockQueries = [ { + id: 'queries/GetOrder/index.mdx', slug: 'GetOrder', collection: 'queries', data: { diff --git a/src/utils/__tests__/services/node-graph.spec.ts b/src/utils/__tests__/services/node-graph.spec.ts index f20ad1a3..5d6c7c32 100644 --- a/src/utils/__tests__/services/node-graph.spec.ts +++ b/src/utils/__tests__/services/node-graph.spec.ts @@ -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) }, }; @@ -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', }; @@ -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' }); @@ -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) }, }; @@ -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', }; @@ -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) }, }; @@ -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', }; diff --git a/src/utils/node-graphs/services-node-graph.ts b/src/utils/node-graphs/services-node-graph.ts index bb9c1a30..21e2a6be 100644 --- a/src/utils/node-graphs/services-node-graph.ts +++ b/src/utils/node-graphs/services-node-graph.ts @@ -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; @@ -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];