1
0
Fork 0
mirror of synced 2024-05-06 13:32:37 +12:00

Fix types

This commit is contained in:
Mel O'Hagan 2022-10-03 19:10:01 +01:00
parent 268dd0ace5
commit 6ef497992a
5 changed files with 24 additions and 44 deletions

View file

@ -33,7 +33,7 @@ module MongoMock {
}) })
} }
mongodb.ObjectID = jest.requireActual("mongodb").ObjectID mongodb.ObjectId = jest.requireActual("mongodb").ObjectId
module.exports = mongodb module.exports = mongodb
} }

View file

@ -103,7 +103,7 @@ class MongoIntegration implements IntegrationBase {
) { ) {
const id = json[field].match(/(?<=objectid\(['"]).*(?=['"]\))/gi)?.[0] const id = json[field].match(/(?<=objectid\(['"]).*(?=['"]\))/gi)?.[0]
if (id) { if (id) {
json[field] = ObjectID.createFromHexString(id) json[field] = ObjectId.createFromHexString(id)
} }
} }
} }
@ -207,9 +207,9 @@ class MongoIntegration implements IntegrationBase {
json = this.parseQueryParams(query.json, "update") json = this.parseQueryParams(query.json, "update")
} }
let findAndUpdateJson = this.createObjectIds(json) as { let findAndUpdateJson = this.createObjectIds(json) as {
filter: FilterQuery<any> filter: Filter<any>
update: UpdateQuery<any> update: UpdateFilter<any>
options: FindOneAndUpdateOption<any> options: FindOneAndUpdateOptions
} }
return await collection.findOneAndUpdate( return await collection.findOneAndUpdate(
findAndUpdateJson.filter, findAndUpdateJson.filter,
@ -247,8 +247,8 @@ class MongoIntegration implements IntegrationBase {
queryJson = this.parseQueryParams(queryJson, "update") queryJson = this.parseQueryParams(queryJson, "update")
} }
let json = this.createObjectIds(queryJson) as { let json = this.createObjectIds(queryJson) as {
filter: FilterQuery<any> filter: Filter<any>
update: UpdateQuery<any> update: UpdateFilter<any>
options: object options: object
} }
@ -257,14 +257,14 @@ class MongoIntegration implements IntegrationBase {
return await collection.updateOne( return await collection.updateOne(
json.filter, json.filter,
json.update, json.update,
json.options as UpdateOneOptions json.options as UpdateOptions
) )
} }
case "updateMany": { case "updateMany": {
return await collection.updateMany( return await collection.updateMany(
json.filter, json.filter,
json.update, json.update,
json.options as UpdateManyOptions json.options as UpdateOptions
) )
} }
default: { default: {
@ -291,8 +291,8 @@ class MongoIntegration implements IntegrationBase {
queryJson = this.parseQueryParams(queryJson, "delete") queryJson = this.parseQueryParams(queryJson, "delete")
} }
let json = this.createObjectIds(queryJson) as { let json = this.createObjectIds(queryJson) as {
filter: FilterQuery<any> filter: Filter<any>
options: CommonOptions options: OperationOptions
} }
if (!json.options) { if (!json.options) {
json = { json = {

View file

@ -169,12 +169,12 @@ describe("MongoDB Integration", () => {
const args = config.integration.client.updateOne.mock.calls[0] const args = config.integration.client.updateOne.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: { _id: {
$eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), $eq: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
}, },
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({
$set: { $set: {
_id: mongo.ObjectID.createFromHexString("FFFF12345678ABCD12345678"), _id: mongo.ObjectId.createFromHexString("FFFF12345678ABCD12345678"),
}, },
}) })
expect(args[2]).toEqual({ expect(args[2]).toEqual({
@ -208,7 +208,7 @@ describe("MongoDB Integration", () => {
const args = config.integration.client.findOneAndUpdate.mock.calls[0] const args = config.integration.client.findOneAndUpdate.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: { _id: {
$eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), $eq: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
}, },
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({
@ -253,7 +253,7 @@ describe("MongoDB Integration", () => {
const args = config.integration.client.updateOne.mock.calls[0] const args = config.integration.client.updateOne.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: { _id: {
$eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), $eq: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
}, },
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({
@ -308,7 +308,7 @@ describe("MongoDB Integration", () => {
const args = config.integration.client.updateOne.mock.calls[0] const args = config.integration.client.updateOne.mock.calls[0]
expect(args[0]).toEqual({ expect(args[0]).toEqual({
_id: { _id: {
$eq: mongo.ObjectID.createFromHexString("ACBD12345678ABCD12345678"), $eq: mongo.ObjectId.createFromHexString("ACBD12345678ABCD12345678"),
}, },
}) })
expect(args[1]).toEqual({ expect(args[1]).toEqual({

View file

@ -13889,6 +13889,13 @@ tr46@^2.1.0:
dependencies: dependencies:
punycode "^2.1.1" punycode "^2.1.1"
tr46@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-3.0.0.tgz#555c4e297a950617e8eeddef633c87d4d9d6cbf9"
integrity sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==
dependencies:
punycode "^2.1.1"
tr46@~0.0.3: tr46@~0.0.3:
version "0.0.3" version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"

View file

@ -986,13 +986,6 @@
estree-walker "^1.0.1" estree-walker "^1.0.1"
picomatch "^2.2.2" picomatch "^2.2.2"
"@types/bson@*":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@types/bson/-/bson-4.2.0.tgz#a2f71e933ff54b2c3bf267b67fa221e295a33337"
integrity sha512-ELCPqAdroMdcuxqwMgUpifQyRoTpyYCNr1V9xKyF40VsBobsj+BbWNRvwGchMgBPGqkw655ypkjj2MEF5ywVwg==
dependencies:
bson "*"
"@types/estree@0.0.39": "@types/estree@0.0.39":
version "0.0.39" version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
@ -1008,19 +1001,6 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c" resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ== integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==
"@types/mongodb@3.6.3":
version "3.6.3"
resolved "https://registry.yarnpkg.com/@types/mongodb/-/mongodb-3.6.3.tgz#5655af409d9e32d5d5ae9a653abf3e5f9c83eb7a"
integrity sha512-6YNqGP1hk5bjUFaim+QoFFuI61WjHiHE1BNeB41TA00Xd2K7zG4lcWyLLq/XtIp36uMavvS5hoAUJ+1u/GcX2Q==
dependencies:
"@types/bson" "*"
"@types/node" "*"
"@types/node@*":
version "17.0.33"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.33.tgz#3c1879b276dc63e73030bb91165e62a4509cd506"
integrity sha512-miWq2m2FiQZmaHfdZNcbpp9PuXg34W5JZ5CrJ/BaS70VuhoJENBEQybeiYSaPBRNq6KQGnjfEnc/F3PN++D+XQ==
"@types/node@>= 8": "@types/node@>= 8":
version "18.0.0" version "18.0.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.0.tgz#67c7b724e1bcdd7a8821ce0d5ee184d3b4dd525a" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.0.0.tgz#67c7b724e1bcdd7a8821ce0d5ee184d3b4dd525a"
@ -1466,13 +1446,6 @@ braces@^3.0.2:
dependencies: dependencies:
fill-range "^7.0.1" fill-range "^7.0.1"
bson@*:
version "4.6.3"
resolved "https://registry.yarnpkg.com/bson/-/bson-4.6.3.tgz#d1a9a0b84b9e84b62390811fc5580f6a8b1d858c"
integrity sha512-rAqP5hcUVJhXP2MCSNVsf0oM2OGU1So6A9pVRDYayvJ5+hygXHQApf87wd5NlhPM1J9RJnbqxIG/f8QTzRoQ4A==
dependencies:
buffer "^5.6.0"
btoa-lite@^1.0.0: btoa-lite@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337" resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
@ -1483,7 +1456,7 @@ buffer-from@^1.0.0:
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
buffer@^5.5.0, buffer@^5.6.0: buffer@^5.5.0:
version "5.7.1" version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0" resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ== integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==