1
0
Fork 0
mirror of synced 2024-10-06 04:54:52 +13:00

More MongoDB query tests.

This commit is contained in:
Sam Rose 2024-02-06 10:47:47 +00:00
parent 4d1b13f754
commit 8bb25c4715
No known key found for this signature in database

View file

@ -154,6 +154,55 @@ describe("/queries", () => {
expect(result.data).toEqual([{ _id: expect.anything(), name: "one" }])
})
it("should execute a findOneAndUpdate query", async () => {
const query = await createQuery({
fields: {
json: {
filter: { name: { $eq: "one" } },
update: { $set: { name: "newName" } },
},
extra: {
actionType: "findOneAndUpdate",
},
},
})
const result = await config.api.query.execute(query._id!)
expect(result.data).toEqual([
{
lastErrorObject: { n: 1, updatedExisting: true },
ok: 1,
value: { _id: expect.anything(), name: "one" },
},
])
await withCollection(async collection => {
expect(await collection.countDocuments()).toBe(5)
const doc = await collection.findOne({ name: { $eq: "newName" } })
expect(doc).toEqual({
_id: expect.anything(),
name: "newName",
})
})
})
it("should execute a distinct query", async () => {
const query = await createQuery({
fields: {
json: "name",
extra: {
actionType: "distinct",
},
},
})
const result = await config.api.query.execute(query._id!)
const values = result.data.map(o => o.value).sort()
expect(values).toEqual(["five", "four", "one", "three", "two"])
})
it("should execute a create query with parameters", async () => {
const query = await createQuery({
fields: {