transactions-mongoose
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -14,2 +14,4 @@ /* | ||
const {Transaction} = require("../src/index"); | ||
const {describe, it} = require("node:test"); | ||
const {strict: assert} = require("node:assert"); | ||
@@ -52,4 +54,24 @@ (async () => { | ||
// test _id <--> idSynonym | ||
const doc = transactionData1.result._doc; // extract result | ||
doc.id = doc._id; // copy orig _id to id | ||
delete doc._id; | ||
const td = transaction.add(Person, doc); | ||
await transaction.commit(); | ||
console.log('persons', await Person.find()) | ||
// check | ||
const count = await Person.countDocuments({}) | ||
const count2 = await Person.countDocuments({firstname: 'Sancho'}) | ||
describe('Transactions - No Replica Set', () => { | ||
it('Persons count 4', () => { | ||
assert.strictEqual(count, 4); | ||
}) | ||
it('Sancho count 2', () => { | ||
assert.strictEqual(count2, 2); | ||
}) | ||
}) | ||
await mongoose.disconnect(); | ||
await mongod.stop(); | ||
})(); |
@@ -15,2 +15,4 @@ /* | ||
const personHelper = require('./personHelper'); | ||
const {describe, it} = require("node:test"); | ||
const {strict: assert} = require("node:assert"); | ||
@@ -67,5 +69,21 @@ (async () => { | ||
// check | ||
personSancho = await Person.findById(persons.Sancho._id); // test Sancho exists? | ||
personJanna = await Person.findById(persons.Janna._id); | ||
personHulio = await Person.findById(persons.Hulio._id); | ||
describe('Transactions - No Replica Set', () => { | ||
it('Sancho married', () => { | ||
assert.strictEqual(personSancho.status, 'married'); | ||
}) | ||
it('Janna married', () => { | ||
assert.strictEqual(personJanna.status, 'married'); | ||
}) | ||
it('Sancho friend Janna', () => { | ||
assert.strictEqual(personJanna._id.toString(), personSancho.friend_id.toString()); | ||
}) | ||
}) | ||
await mongoose.disconnect(); | ||
await mongod.stop(); | ||
})(); |
{ | ||
"name": "transactions-mongoose", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Transactions for mongoose", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "https://github.com/rosbitskyy/transactions-mongoose.git" | ||
"url": "git+https://github.com/rosbitskyy/transactions-mongoose.git" | ||
}, | ||
@@ -11,0 +11,0 @@ "keywords": [ |
@@ -186,3 +186,11 @@ /* | ||
isValidArguments(model, object) { | ||
return (!this.isModel(model) && this.isExecutor(object)) || (this.isModel(model) && (this.isDocument(object) || this.isCleanDocument(object))) | ||
if (object) delete object.id | ||
const isExecutor = (!this.isModel(model) && this.isExecutor(object)); | ||
const isDoc = (this.isModel(model) && (this.isDocument(object) || this.isCleanDocument(object))); | ||
const exclude = ['__v', '_id', 'id']; | ||
if (isDoc) { | ||
if (this.isCleanDocument(object) && !object._id) exclude.map(it => delete object[it]); | ||
else if (this.isDocument(object) && !object._doc._id) exclude.map(it => delete object._doc[it]); | ||
} | ||
return isExecutor || isDoc; | ||
} | ||
@@ -189,0 +197,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71188
1228