cypress-mongodb
Version:
Cypress MongoDB plugin
63 lines (62 loc) • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateOne = updateOne;
exports.updateMany = updateMany;
var validator_1 = require("../utils/validator");
var bson_1 = require("bson");
function updateOne(filter, document, 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,
filter: filter,
document: document,
};
(0, validator_1.validate)(args);
if (!filter) {
throw new Error('Filter must be specified');
}
else if (typeof filter !== 'object' || Array.isArray(filter)) {
throw new Error('Filter must be an object');
}
if (!document) {
throw new Error('Document must be specified');
}
else if (typeof document !== 'object' || Array.isArray(document)) {
throw new Error('Document must be an object');
}
args.filter = (0, bson_1.serialize)(args.filter);
args.document = (0, bson_1.serialize)(args.document);
return cy.task('updateOne', args).then(function (result) {
return (0, bson_1.deserialize)(Buffer.from(result));
});
}
function updateMany(filter, document, 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,
filter: filter,
document: document,
};
(0, validator_1.validate)(args);
if (!filter) {
throw new Error('Filter must be specified');
}
else if (typeof filter !== 'object' || Array.isArray(filter)) {
throw new Error('Filter must be an object');
}
if (!document) {
throw new Error('Document must be specified');
}
else if (typeof document !== 'object' || Array.isArray(document)) {
throw new Error('Document must be an object');
}
args.filter = (0, bson_1.serialize)(args.filter);
args.document = (0, bson_1.serialize)(args.document);
return cy.task('updateMany', args).then(function (result) {
return (0, bson_1.deserialize)(Buffer.from(result));
});
}