Merge branch 'master' into revert-12934-revert-12930-revert-12929-revert-12769-isolated-vm

This commit is contained in:
Adria Navarro 2024-02-07 10:57:28 +01:00 committed by GitHub
commit e72e7c614a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 13 deletions

View File

@ -1,12 +1,15 @@
import { Datasource, Query } from "@budibase/types" import { Datasource, Query } from "@budibase/types"
import * as setup from "../utilities" import * as setup from "../utilities"
import { databaseTestProviders } from "../../../../integrations/tests/utils" import { databaseTestProviders } from "../../../../integrations/tests/utils"
import { MongoClient, type Collection } from "mongodb" import { MongoClient, type Collection, BSON } from "mongodb"
jest.unmock("mongodb") jest.unmock("mongodb")
const collection = "test_collection" const collection = "test_collection"
const expectValidId = expect.stringMatching(/^\w{24}$/)
const expectValidBsonObjectId = expect.any(BSON.ObjectId)
describe("/queries", () => { describe("/queries", () => {
let config = setup.getConfig() let config = setup.getConfig()
let datasource: Datasource let datasource: Datasource
@ -131,11 +134,11 @@ describe("/queries", () => {
const result = await config.api.query.execute(query._id!) const result = await config.api.query.execute(query._id!)
expect(result.data).toEqual([ expect(result.data).toEqual([
{ _id: expect.anything(), name: "one" }, { _id: expectValidId, name: "one" },
{ _id: expect.anything(), name: "two" }, { _id: expectValidId, name: "two" },
{ _id: expect.anything(), name: "three" }, { _id: expectValidId, name: "three" },
{ _id: expect.anything(), name: "four" }, { _id: expectValidId, name: "four" },
{ _id: expect.anything(), name: "five" }, { _id: expectValidId, name: "five" },
]) ])
}) })
@ -151,7 +154,7 @@ describe("/queries", () => {
const result = await config.api.query.execute(query._id!) const result = await config.api.query.execute(query._id!)
expect(result.data).toEqual([{ _id: expect.anything(), name: "one" }]) expect(result.data).toEqual([{ _id: expectValidId, name: "one" }])
}) })
it("should execute a findOneAndUpdate query", async () => { it("should execute a findOneAndUpdate query", async () => {
@ -173,7 +176,7 @@ describe("/queries", () => {
{ {
lastErrorObject: { n: 1, updatedExisting: true }, lastErrorObject: { n: 1, updatedExisting: true },
ok: 1, ok: 1,
value: { _id: expect.anything(), name: "one" }, value: { _id: expectValidId, name: "one" },
}, },
]) ])
@ -182,7 +185,7 @@ describe("/queries", () => {
const doc = await collection.findOne({ name: { $eq: "newName" } }) const doc = await collection.findOne({ name: { $eq: "newName" } })
expect(doc).toEqual({ expect(doc).toEqual({
_id: expect.anything(), _id: expectValidBsonObjectId,
name: "newName", name: "newName",
}) })
}) })
@ -227,14 +230,14 @@ describe("/queries", () => {
expect(result.data).toEqual([ expect(result.data).toEqual([
{ {
acknowledged: true, acknowledged: true,
insertedId: expect.anything(), insertedId: expectValidId,
}, },
]) ])
await withCollection(async collection => { await withCollection(async collection => {
const doc = await collection.findOne({ foo: { $eq: "bar" } }) const doc = await collection.findOne({ foo: { $eq: "bar" } })
expect(doc).toEqual({ expect(doc).toEqual({
_id: expect.anything(), _id: expectValidBsonObjectId,
foo: "bar", foo: "bar",
}) })
}) })
@ -315,7 +318,7 @@ describe("/queries", () => {
await withCollection(async collection => { await withCollection(async collection => {
const doc = await collection.findOne({ name: { $eq: "newOne" } }) const doc = await collection.findOne({ name: { $eq: "newOne" } })
expect(doc).toEqual({ expect(doc).toEqual({
_id: expect.anything(), _id: expectValidBsonObjectId,
name: "newOne", name: "newOne",
}) })
@ -381,7 +384,7 @@ describe("/queries", () => {
expect(docs).toHaveLength(5) expect(docs).toHaveLength(5)
for (const doc of docs) { for (const doc of docs) {
expect(doc).toEqual({ expect(doc).toEqual({
_id: expect.anything(), _id: expectValidBsonObjectId,
name: "newName", name: "newName",
}) })
} }