Skip to content

Commit

Permalink
Merge pull request strongloop#1391 from strongloop/feature/connector-…
Browse files Browse the repository at this point in the history
…refactor

Make the test compatible with latest juggler
  • Loading branch information
raymondfeng committed May 13, 2015
2 parents 28a0537 + 20c9695 commit b3b6df3
Showing 1 changed file with 78 additions and 25 deletions.
103 changes: 78 additions & 25 deletions test/replication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,22 @@ describe('Replication / Change APIs', function() {
},
function replicateWith3rdPartyModifyingData(next) {
setupRaceConditionInReplication(function(cb) {
TargetModel.dataSource.connector.updateAttributes(
TargetModel.modelName,
'1',
{ name: '3rd-party' },
cb);
var connector = TargetModel.dataSource.connector;
if (connector.updateAttributes.length <= 4) {
connector.updateAttributes(
TargetModel.modelName,
'1',
{name: '3rd-party'},
cb);
} else {
// 2.x connectors require `options`
connector.updateAttributes(
TargetModel.modelName,
'1',
{name: '3rd-party'},
{}, // options
cb);
}
});

SourceModel.replicate(
Expand All @@ -325,11 +336,21 @@ describe('Replication / Change APIs', function() {
// of UPDATE is fixed to correctly remove properties
createModel(SourceModel, { id: '1', name: 'source' }),
function replicateWith3rdPartyModifyingData(next) {
var connector = TargetModel.dataSource.connector;
setupRaceConditionInReplication(function(cb) {
TargetModel.dataSource.connector.create(
TargetModel.modelName,
{ id: '1', name: '3rd-party' },
cb);
if (connector.create.length <= 3) {
connector.create(
TargetModel.modelName,
{id: '1', name: '3rd-party'},
cb);
} else {
// 2.x connectors require `options`
connector.create(
TargetModel.modelName,
{id: '1', name: '3rd-party'},
{}, // options
cb);
}
});

SourceModel.replicate(
Expand Down Expand Up @@ -359,11 +380,22 @@ describe('Replication / Change APIs', function() {
},
function replicateWith3rdPartyModifyingData(next) {
setupRaceConditionInReplication(function(cb) {
TargetModel.dataSource.connector.updateAttributes(
TargetModel.modelName,
'1',
{ name: '3rd-party' },
cb);
var connector = TargetModel.dataSource.connector;
if (connector.updateAttributes.length <= 4) {
connector.updateAttributes(
TargetModel.modelName,
'1',
{name: '3rd-party'},
cb);
} else {
// 2.x connectors require `options`
connector.updateAttributes(
TargetModel.modelName,
'1',
{name: '3rd-party'},
{}, // options
cb);
}
});

SourceModel.replicate(
Expand Down Expand Up @@ -392,11 +424,21 @@ describe('Replication / Change APIs', function() {
SourceModel.deleteById('1', next);
},
function setup3rdPartyModifyingData(next) {
var connector = TargetModel.dataSource.connector;
setupRaceConditionInReplication(function(cb) {
TargetModel.dataSource.connector.destroy(
TargetModel.modelName,
'1',
cb);
if (connector.destroy.length <= 3) {
connector.destroy(
TargetModel.modelName,
'1',
cb);
} else {
// 2.x connectors require `options`
connector.destroy(
TargetModel.modelName,
'1',
{}, // options
cb);
}
});
next();
},
Expand Down Expand Up @@ -681,13 +723,24 @@ describe('Replication / Change APIs', function() {
// make sure we bypass find+create and call the connector directly
SourceModel.dataSource.connector.findOrCreate =
function(model, query, data, callback) {
this.all(model, query, function(err, list) {
if (err || (list && list[0]))
return callback(err, list && list[0], false);
this.create(model, data, function(err) {
callback(err, data, true);
});
}.bind(this));
if (this.all.length <= 3) {
this.all(model, query, function(err, list) {
if (err || (list && list[0]))
return callback(err, list && list[0], false);
this.create(model, data, function(err) {
callback(err, data, true);
});
}.bind(this));
} else {
// 2.x connectors requires `options`
this.all(model, query, {}, function(err, list) {
if (err || (list && list[0]))
return callback(err, list && list[0], false);
this.create(model, data, {}, function(err) {
callback(err, data, true);
});
}.bind(this));
}
};

SourceModel.findOrCreate(
Expand Down

0 comments on commit b3b6df3

Please sign in to comment.