Convert mongodb.spec.ts

This commit is contained in:
Sam Rose 2024-11-05 16:25:50 +00:00
parent 6b9b0801a8
commit 85d42002f9
No known key found for this signature in database
1 changed files with 627 additions and 630 deletions

View File

@ -1,8 +1,7 @@
import { Datasource, Query } from "@budibase/types"
import * as setup from "../utilities"
import {
DatabaseName,
getDatasource,
datasourceDescribe,
} from "../../../../integrations/tests/utils"
import { MongoClient, type Collection, BSON, Db } from "mongodb"
import { generator } from "@budibase/backend-core/tests"
@ -10,9 +9,10 @@ import { generator } from "@budibase/backend-core/tests"
const expectValidId = expect.stringMatching(/^\w{24}$/)
const expectValidBsonObjectId = expect.any(BSON.ObjectId)
describe("/queries", () => {
datasourceDescribe(
{ name: "/queries", only: [DatabaseName.MONGODB] },
({ config, dsProvider }) => {
let collection: string
let config = setup.getConfig()
let datasource: Datasource
async function createQuery(query: Partial<Query>): Promise<Query> {
@ -63,15 +63,9 @@ describe("/queries", () => {
})
}
afterAll(async () => {
setup.afterAll()
})
beforeAll(async () => {
await config.init()
datasource = await config.api.datasource.create(
await getDatasource(DatabaseName.MONGODB)
)
const ds = await dsProvider
datasource = ds.datasource!
})
beforeEach(async () => {
@ -319,7 +313,9 @@ describe("/queries", () => {
const query = await createQuery({
fields: {
json: {
filter: { _id: { $eq: `ObjectId("${insertResult.insertedId}")` } },
filter: {
_id: { $eq: `ObjectId("${insertResult.insertedId}")` },
},
update: { $set: { name: "newName" } },
},
extra: {
@ -717,4 +713,5 @@ describe("/queries", () => {
})
})
})
})
}
)