-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathentity_event_registry.test.ts
More file actions
187 lines (153 loc) · 6.56 KB
/
entity_event_registry.test.ts
File metadata and controls
187 lines (153 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import { expect } from 'chai';
import {
COMMAND_FAILED,
COMMAND_STARTED,
COMMAND_SUCCEEDED,
CONNECTION_CHECK_OUT_FAILED,
CONNECTION_CHECK_OUT_STARTED,
CONNECTION_CHECKED_IN,
CONNECTION_CHECKED_OUT,
CONNECTION_CLOSED,
CONNECTION_CREATED,
CONNECTION_POOL_CLEARED,
CONNECTION_POOL_CLOSED,
CONNECTION_POOL_CREATED,
CONNECTION_POOL_READY,
CONNECTION_READY
} from '../../../mongodb';
import { EntitiesMap, UnifiedMongoClient } from '../../../tools/unified-spec-runner/entities';
import { EntityEventRegistry } from '../../../tools/unified-spec-runner/entity_event_registry';
describe('EntityEventRegistry', function () {
describe('#register', function () {
context('when storeEventsAsEntities exists on the client entity', function () {
const clientEntity = {
id: 'client0',
storeEventsAsEntities: [
{
id: 'eventList',
events: [
'PoolCreatedEvent',
'PoolReadyEvent',
'PoolClearedEvent',
'PoolClosedEvent',
'ConnectionCreatedEvent',
'ConnectionReadyEvent',
'ConnectionClosedEvent',
'ConnectionCheckOutStartedEvent',
'ConnectionCheckOutFailedEvent',
'ConnectionCheckedOutEvent',
'ConnectionCheckedInEvent',
'CommandStartedEvent',
'CommandSucceededEvent',
'CommandFailedEvent'
]
}
]
};
const entitesMap = new EntitiesMap();
const uri = 'mongodb://127.0.0.1:27017';
const client = new UnifiedMongoClient(uri, clientEntity, {});
const registry = new EntityEventRegistry(client, clientEntity, entitesMap);
before(function () {
registry.register();
});
it('initializes the events in the entities map', function () {
expect(entitesMap.getEntity('events', 'eventList')).to.deep.equal([]);
});
it('maps PoolCreatedEvent to connectionPoolCreated', function () {
expect(client.listeners(CONNECTION_POOL_CREATED)).to.have.length(1);
});
it('maps PoolReadyEvent to connectionPoolReady', function () {
expect(client.listeners(CONNECTION_POOL_READY)).to.have.length(1);
});
it('maps PoolClearedEvent to connectionPoolCleared', function () {
expect(client.listeners(CONNECTION_POOL_CLEARED)).to.have.length(1);
});
it('maps PoolClosedEvent to connectionPoolClosed', function () {
expect(client.listeners(CONNECTION_POOL_CLOSED)).to.have.length(1);
});
it('maps ConnectionCreatedEvent to connectionCreated', function () {
expect(client.listeners(CONNECTION_CREATED)).to.have.length(1);
});
it('maps ConnectionReadyEvent to connectionReady', function () {
expect(client.listeners(CONNECTION_READY)).to.have.length(1);
});
it('maps ConnectionClosedEvent to connectionClosed', function () {
expect(client.listeners(CONNECTION_CLOSED)).to.have.length(1);
});
it('maps ConnectionCheckOutStartedEvent to connectionCheckoutStarted', function () {
expect(client.listeners(CONNECTION_CHECK_OUT_STARTED)).to.have.length(1);
});
it('maps ConnectionCheckOutFailedEvent to connectionCheckoutFailed', function () {
expect(client.listeners(CONNECTION_CHECK_OUT_FAILED)).to.have.length(1);
});
it('maps ConnectionCheckedOutEvent to connectionCheckedOut', function () {
expect(client.listeners(CONNECTION_CHECKED_OUT)).to.have.length(1);
});
it('maps ConnectionCheckedInEvent to connectionCheckedIn', function () {
expect(client.listeners(CONNECTION_CHECKED_IN)).to.have.length(1);
});
it('maps CommandStartedEvent to commandStarted', function () {
expect(client.listeners(COMMAND_STARTED)).to.have.length(1);
});
it('maps CommandSucceededEvent to commandSucceeded', function () {
expect(client.listeners(COMMAND_SUCCEEDED)).to.have.length(1);
});
it('maps CommandFailedEvent to commandFailed', function () {
expect(client.listeners(COMMAND_FAILED)).to.have.length(1);
});
});
context('when storeEventsAsEntities does not exist on the client entity', function () {
const clientEntity = { id: 'client0' };
const entitesMap = new EntitiesMap();
const uri = 'mongodb://127.0.0.1:27017';
const client = new UnifiedMongoClient(uri, clientEntity, {});
const registry = new EntityEventRegistry(client, clientEntity, entitesMap);
before(function () {
registry.register();
});
it('does not listen for connectionPoolCreated', function () {
expect(client.listeners(CONNECTION_POOL_CREATED)).to.be.empty;
});
it('does not listen for connectionPoolReady', function () {
expect(client.listeners(CONNECTION_POOL_READY)).to.be.empty;
});
it('does not listen for connectionPoolCleared', function () {
expect(client.listeners(CONNECTION_POOL_CLEARED)).to.be.empty;
});
it('does not listen for connectionPoolClosed', function () {
expect(client.listeners(CONNECTION_POOL_CLOSED)).to.be.empty;
});
it('mdoes not listen for connectionCreated', function () {
expect(client.listeners(CONNECTION_CREATED)).to.be.empty;
});
it('does not listen for connectionReady', function () {
expect(client.listeners(CONNECTION_READY)).to.be.empty;
});
it('does not listen for connectionClosed', function () {
expect(client.listeners(CONNECTION_CLOSED)).to.be.empty;
});
it('does not listen for connectionCheckoutStarted', function () {
expect(client.listeners(CONNECTION_CHECK_OUT_STARTED)).to.be.empty;
});
it('does not listen for connectionCheckoutFailed', function () {
expect(client.listeners(CONNECTION_CHECK_OUT_FAILED)).to.be.empty;
});
it('does not listen for connectionCheckedOut', function () {
expect(client.listeners(CONNECTION_CHECKED_OUT)).to.be.empty;
});
it('does not listen for connectionCheckedIn', function () {
expect(client.listeners(CONNECTION_CHECKED_IN)).to.be.empty;
});
it('does not listen for commandStarted', function () {
expect(client.listeners(COMMAND_STARTED)).to.be.empty;
});
it('does not listen for commandSucceeded', function () {
expect(client.listeners(COMMAND_SUCCEEDED)).to.be.empty;
});
it('does not listen for commandFailed', function () {
expect(client.listeners(COMMAND_FAILED)).to.be.empty;
});
});
});
});