(key: string, value: any, checkExtraKeys: boolean)
| 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 |
no test coverage detected