1 | import { EventFormatter } from '../../src/util';
|
2 |
|
3 | describe('EventFormatter', () => {
|
4 | let eventFormatter;
|
5 |
|
6 | beforeEach(() => {
|
7 | eventFormatter = new EventFormatter('App.Events');
|
8 | });
|
9 |
|
10 | test('prepends an event with a namespace and replaces dot separators with backslashes', () => {
|
11 | let formatted = eventFormatter.format('Users.UserCreated');
|
12 |
|
13 | expect(formatted).toBe('App\\Events\\Users\\UserCreated');
|
14 | });
|
15 |
|
16 | test('does not prepend a namespace when an event starts with a dot', () => {
|
17 | let formatted = eventFormatter.format('.App\\Users\\UserCreated');
|
18 |
|
19 | expect(formatted).toBe('App\\Users\\UserCreated');
|
20 | });
|
21 |
|
22 | test('does not prepend a namespace when an event starts with a backslash', () => {
|
23 | let formatted = eventFormatter.format('\\App\\Users\\UserCreated');
|
24 |
|
25 | expect(formatted).toBe('App\\Users\\UserCreated');
|
26 | });
|
27 |
|
28 | test('does not replace dot separators when the event starts with a dot', () => {
|
29 | let formatted = eventFormatter.format('.users.created');
|
30 |
|
31 | expect(formatted).toBe('users.created');
|
32 | });
|
33 |
|
34 | test('does not replace dot separators when the event starts with a backslash', () => {
|
35 | let formatted = eventFormatter.format('\\users.created');
|
36 |
|
37 | expect(formatted).toBe('users.created');
|
38 | });
|
39 |
|
40 | test('does not prepend a namespace when none is set', () => {
|
41 | let eventFormatter = new EventFormatter(false);
|
42 |
|
43 | let formatted = eventFormatter.format('Users.UserCreated');
|
44 |
|
45 | expect(formatted).toBe('Users\\UserCreated');
|
46 | });
|
47 | });
|