- fix test: ''collection - fetch, STRING | MONGO'

This commit is contained in:
denihs
2023-02-16 14:31:47 -04:00
parent 783f6976b2
commit 18b47177cc
3 changed files with 99 additions and 44 deletions

View File

@@ -731,19 +731,18 @@ export class Connection {
"delivering result of invoking '" + name + "'"
);
}
// Keep our args safe from mutation (eg if we don't send the message for a
// while because of a wait method).
args = EJSON.clone(args);
const {
hasStub,
exception,
stubReturnValue,
alreadyInSimulation,
randomSeed,
stubArgs,
} = stubCallValue;
// Keep our args safe from mutation (eg if we don't send the message for a
// while because of a wait method).
args = EJSON.clone(stubArgs);
// If we're in a simulation, stop and return the result we have,
// rather than going on to do an RPC. If there was no stub,
// we'll end up returning undefined.
@@ -812,7 +811,7 @@ export class Connection {
// only thing we can do is to return undefined and discard the
// result of the RPC. If an error occurred then print the error
// to the console.
callback = err => {
callback = (err) => {
err && Meteor._debug("Error invoking Method '" + name + "'", err);
};
} else {
@@ -881,7 +880,7 @@ export class Connection {
// block waiting for the result.
if (future) {
return options.returnStubValue
? future
? future.then(() => stubReturnValue)
: {
stubValuePromise: future,
};
@@ -910,7 +909,10 @@ export class Connection {
const randomSeed = { value: null};
const defaultReturn = {
alreadyInSimulation, randomSeed, isFromCallAsync
alreadyInSimulation,
randomSeed,
isFromCallAsync,
stubArgs: args,
};
if (!stub) {
return { ...defaultReturn, hasStub: false };
@@ -956,10 +958,10 @@ export class Connection {
// don't allow stubs to yield.
return Meteor._noYieldsAllowed(() => {
// re-clone, so that the stub can't affect our caller's values
return stub.apply(invocation, EJSON.clone(args));
return stub.apply(invocation, args);
});
} else {
return stub.apply(invocation, EJSON.clone(args));
return stub.apply(invocation, args);
}
};
return { ...defaultReturn, hasStub: true, stubInvocation, invocation };

View File

@@ -128,7 +128,9 @@ export default class LocalCollection {
// XXX possibly enforce that 'undefined' does not appear (we assume
// this in our handling of null and $exists)
insert(doc, callback) {
const docId = doc._id;
doc = EJSON.clone(doc);
doc._id = docId;
const id = this.prepareInsert(doc);
const queriesToRecompute = [];
@@ -171,7 +173,9 @@ export default class LocalCollection {
return id;
}
async insertAsync(doc, callback) {
const docId = doc._id;
doc = EJSON.clone(doc);
doc._id = docId;
const id = this.prepareInsert(doc);
const queriesToRecompute = [];

View File

@@ -175,13 +175,13 @@ if (Meteor.isServer) {
// verify that we only fetch the fields specified - we should
// be fetching just field1, field2, and field3.
restrictedCollectionForFetchTest.allow({
insert: function() { return true; },
update: function(userId, doc) {
insertAsync: function() { return true; },
updateAsync: function(userId, doc) {
// throw fields in doc so that we can inspect them in test
throw new Meteor.Error(
999, "Test: Fields in doc: " + _.keys(doc).sort().join(','));
},
remove: function(userId, doc) {
removeAsync: function(userId, doc) {
// throw fields in doc so that we can inspect them in test
throw new Meteor.Error(
999, "Test: Fields in doc: " + _.keys(doc).sort().join(','));
@@ -198,13 +198,13 @@ if (Meteor.isServer) {
// verify that not passing fetch to one of the calls to allow
// causes all fields to be fetched
restrictedCollectionForFetchAllTest.allow({
insert: function() { return true; },
update: function(userId, doc) {
insertAsync: function() { return true; },
updateAsync: function(userId, doc) {
// throw fields in doc so that we can inspect them in test
throw new Meteor.Error(
999, "Test: Fields in doc: " + _.keys(doc).sort().join(','));
},
remove: function(userId, doc) {
removeAsync: function(userId, doc) {
// throw fields in doc so that we can inspect them in test
throw new Meteor.Error(
999, "Test: Fields in doc: " + _.keys(doc).sort().join(','));
@@ -212,7 +212,7 @@ if (Meteor.isServer) {
fetch: ['field1']
});
restrictedCollectionForFetchAllTest.allow({
update: function() { return true; }
updateAsync: function() { return true; }
});
}
@@ -316,34 +316,83 @@ if (Meteor.isClient) {
// test that we only fetch the fields specified
testAsyncMulti("collection - fetch, " + idGeneration, [
function (test, expect) {
var fetchId = restrictedCollectionForFetchTest.insert(
{field1: 1, field2: 1, field3: 1, field4: 1});
var fetchAllId = restrictedCollectionForFetchAllTest.insert(
{field1: 1, field2: 1, field3: 1, field4: 1});
restrictedCollectionForFetchTest.update(
fetchId, {$set: {updated: true}}, expect(function (err, res) {
test.equal(err.reason,
"Test: Fields in doc: _id,field1,field2,field3");
}));
restrictedCollectionForFetchTest.remove(
fetchId, expect(function (err, res) {
test.equal(err.reason,
"Test: Fields in doc: _id,field1,field2,field3");
}));
testAsyncMulti('collection - fetch, ' + idGeneration, [
async function(test, expect) {
var fetchId = await restrictedCollectionForFetchTest.insertAsync({
field1: 1,
field2: 1,
field3: 1,
field4: 1,
},{
returnServerResultPromise: true,
});
var fetchAllId = await restrictedCollectionForFetchAllTest.insertAsync({
field1: 1,
field2: 1,
field3: 1,
field4: 1,
},{
returnServerResultPromise: true,
});
await restrictedCollectionForFetchTest
.updateAsync(
fetchId,
{ $set: { updated: true } },
{
returnServerResultPromise: true,
}
)
.catch(
expect(function(err) {
test.equal(
err.reason,
'Test: Fields in doc: _id,field1,field2,field3'
);
})
);
restrictedCollectionForFetchAllTest.update(
fetchAllId, {$set: {updated: true}}, expect(function (err, res) {
test.equal(err.reason,
"Test: Fields in doc: _id,field1,field2,field3,field4");
}));
restrictedCollectionForFetchAllTest.remove(
fetchAllId, expect(function (err, res) {
test.equal(err.reason,
"Test: Fields in doc: _id,field1,field2,field3,field4");
}));
}
await restrictedCollectionForFetchTest
.removeAsync(fetchId, {
returnServerResultPromise: true,
})
.catch(
expect(function(err) {
test.equal(
err.reason,
'Test: Fields in doc: _id,field1,field2,field3'
);
})
);
await restrictedCollectionForFetchAllTest
.updateAsync(
fetchAllId,
{ $set: { updated: true } },
{
returnServerResultPromise: true,
}
)
.catch(
expect(function(err) {
test.equal(
err.reason,
'Test: Fields in doc: _id,field1,field2,field3,field4'
);
})
);
await restrictedCollectionForFetchAllTest
.removeAsync(fetchAllId, {
returnServerResultPromise: true,
})
.catch(
expect(function(err) {
test.equal(
err.reason,
'Test: Fields in doc: _id,field1,field2,field3,field4'
);
})
);
},
]);
(function(){