mirror of
https://github.com/nvms/prsm.git
synced 2025-12-16 00:00:52 +00:00
26 lines
908 B
TypeScript
26 lines
908 B
TypeScript
import { expect, testSuite } from "manten";
|
|
import { nrml, testCollection } from "../../../common";
|
|
|
|
export default testSuite(async ({ describe }) => {
|
|
describe("$map", ({ test }) => {
|
|
test("works", () => {
|
|
const collection = testCollection();
|
|
const mapfn = (doc: any) => ({ ...doc, c: 5 });
|
|
collection.insert({ a: 1, b: { c: 5 } });
|
|
collection.update({ a: 1 }, { $map: mapfn });
|
|
const found = nrml(collection.find({ c: 5 }));
|
|
expect(found).toEqual([{ a: 1, b: { c: 5 }, c: 5 }]);
|
|
});
|
|
|
|
test("works with other operators", () => {
|
|
const collection = testCollection();
|
|
const mapfn = (doc: any) => ({ ...doc, c: 5 });
|
|
collection.insert({ a: 1, b: { c: 5 } });
|
|
collection.update({ a: 1 }, { $map: mapfn, $unset: "b" });
|
|
const found = nrml(collection.find({ c: 5 }));
|
|
expect(found).toEqual([{ a: 1, c: 5 }]);
|
|
});
|
|
});
|
|
});
|
|
|