cypress-mongodb
Version:
Cypress MongoDB plugin
26 lines (25 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.aggregate = aggregate;
var validator_1 = require("../utils/validator");
var bson_1 = require("bson");
function aggregate(pipeline, options) {
var args = {
uri: Cypress.env('mongodb').uri,
database: (options === null || options === void 0 ? void 0 : options.database) || Cypress.env('mongodb').database,
collection: (options === null || options === void 0 ? void 0 : options.collection) || Cypress.env('mongodb').collection,
options: options,
pipeline: pipeline,
};
(0, validator_1.validate)(args);
if (!pipeline) {
throw new Error('Pipeline must be specified');
}
else if (typeof pipeline !== 'object' || !Array.isArray(pipeline)) {
throw new Error('Pipeline must be a valid mongodb aggregation');
}
args.pipeline = (0, bson_1.serialize)(Object.fromEntries(args.pipeline.entries()));
return cy.task('aggregate', args).then(function (result) {
return Object.values((0, bson_1.deserialize)(Buffer.from(result)));
});
}