-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import type { ContentCollectionKey } from 'astro:content'; | ||
import { expect, describe, it, vi } from 'vitest'; | ||
import { mockCommands, mockEvents, mockQueries, mockServices, mockChannels } from './mocks'; | ||
import { getChannels } from '@utils/channels'; | ||
|
||
vi.mock('astro:content', async (importOriginal) => { | ||
return { | ||
...(await importOriginal<typeof import('astro:content')>()), | ||
// this will only affect "foo" outside of the original module | ||
getCollection: (key: ContentCollectionKey) => { | ||
switch (key) { | ||
case 'services': | ||
return Promise.resolve(mockServices); | ||
case 'events': | ||
return Promise.resolve(mockEvents); | ||
case 'commands': | ||
return Promise.resolve(mockCommands); | ||
case 'channels': | ||
return Promise.resolve(mockChannels); | ||
case 'queries': | ||
return Promise.resolve(mockQueries); | ||
} | ||
}, | ||
}; | ||
}); | ||
|
||
describe('channels', () => { | ||
describe('getChannels', () => { | ||
it('returns an array of channels', async () => { | ||
const channels = await getChannels(); | ||
|
||
expect(channels).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
collection: 'channels', | ||
data: expect.objectContaining({ | ||
id: 'orders.{env}.events', | ||
version: '1.0.0', | ||
}), | ||
}), | ||
expect.objectContaining({ | ||
collection: 'channels', | ||
data: expect.objectContaining({ | ||
id: 'inventory.{env}.events', | ||
version: '1.0.0', | ||
}), | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
it('should returns an array of channels with messages', async () => { | ||
const channels = await getChannels(); | ||
|
||
expect(channels).toEqual( | ||
expect.arrayContaining([ | ||
/** OrderService */ | ||
expect.objectContaining({ | ||
id: 'orders.{env}.events', | ||
slug: 'orders.{env}.events', | ||
collection: 'channels', | ||
data: expect.objectContaining({ | ||
messages: [ | ||
{ | ||
id: 'OrderCreatedEvent', | ||
name: 'Order Created', | ||
version: '0.0.1', | ||
collection: 'events', | ||
}, | ||
{ | ||
id: 'GetOrder', | ||
name: 'Get Order', | ||
version: '0.0.1', | ||
collection: 'queries', | ||
}, | ||
], | ||
}), | ||
}), | ||
]) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
export const mockServices = [ | ||
{ | ||
id: 'services/Order/OrderService/index.mdx', | ||
slug: 'services/Order/OrderService', | ||
collection: 'services', | ||
data: { | ||
id: 'OrderService', | ||
version: '1.0.0', | ||
sends: [ | ||
{ | ||
id: 'OrderCreatedEvent', | ||
name: 'Order Created', | ||
version: '0.0.1', | ||
}, | ||
], | ||
receives: [ | ||
{ | ||
id: 'PaymentProcessed', | ||
name: 'Payment Processed', | ||
version: '0.0.1', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'services/Inventory/InventoryService/index.mdx', | ||
slug: 'services/Inventory/InventoryService', | ||
collection: 'services', | ||
data: { | ||
id: 'InventoryService', | ||
version: '1.0.0', | ||
receives: [ | ||
{ | ||
id: 'OrderCreatedEvent', | ||
name: 'Order Created', | ||
version: '^1.3.0', | ||
}, | ||
], | ||
sends: [ | ||
{ | ||
id: 'InventoryAdjusted', | ||
version: '~2', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'services/Payment/PaymentService/index.mdx', | ||
slug: 'services/Payment/PaymentService', | ||
collection: 'services', | ||
data: { | ||
id: 'PaymentService', | ||
version: '1.0.0', | ||
receives: [ | ||
{ | ||
id: 'OrderCreatedEvent', | ||
}, | ||
{ | ||
id: 'OrderDeletedEvent', | ||
}, | ||
], | ||
sends: [ | ||
{ | ||
id: 'PaymentPaid', | ||
}, | ||
{ | ||
id: 'PaymentFailed', | ||
version: 'latest', | ||
}, | ||
{ | ||
id: 'EmailVerified', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'services/Notifications/NotificationsService/index.mdx', | ||
slug: 'services/Notifications/NotificationsService', | ||
collection: 'services', | ||
data: { | ||
id: 'NotificationsService', | ||
version: '1.0.0', | ||
receives: [ | ||
{ | ||
id: 'OrderCreatedEvent', | ||
}, | ||
], | ||
sends: [ | ||
{ | ||
id: 'OrderCreatedEvent', | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
export const mockEvents = [ | ||
{ | ||
id: 'OrderCreatedEvent', | ||
slug: 'OrderCreatedEvent', | ||
collection: 'events', | ||
data: { | ||
id: 'OrderCreatedEvent', | ||
version: '0.0.1', | ||
name: 'Order Created', | ||
channels: [ | ||
{ | ||
id: 'orders.{env}.events', | ||
version: '1.0.0', | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
export const mockCommands = [ | ||
{ | ||
id: 'PaymentProcessed', | ||
slug: 'PaymentProcessed', | ||
collection: 'commands', | ||
data: { | ||
id: 'PaymentProcessed', | ||
version: '0.0.1', | ||
}, | ||
}, | ||
]; | ||
export const mockQueries = [ | ||
{ | ||
id: 'GetOrder', | ||
slug: 'GetOrder', | ||
collection: 'queries', | ||
data: { | ||
id: 'GetOrder', | ||
version: '0.0.1', | ||
name: 'Get Order', | ||
channels: [ | ||
{ | ||
id: 'orders.{env}.events', | ||
version: '1.0.0', | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
export const mockChannels = [ | ||
{ | ||
id: 'orders.{env}.events', | ||
slug: 'orders.{env}.events', | ||
collection: 'channels', | ||
data: { | ||
id: 'orders.{env}.events', | ||
version: '1.0.0', | ||
}, | ||
}, | ||
{ | ||
id: 'inventory.{env}.events', | ||
slug: 'inventory.{env}.events', | ||
collection: 'channels', | ||
data: { | ||
id: 'inventory.{env}.events', | ||
version: '1.0.0', | ||
}, | ||
}, | ||
]; |