@eventcatalog/core 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/README.md +11 -0
- package/bin/eventcatalog.js +125 -0
- package/components/BreadCrumbs.tsx +50 -0
- package/components/ContentView.tsx +127 -0
- package/components/Footer.tsx +38 -0
- package/components/Grids/EventGrid.tsx +89 -0
- package/components/Grids/ServiceGrid.tsx +70 -0
- package/components/Header.tsx +59 -0
- package/components/Mdx/Admonition.tsx +33 -0
- package/components/Mdx/Examples.tsx +77 -0
- package/components/Mermaid/index.tsx +47 -0
- package/components/NotFound/index.tsx +44 -0
- package/components/Sidebars/EventSidebar.tsx +202 -0
- package/components/Sidebars/ServiceSidebar.tsx +198 -0
- package/components/SyntaxHighlighter.tsx +34 -0
- package/hooks/EventCatalog.tsx +35 -0
- package/lib/__tests__/assets/events/AddedItemToCart/index.md +19 -0
- package/lib/__tests__/assets/events/EmailSent/index.md +15 -0
- package/lib/__tests__/assets/events/EventWithSchemaAndExamples/examples/Basic.cs +31 -0
- package/lib/__tests__/assets/events/EventWithSchemaAndExamples/examples/Basic.js +1 -0
- package/lib/__tests__/assets/events/EventWithSchemaAndExamples/index.md +8 -0
- package/lib/__tests__/assets/events/EventWithSchemaAndExamples/schema.json +4 -0
- package/lib/__tests__/assets/events/EventWithVersions/index.md +10 -0
- package/lib/__tests__/assets/events/EventWithVersions/versioned/0.0.1/index.md +10 -0
- package/lib/__tests__/assets/services/Email Platform/index.md +17 -0
- package/lib/__tests__/events.spec.ts +294 -0
- package/lib/__tests__/file-reader.spec.ts +57 -0
- package/lib/__tests__/graphs.spec.ts +62 -0
- package/lib/__tests__/services.spec.ts +144 -0
- package/lib/events.ts +221 -0
- package/lib/file-reader.ts +52 -0
- package/lib/graphs.ts +33 -0
- package/lib/services.ts +72 -0
- package/next-env.d.ts +5 -0
- package/next.config.js +3 -0
- package/package.json +52 -0
- package/pages/_app.tsx +49 -0
- package/pages/api/event/[name]/download.js +25 -0
- package/pages/events/[name]/logs.tsx +170 -0
- package/pages/events/[name]/v/[version].tsx +19 -0
- package/pages/events/[name].tsx +139 -0
- package/pages/events.tsx +227 -0
- package/pages/index.tsx +47 -0
- package/pages/overview.tsx +80 -0
- package/pages/services/[name].tsx +102 -0
- package/pages/services.tsx +123 -0
- package/pages/users/[id].tsx +83 -0
- package/postcss.config.js +6 -0
- package/public/favicon.ico +0 -0
- package/public/logo-random.svg +114 -0
- package/public/logo.svg +44 -0
- package/public/opengraph.png +0 -0
- package/scripts/__tests__/assets/eventcatalog.config.js +33 -0
- package/scripts/__tests__/generate.spec.ts +39 -0
- package/scripts/generate.js +28 -0
- package/styles/Home.module.css +116 -0
- package/styles/globals.css +48 -0
- package/tailwind.config.js +16 -0
- package/tsconfig.json +38 -0
- package/types/index.ts +7 -0
- package/utils/random-bg.ts +13 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
public static async Task ConnectAsync()
|
|
2
|
+
{
|
|
3
|
+
string clientId = Guid.NewGuid().ToString();
|
|
4
|
+
string mqttURI = {REPLACE THIS WITH YOUR MQTT SERVER URI HERE}
|
|
5
|
+
string mqttUser = { REPLACE THIS WITH YOUR MQTT USER HERE }
|
|
6
|
+
string mqttPassword = { REPLACE THIS WITH YOUR MQTT PASSWORD HERE }
|
|
7
|
+
int mqttPort = { REPLACE THIS WITH YOUR MQTT PORT HERE }
|
|
8
|
+
bool mqttSecure = {IF YOU ARE USING SSL Port THEN SET true OTHERWISE SET false}
|
|
9
|
+
|
|
10
|
+
var messageBuilder = new MqttClientOptionsBuilder()
|
|
11
|
+
.WithClientId(clientId)
|
|
12
|
+
.WithCredentials(mqttUser, mqttPassword)
|
|
13
|
+
.WithTcpServer(mqttURI, mqttPort)
|
|
14
|
+
.WithCleanSession();
|
|
15
|
+
|
|
16
|
+
var options = mqttSecure
|
|
17
|
+
? messageBuilder
|
|
18
|
+
.WithTls()
|
|
19
|
+
.Build()
|
|
20
|
+
: messageBuilder
|
|
21
|
+
.Build();
|
|
22
|
+
|
|
23
|
+
var managedOptions = new ManagedMqttClientOptionsBuilder()
|
|
24
|
+
.WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
|
|
25
|
+
.WithClientOptions(options)
|
|
26
|
+
.Build();
|
|
27
|
+
|
|
28
|
+
client = new MqttFactory().CreateManagedMqttClient();
|
|
29
|
+
|
|
30
|
+
await client.StartAsync(managedOptions);
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default true;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: EventWithVersions
|
|
3
|
+
version: 0.0.5
|
|
4
|
+
summary: |
|
|
5
|
+
Tells us when an email has been sent
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
Duis mollis quam enim, feugiat porta mi porta non. In lacus nulla, gravida nec sagittis vel, sagittis id tellus. Vestibulum maximus velit eget massa pulvinar ornare. In vel libero nulla. Aliquam a leo risus. Donec bibendum velit non nulla sollicitudin lacinia. Vestibulum imperdiet nunc eget neque sagittis, eget volutpat purus ornare. Mauris malesuada finibus pretium. Vestibulum suscipit tortor sit amet dolor tempor cursus. Nunc ac felis accumsan.
|
|
9
|
+
|
|
10
|
+
<Mermaid />
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: Email Platform
|
|
3
|
+
name: Email Platform
|
|
4
|
+
summary: |
|
|
5
|
+
Internal Email system. Used to send emails to 1000s of customers. Hosted in AWS
|
|
6
|
+
owners:
|
|
7
|
+
- dboyne
|
|
8
|
+
repository:
|
|
9
|
+
url: 'https://github.com/boyney123/EmailPlatform'
|
|
10
|
+
language: JavaScript
|
|
11
|
+
tags:
|
|
12
|
+
- label: defaultContentType:application/json
|
|
13
|
+
- label: Apache 2.0
|
|
14
|
+
url: https://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# Testing
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import {
|
|
4
|
+
getAllEvents,
|
|
5
|
+
getEventByName,
|
|
6
|
+
getUniqueServicesNamesFromEvents,
|
|
7
|
+
getAllEventsByOwnerId,
|
|
8
|
+
getAllEventsThatHaveRelationshipWithService,
|
|
9
|
+
} from '../events';
|
|
10
|
+
|
|
11
|
+
let PROJECT_DIR: any;
|
|
12
|
+
|
|
13
|
+
describe('events lib', () => {
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
PROJECT_DIR = process.env.PROJECT_DIR;
|
|
16
|
+
process.env.PROJECT_DIR = path.join(__dirname, 'assets');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterAll(() => {
|
|
20
|
+
process.env.PROJECT_DIR = PROJECT_DIR;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('getEventByName', () => {
|
|
24
|
+
it('returns an event and markdown by the given event name', async () => {
|
|
25
|
+
const { event, markdown } = await getEventByName('AddedItemToCart');
|
|
26
|
+
|
|
27
|
+
expect(event).toEqual({
|
|
28
|
+
name: 'AddedItemToCart',
|
|
29
|
+
version: '0.0.1',
|
|
30
|
+
summary:
|
|
31
|
+
'Holds information about the cusomer and product when they add an item to the cart.\n',
|
|
32
|
+
producers: ['Shopping API', 'Application API'],
|
|
33
|
+
consumers: ['Customer Portal'],
|
|
34
|
+
owners: ['dboyne', 'mSmith'],
|
|
35
|
+
historicVersions: [],
|
|
36
|
+
schema: null,
|
|
37
|
+
examples: [],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
expect(markdown.content).toMatchMarkdown('# Testing');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('returns the schema and examples of the event as empty if no schema or examples are found', async () => {
|
|
45
|
+
const { event } = await getEventByName('AddedItemToCart');
|
|
46
|
+
|
|
47
|
+
expect(event.schema).toEqual(null);
|
|
48
|
+
expect(event.examples).toEqual([]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('returns the schema if there is a `schema` file is found in directory of the event', async () => {
|
|
52
|
+
const { event } = await getEventByName('EventWithSchemaAndExamples');
|
|
53
|
+
|
|
54
|
+
const schema = `{
|
|
55
|
+
"some-schema": true,
|
|
56
|
+
"does-not-really-matter-what-content-is-in-this-file": true
|
|
57
|
+
}`;
|
|
58
|
+
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
expect(event.schema.snippet).toMatchMarkdown(schema);
|
|
61
|
+
expect(event.schema.language).toEqual('json');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('returns all event examples (files) when examples directory is found within the event folder', async () => {
|
|
65
|
+
const { event } = await getEventByName('EventWithSchemaAndExamples');
|
|
66
|
+
|
|
67
|
+
const example1 = event.examples[0];
|
|
68
|
+
const example2 = event.examples[1];
|
|
69
|
+
|
|
70
|
+
const example1File = fs.readFileSync(
|
|
71
|
+
path.join(
|
|
72
|
+
process.env.PROJECT_DIR,
|
|
73
|
+
'events',
|
|
74
|
+
'EventWithSchemaAndExamples',
|
|
75
|
+
'examples',
|
|
76
|
+
'Basic.cs'
|
|
77
|
+
),
|
|
78
|
+
{ encoding: 'utf-8' }
|
|
79
|
+
);
|
|
80
|
+
const example2File = fs.readFileSync(
|
|
81
|
+
path.join(
|
|
82
|
+
process.env.PROJECT_DIR,
|
|
83
|
+
'events',
|
|
84
|
+
'EventWithSchemaAndExamples',
|
|
85
|
+
'examples',
|
|
86
|
+
'Basic.js'
|
|
87
|
+
),
|
|
88
|
+
{ encoding: 'utf-8' }
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(event.examples).toHaveLength(2);
|
|
92
|
+
|
|
93
|
+
expect(example1.name).toEqual('Basic.cs');
|
|
94
|
+
expect(example1.langugage).toEqual('csharp');
|
|
95
|
+
expect(example1.snippet).toEqual(example1File);
|
|
96
|
+
|
|
97
|
+
expect(example2.name).toEqual('Basic.js');
|
|
98
|
+
expect(example2.langugage).toEqual('javascript');
|
|
99
|
+
expect(example2.snippet).toEqual(example2File);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('returns previous versions of events when the event has previous versions in the folder directory', async () => {
|
|
103
|
+
const { event } = await getEventByName('EventWithVersions');
|
|
104
|
+
expect(event.historicVersions).toEqual(['0.0.1']);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('returns empty array of event historic events when the event does not have previous versions in the folder directory', async () => {
|
|
108
|
+
const { event } = await getEventByName('EventWithSchemaAndExamples');
|
|
109
|
+
expect(event.historicVersions).toEqual([]);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('getAllEvents', () => {
|
|
114
|
+
it('gets all the events (in the PROJECT_DIR events dir)', async () => {
|
|
115
|
+
const events = await getAllEvents();
|
|
116
|
+
|
|
117
|
+
expect(events).toEqual([
|
|
118
|
+
{
|
|
119
|
+
name: 'AddedItemToCart',
|
|
120
|
+
version: '0.0.1',
|
|
121
|
+
summary:
|
|
122
|
+
'Holds information about the cusomer and product when they add an item to the cart.\n',
|
|
123
|
+
producers: ['Shopping API', 'Application API'],
|
|
124
|
+
consumers: ['Customer Portal'],
|
|
125
|
+
historicVersions: [],
|
|
126
|
+
owners: ['dboyne', 'mSmith'],
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'EmailSent',
|
|
130
|
+
version: '0.0.1',
|
|
131
|
+
summary: 'Tells us when an email has been sent\n',
|
|
132
|
+
producers: ['Email Platform'],
|
|
133
|
+
historicVersions: [],
|
|
134
|
+
consumers: [],
|
|
135
|
+
owners: ['dboyne', 'mSmith'],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'EventWithSchemaAndExamples',
|
|
139
|
+
version: '0.0.1',
|
|
140
|
+
summary: 'Example event with schema and examples\n',
|
|
141
|
+
historicVersions: [],
|
|
142
|
+
producers: [],
|
|
143
|
+
consumers: [],
|
|
144
|
+
owners: [],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'EventWithVersions',
|
|
148
|
+
version: '0.0.5',
|
|
149
|
+
summary: 'Tells us when an email has been sent\n',
|
|
150
|
+
historicVersions: ['0.0.1'],
|
|
151
|
+
producers: [],
|
|
152
|
+
consumers: [],
|
|
153
|
+
owners: [],
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('getUniqueServicesNamesFromEvents', () => {
|
|
160
|
+
it('returns an empty array when no services can be found in the array of events', () => {
|
|
161
|
+
const events = [
|
|
162
|
+
{ name: 'Testing', version: '1.0.0' },
|
|
163
|
+
{ name: 'Testing', version: '2.0.0' },
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
const result = getUniqueServicesNamesFromEvents(events);
|
|
167
|
+
|
|
168
|
+
expect(result).toEqual([]);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('takes an array of events and only returns unique service names', () => {
|
|
172
|
+
const events = [
|
|
173
|
+
{
|
|
174
|
+
name: 'Testing',
|
|
175
|
+
version: '1.0.0',
|
|
176
|
+
consumers: ['Service 1', 'Service 2'],
|
|
177
|
+
historicVersions: [],
|
|
178
|
+
producers: ['Service 3'],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: 'Testing',
|
|
182
|
+
version: '2.0.0',
|
|
183
|
+
consumers: ['Service 2', 'Service 3'],
|
|
184
|
+
historicVersions: [],
|
|
185
|
+
producers: ['Service 4'],
|
|
186
|
+
},
|
|
187
|
+
{ name: 'Testing', version: '3.0.0', consumers: ['Service 3', 'Service 4'] },
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
const result = getUniqueServicesNamesFromEvents(events);
|
|
191
|
+
|
|
192
|
+
expect(result).toEqual(['Service 1', 'Service 2', 'Service 3', 'Service 4']);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('getAllEventsByOwnerId', () => {
|
|
197
|
+
it('returns empty array when no owner is found', async () => {
|
|
198
|
+
const events = await getAllEventsByOwnerId('made-up-user');
|
|
199
|
+
expect(events).toEqual([]);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('returns all the events for a given owner id', async () => {
|
|
203
|
+
const events = await getAllEventsByOwnerId('dboyne');
|
|
204
|
+
|
|
205
|
+
expect(events).toEqual([
|
|
206
|
+
{
|
|
207
|
+
name: 'AddedItemToCart',
|
|
208
|
+
version: '0.0.1',
|
|
209
|
+
summary:
|
|
210
|
+
'Holds information about the cusomer and product when they add an item to the cart.\n',
|
|
211
|
+
producers: ['Shopping API', 'Application API'],
|
|
212
|
+
consumers: ['Customer Portal'],
|
|
213
|
+
historicVersions: [],
|
|
214
|
+
owners: ['dboyne', 'mSmith'],
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: 'EmailSent',
|
|
218
|
+
version: '0.0.1',
|
|
219
|
+
summary: 'Tells us when an email has been sent\n',
|
|
220
|
+
producers: ['Email Platform'],
|
|
221
|
+
consumers: [],
|
|
222
|
+
historicVersions: [],
|
|
223
|
+
owners: ['dboyne', 'mSmith'],
|
|
224
|
+
},
|
|
225
|
+
]);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe('getAllEventsThatHaveRelationshipWithService', () => {
|
|
230
|
+
it('returns the relationships between events for a given service', () => {
|
|
231
|
+
const events = [
|
|
232
|
+
{
|
|
233
|
+
name: 'AddedItemToCart',
|
|
234
|
+
version: '0.0.1',
|
|
235
|
+
summary:
|
|
236
|
+
'Holds information about the cusomer and product when they add an item to the cart.\n',
|
|
237
|
+
producers: ['Shopping API', 'My Service'],
|
|
238
|
+
consumers: ['Customer Portal'],
|
|
239
|
+
historicVersions: [],
|
|
240
|
+
owners: ['dboyne', 'mSmith'],
|
|
241
|
+
},
|
|
242
|
+
];
|
|
243
|
+
|
|
244
|
+
const service = {
|
|
245
|
+
id: 'My Service',
|
|
246
|
+
name: 'My Service',
|
|
247
|
+
summary: 'Test Service',
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const result = getAllEventsThatHaveRelationshipWithService(service, events);
|
|
251
|
+
|
|
252
|
+
expect(result).toEqual({
|
|
253
|
+
publishes: [
|
|
254
|
+
{
|
|
255
|
+
name: 'AddedItemToCart',
|
|
256
|
+
version: '0.0.1',
|
|
257
|
+
summary:
|
|
258
|
+
'Holds information about the cusomer and product when they add an item to the cart.\n',
|
|
259
|
+
producers: ['Shopping API', 'My Service'],
|
|
260
|
+
consumers: ['Customer Portal'],
|
|
261
|
+
historicVersions: [],
|
|
262
|
+
owners: ['dboyne', 'mSmith'],
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
subscribes: [],
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('if no relationships for given service and events can be found then empty arrays are returned', () => {
|
|
270
|
+
const events = [
|
|
271
|
+
{
|
|
272
|
+
name: 'AddedItemToCart',
|
|
273
|
+
version: '0.0.1',
|
|
274
|
+
summary:
|
|
275
|
+
'Holds information about the cusomer and product when they add an item to the cart.\n',
|
|
276
|
+
producers: ['Shopping API', 'Service'],
|
|
277
|
+
consumers: ['Customer Portal'],
|
|
278
|
+
historicVersions: [],
|
|
279
|
+
owners: ['dboyne', 'mSmith'],
|
|
280
|
+
},
|
|
281
|
+
];
|
|
282
|
+
|
|
283
|
+
const service = {
|
|
284
|
+
id: 'My Other Service That Has No Consumers or Anything',
|
|
285
|
+
name: 'My Other Service That Has No Consumers or Anything',
|
|
286
|
+
summary: 'Test Service',
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const result = getAllEventsThatHaveRelationshipWithService(service, events);
|
|
290
|
+
|
|
291
|
+
expect(result).toEqual({ publishes: [], subscribes: [] });
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { getSchemaFromDir, getLastModifiedDateOfFile } from '../file-reader';
|
|
4
|
+
|
|
5
|
+
let PROJECT_DIR: any;
|
|
6
|
+
|
|
7
|
+
describe('file-reader lib', () => {
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
PROJECT_DIR = process.env.PROJECT_DIR;
|
|
10
|
+
process.env.PROJECT_DIR = path.join(__dirname, 'assets');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterAll(() => {
|
|
14
|
+
process.env.PROJECT_DIR = PROJECT_DIR;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('getSchemaFromDir', () => {
|
|
18
|
+
it('returns the schema file found in the given directory path', () => {
|
|
19
|
+
const rawSchemaFile = fs.readFileSync(
|
|
20
|
+
path.join(process.env.PROJECT_DIR, 'events', 'EventWithSchemaAndExamples', 'schema.json'),
|
|
21
|
+
{ encoding: 'utf-8' }
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const result = getSchemaFromDir(
|
|
25
|
+
path.join(process.env.PROJECT_DIR, 'events', 'EventWithSchemaAndExamples')
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(result.snippet).toEqual(rawSchemaFile);
|
|
29
|
+
expect(result.language).toEqual('json');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('returns null when no schema file can be found in the given directory path', () => {
|
|
33
|
+
const result = getSchemaFromDir(path.join(process.env.PROJECT_DIR, 'events', 'EmailSent'));
|
|
34
|
+
|
|
35
|
+
expect(result).toEqual(null);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('getLastModifiedDateOfFile', () => {
|
|
40
|
+
it('returns the date the given file was last modified', () => {
|
|
41
|
+
const result = getLastModifiedDateOfFile(
|
|
42
|
+
path.join(process.env.PROJECT_DIR, 'events', 'EventWithSchemaAndExamples', 'schema.json')
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const stats = fs.statSync(
|
|
46
|
+
path.join(process.env.PROJECT_DIR, 'events', 'EventWithSchemaAndExamples', 'schema.json')
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const fileData = new Date(stats.mtime);
|
|
50
|
+
const expectedResult = `${fileData.getFullYear()}/${
|
|
51
|
+
fileData.getMonth() + 1
|
|
52
|
+
}/${fileData.getDate()}`;
|
|
53
|
+
|
|
54
|
+
expect(result).toEqual(expectedResult);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { buildMermaidFlowChartForEvent, buildMermaidFlowChartForService } from '../graphs';
|
|
2
|
+
|
|
3
|
+
describe('graphs', () => {
|
|
4
|
+
describe('buildMermaidFlowChartForService', () => {
|
|
5
|
+
it('takes a given Service and returns the mermaid code showing relationships between the events it publishes and consumes', () => {
|
|
6
|
+
const event = { name: 'My Event', version: '0.0.1' };
|
|
7
|
+
const event2 = { name: 'My Event 2', version: '0.0.1' };
|
|
8
|
+
|
|
9
|
+
const service = {
|
|
10
|
+
id: 'My Service',
|
|
11
|
+
name: 'My Service',
|
|
12
|
+
version: '0.0.1',
|
|
13
|
+
summary: 'Summary',
|
|
14
|
+
publishes: [event],
|
|
15
|
+
subscribes: [event2],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const result = buildMermaidFlowChartForService(service);
|
|
19
|
+
|
|
20
|
+
expect(result.trim()).toEqual(`flowchart LR
|
|
21
|
+
My_Event_2:::producer-->My_Service:::event
|
|
22
|
+
|
|
23
|
+
classDef event stroke:#2563eb,stroke-width: 4px;
|
|
24
|
+
classDef producer stroke:#75d7b6,stroke-width: 2px;
|
|
25
|
+
classDef consumer stroke:#818cf8,stroke-width: 2px;
|
|
26
|
+
My_Service:::event-->My_Event:::consumer`);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('buildMermaidFlowChartForEvent', () => {
|
|
31
|
+
it('takes and Event and returns the mermaid code showing relationships between the event and its consumers and producers', () => {
|
|
32
|
+
const event = {
|
|
33
|
+
name: 'My Event',
|
|
34
|
+
version: '0.0.1',
|
|
35
|
+
producers: ['Service 1'],
|
|
36
|
+
consumers: ['Service 2'],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const result = buildMermaidFlowChartForEvent(event);
|
|
40
|
+
|
|
41
|
+
expect(result.trim()).toEqual(`flowchart LR
|
|
42
|
+
Service_1:::producer-->My_Event:::event
|
|
43
|
+
|
|
44
|
+
classDef event stroke:#2563eb,stroke-width: 4px;
|
|
45
|
+
classDef producer stroke:#75d7b6,stroke-width: 2px;
|
|
46
|
+
classDef consumer stroke:#818cf8,stroke-width: 2px;
|
|
47
|
+
My_Event:::event-->Service_2:::consumer`);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('transforms any service name with spaces into _', () => {
|
|
51
|
+
const event = {
|
|
52
|
+
name: 'My Event',
|
|
53
|
+
version: '0.0.1',
|
|
54
|
+
producers: ['Service 1 With Spaces'],
|
|
55
|
+
consumers: [],
|
|
56
|
+
};
|
|
57
|
+
const result = buildMermaidFlowChartForEvent(event);
|
|
58
|
+
expect(result).toContain(`Service_1_With_Spaces:::producer-->My_Event:::event`);
|
|
59
|
+
expect(result).not.toContain(`Service 1 With Spaces`);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getAllServices, getAllServicesByOwnerId, getServiceByName } from '../services';
|
|
3
|
+
|
|
4
|
+
let PROJECT_DIR: any;
|
|
5
|
+
|
|
6
|
+
describe('services', () => {
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
PROJECT_DIR = process.env.PROJECT_DIR;
|
|
9
|
+
process.env.PROJECT_DIR = path.join(__dirname, 'assets');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterAll(() => {
|
|
13
|
+
process.env.PROJECT_DIR = PROJECT_DIR;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('getAllServices', () => {
|
|
17
|
+
it('gets all the services (in the PROJECT_DIR services dir)', async () => {
|
|
18
|
+
const services = await getAllServices();
|
|
19
|
+
|
|
20
|
+
expect(services).toEqual([
|
|
21
|
+
{
|
|
22
|
+
id: 'Email Platform',
|
|
23
|
+
name: 'Email Platform',
|
|
24
|
+
summary:
|
|
25
|
+
'Internal Email system. Used to send emails to 1000s of customers. Hosted in AWS\n',
|
|
26
|
+
owners: ['dboyne'],
|
|
27
|
+
repository: {
|
|
28
|
+
url: 'https://github.com/boyney123/EmailPlatform',
|
|
29
|
+
language: 'JavaScript',
|
|
30
|
+
},
|
|
31
|
+
tags: [
|
|
32
|
+
{
|
|
33
|
+
label: 'defaultContentType:application/json',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
label: 'Apache 2.0',
|
|
37
|
+
url: 'https://www.apache.org/licenses/LICENSE-2.0',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
publishes: [
|
|
41
|
+
{
|
|
42
|
+
name: 'EmailSent',
|
|
43
|
+
version: '0.0.1',
|
|
44
|
+
summary: 'Tells us when an email has been sent\n',
|
|
45
|
+
producers: ['Email Platform'],
|
|
46
|
+
consumers: [],
|
|
47
|
+
historicVersions: [],
|
|
48
|
+
owners: ['dboyne', 'mSmith'],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
subscribes: [],
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('getAllServicesByOwnerId', () => {
|
|
58
|
+
it('returns empty array when no owner is found', async () => {
|
|
59
|
+
const services = await getAllServicesByOwnerId('made-up-user');
|
|
60
|
+
expect(services).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('returns all the services for a given owner id', async () => {
|
|
64
|
+
const services = await getAllServicesByOwnerId('dboyne');
|
|
65
|
+
|
|
66
|
+
expect(services).toEqual([
|
|
67
|
+
{
|
|
68
|
+
id: 'Email Platform',
|
|
69
|
+
name: 'Email Platform',
|
|
70
|
+
summary:
|
|
71
|
+
'Internal Email system. Used to send emails to 1000s of customers. Hosted in AWS\n',
|
|
72
|
+
owners: ['dboyne'],
|
|
73
|
+
repository: {
|
|
74
|
+
url: 'https://github.com/boyney123/EmailPlatform',
|
|
75
|
+
language: 'JavaScript',
|
|
76
|
+
},
|
|
77
|
+
tags: [
|
|
78
|
+
{
|
|
79
|
+
label: 'defaultContentType:application/json',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
label: 'Apache 2.0',
|
|
83
|
+
url: 'https://www.apache.org/licenses/LICENSE-2.0',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
publishes: [
|
|
87
|
+
{
|
|
88
|
+
name: 'EmailSent',
|
|
89
|
+
version: '0.0.1',
|
|
90
|
+
summary: 'Tells us when an email has been sent\n',
|
|
91
|
+
producers: ['Email Platform'],
|
|
92
|
+
consumers: [],
|
|
93
|
+
historicVersions: [],
|
|
94
|
+
owners: ['dboyne', 'mSmith'],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
subscribes: [],
|
|
98
|
+
},
|
|
99
|
+
]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('getServiceByName', () => {
|
|
104
|
+
it('returns an event and markdown by the given event name', async () => {
|
|
105
|
+
const { service, markdown } = await getServiceByName('Email Platform');
|
|
106
|
+
|
|
107
|
+
expect(service).toEqual({
|
|
108
|
+
id: 'Email Platform',
|
|
109
|
+
name: 'Email Platform',
|
|
110
|
+
summary:
|
|
111
|
+
'Internal Email system. Used to send emails to 1000s of customers. Hosted in AWS\n',
|
|
112
|
+
owners: ['dboyne'],
|
|
113
|
+
repository: {
|
|
114
|
+
url: 'https://github.com/boyney123/EmailPlatform',
|
|
115
|
+
language: 'JavaScript',
|
|
116
|
+
},
|
|
117
|
+
tags: [
|
|
118
|
+
{
|
|
119
|
+
label: 'defaultContentType:application/json',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
label: 'Apache 2.0',
|
|
123
|
+
url: 'https://www.apache.org/licenses/LICENSE-2.0',
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
publishes: [
|
|
127
|
+
{
|
|
128
|
+
name: 'EmailSent',
|
|
129
|
+
version: '0.0.1',
|
|
130
|
+
summary: 'Tells us when an email has been sent\n',
|
|
131
|
+
producers: ['Email Platform'],
|
|
132
|
+
consumers: [],
|
|
133
|
+
historicVersions: [],
|
|
134
|
+
owners: ['dboyne', 'mSmith'],
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
subscribes: [],
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
expect(markdown.content).toMatchMarkdown('# Testing');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|