-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
comment_with_falsy_values.test.ts
175 lines (163 loc) · 4.23 KB
/
comment_with_falsy_values.test.ts
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
import { Long } from '../../../src';
import { TestBuilder, UnifiedTestSuiteBuilder } from '../../tools/utils';
const falsyValues = [0, false, '', Long.ZERO, null, NaN] as const;
const falsyToString = (value: typeof falsyValues[number]) => {
if (Number.isNaN(value)) {
return 'NaN';
}
if (value === '') {
return "''";
}
if (value?._bsontype === 'Long') {
return 'Long.ZERO';
}
return JSON.stringify(value);
};
function* generateTestCombinations() {
for (const [name, args] of [
['find', { filter: { _id: 1 } }] as const,
['aggregate', { pipeline: [] }] as const,
['insertMany', { documents: [{ name: 'john' }] }] as const,
['deleteOne', { filter: { toBeDeleted: true } }] as const,
['findOneAndReplace', { filter: { _id: 1 }, replacement: { x: 12 } }] as const
]) {
for (const falsyValue of falsyValues) {
yield { name, args: { ...args, comment: falsyValue } };
}
}
}
const tests = Array.from(generateTestCombinations()).map(({ name, args }) => {
const description = `${name} should pass falsy value ${falsyToString(
args.comment
)} for comment option`;
return new TestBuilder(description)
.operation({
name,
object: 'collection0',
arguments: args
})
.expectEvents({
client: 'client0',
events: [
{
commandStartedEvent: {
command: {
comment: args.comment
}
}
}
]
})
.toJSON();
});
const testsForChangeStreamsAggregate = falsyValues.map(falsyValue => {
const description = `ChangeStreams should pass falsy value ${falsyToString(
falsyValue
)} for comment option on initial aggregate`;
return new TestBuilder(description)
.operation({
name: 'createChangeStream',
object: 'collection0',
arguments: {
pipeline: [],
comment: falsyValue
},
saveResultAsEntity: 'changeStream0'
})
.expectEvents({
client: 'client0',
events: [
{
commandStartedEvent: {
command: {
comment: falsyValue
}
}
}
]
})
.toJSON();
});
const testsForGetMore = falsyValues.map(falsyValue => {
const description = `ChangeStreams should pass falsy value ${falsyToString(
falsyValue
)} for comment option on getMore`;
return new TestBuilder(description)
.runOnRequirement({ topologies: ['replicaset'] })
.operation({
name: 'createChangeStream',
object: 'collection0',
arguments: {
pipeline: [],
comment: falsyValue
},
saveResultAsEntity: 'changeStream0'
})
.operation({
name: 'insertOne',
object: 'collection0',
arguments: {
document: {
a: 1
}
}
})
.operation({
name: 'iterateUntilDocumentOrError',
object: 'changeStream0',
arguments: {}
})
.expectEvents({
client: 'client0',
events: [
{
commandStartedEvent: {
command: {
comment: falsyValue
}
}
},
{
commandStartedEvent: {}
},
{
commandStartedEvent: {
command: {
comment: falsyValue
}
}
}
]
})
.toJSON();
});
describe('Comment with falsy values', () => {
UnifiedTestSuiteBuilder.describe('Comment with Falsy Values')
.runOnRequirement({ minServerVersion: '4.4.0' })
.createEntities(UnifiedTestSuiteBuilder.defaultEntities)
.initialData({
collectionName: 'collection0',
databaseName: 'database0',
documents: [
{ _id: 1, x: 11 },
{ _id: 2, toBeDeleted: true } // This should only be used by the delete test
]
})
.test(tests)
.run();
UnifiedTestSuiteBuilder.describe('Change Streams Comment with Falsy Values')
.schemaVersion('1.0')
.createEntities(UnifiedTestSuiteBuilder.defaultEntities)
.initialData({
collectionName: 'collection0',
databaseName: 'database0',
documents: []
})
.runOnRequirement({
minServerVersion: '4.4.0',
topologies: ['replicaset', 'sharded-replicaset']
})
.test(testsForChangeStreamsAggregate)
.test(testsForGetMore)
.run();
});