MCPcopy
hub / github.com/mongodb/node-mongodb-native / resultCheck

Function resultCheck

test/tools/unified-spec-runner/match.ts:201–330  ·  view source on GitHub ↗
(
  actual: Document,
  expected: Document | number | string | boolean,
  entities: EntitiesMap,
  path: string[] = [],
  checkExtraKeys = false
)

Source from the content-addressed store, hash-verified

199 * `actual` object will throw an error
200 */
201export function resultCheck(
202 actual: Document,
203 expected: Document | number | string | boolean,
204 entities: EntitiesMap,
205 path: string[] = [],
206 checkExtraKeys = false
207): void {
208 function checkNestedDocuments(key: string, value: any, checkExtraKeys: boolean) {
209 if (key === 'sort') {
210 // TODO: This is a workaround that works because all sorts in the specs
211 // are objects with one key; ideally we'd want to adjust the spec definitions
212 // to indicate whether order matters for any given key and set general
213 // expectations accordingly (see NODE-3235)
214 expect(Object.keys(value)).to.have.lengthOf(1);
215 expect(actual[key]).to.be.instanceOf(Map);
216 expect(actual[key].size).to.equal(1);
217 const expectedSortKey = Object.keys(value)[0];
218 expect(actual[key]).to.have.all.keys(expectedSortKey);
219 const objFromActual = { [expectedSortKey]: actual[key].get(expectedSortKey) };
220 resultCheck(objFromActual, value, entities, path, checkExtraKeys);
221 } else if (key === 'createIndexes') {
222 for (const [i, userIndex] of actual.indexes.entries()) {
223 if (expected?.indexes?.[i]?.key == null) {
224 // The expectation does not include an assertion for the index key
225 continue;
226 }
227 expect(expected).to.have.nested.property(`.indexes[${i}].key`).to.be.a('object');
228 // @ts-expect-error: Not worth narrowing to a document
229 expect(Object.keys(expected.indexes[i].key)).to.have.lengthOf(1);
230 expect(userIndex).to.have.property('key').that.is.instanceOf(Map);
231 expect(
232 userIndex.key.size,
233 'Test input is JSON and cannot correctly test more than 1 key'
234 ).to.equal(1);
235 userIndex.key = Object.fromEntries(userIndex.key);
236 }
237 resultCheck(actual[key], value, entities, path, checkExtraKeys);
238 } else {
239 // If our actual value is a map, such as in the client bulk write results, we need
240 // to convert the expected keys from the string numbers to actual numbers since the key
241 // values in the maps are actual numbers.
242 const isActualMap = actual instanceof Map;
243 const mapKey = !Number.isNaN(Number(key)) ? Number(key) : key;
244 resultCheck(
245 isActualMap ? actual.get(mapKey) : actual[key],
246 value,
247 entities,
248 path,
249 checkExtraKeys
250 );
251 }
252 }
253
254 if (typeof expected === 'object' && expected) {
255 // Expected is an object
256 // either its a special operator or just an object to check equality against
257
258 if (isSpecialOperator(expected)) {

Callers 8

executeOperationAndCheckFunction · 0.90
checkNestedDocumentsFunction · 0.85
specialCheckFunction · 0.85
isLogRelevantFunction · 0.85
compareLogsFunction · 0.85
expectErrorCheckFunction · 0.85

Calls 10

isSpecialOperatorFunction · 0.85
specialCheckFunction · 0.85
checkNestedDocumentsFunction · 0.85
popMethod · 0.80
failMethod · 0.80
inspectFunction · 0.50
pushMethod · 0.45
filterMethod · 0.45
equalsMethod · 0.45
isMethod · 0.45

Tested by

no test coverage detected