cypress-mongodb
Version:
Cypress MongoDB plugin
28 lines • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.aggregate = aggregate;
const validator_1 = require("../utils/validator");
const bson_1 = require("bson");
function aggregate(pipeline, options) {
return cy.env(['mongodb']).then(({ mongodb }) => {
const args = {
uri: mongodb.uri,
database: options?.database || mongodb.database,
collection: options?.collection || 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((result) => {
return Object.values((0, bson_1.deserialize)(Buffer.from(result)));
});
});
}
//# sourceMappingURL=aggregation.js.map