Browse Source

Merge pull request #264 from isocolsky/ref/preferences

Incremental preferences
activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
4552d3e524
  1. 21
      lib/server.js
  2. 54
      test/integration/server.js

21
lib/server.js

@ -480,6 +480,7 @@ WalletService.prototype.savePreferences = function(opts, cb) {
}, },
}]; }];
opts = _.pick(opts, _.pluck(preferences, 'name'));
try { try {
_.each(preferences, function(preference) { _.each(preferences, function(preference) {
var value = opts[preference.name]; var value = opts[preference.name];
@ -494,15 +495,17 @@ WalletService.prototype.savePreferences = function(opts, cb) {
} }
self._runLocked(cb, function(cb) { self._runLocked(cb, function(cb) {
var preferences = Model.Preferences.create({ self.storage.fetchPreferences(self.walletId, self.copayerId, function(err, oldPref) {
walletId: self.walletId, if (err) return cb(err);
copayerId: self.copayerId,
email: opts.email, var newPref = Model.Preferences.create({
language: opts.language, walletId: self.walletId,
unit: opts.unit, copayerId: self.copayerId,
}); });
self.storage.storePreferences(preferences, function(err) { var preferences = Model.Preferences.fromObj(_.defaults(newPref, opts, oldPref));
return cb(err); self.storage.storePreferences(preferences, function(err) {
return cb(err);
});
}); });
}); });
}; };

54
test/integration/server.js

@ -1160,6 +1160,7 @@ describe('Wallet service', function() {
email: 'dummy@dummy.com', email: 'dummy@dummy.com',
language: 'es', language: 'es',
unit: 'bit', unit: 'bit',
dummy: 'ignored',
}, function(err) { }, function(err) {
should.not.exist(err); should.not.exist(err);
server.getPreferences({}, function(err, preferences) { server.getPreferences({}, function(err, preferences) {
@ -1168,6 +1169,7 @@ describe('Wallet service', function() {
preferences.email.should.equal('dummy@dummy.com'); preferences.email.should.equal('dummy@dummy.com');
preferences.language.should.equal('es'); preferences.language.should.equal('es');
preferences.unit.should.equal('bit'); preferences.unit.should.equal('bit');
should.not.exist(preferences.dummy);
done(); done();
}); });
}); });
@ -1186,6 +1188,58 @@ describe('Wallet service', function() {
}); });
}); });
}); });
it('should save preferences incrementally', function(done) {
async.series([
function(next) {
server.savePreferences({
email: 'dummy@dummy.com',
}, next);
},
function(next) {
server.getPreferences({}, function(err, preferences) {
should.not.exist(err);
should.exist(preferences);
preferences.email.should.equal('dummy@dummy.com');
should.not.exist(preferences.language);
next();
});
},
function(next) {
server.savePreferences({
language: 'es',
}, next);
},
function(next) {
server.getPreferences({}, function(err, preferences) {
should.not.exist(err);
should.exist(preferences);
preferences.language.should.equal('es');
preferences.email.should.equal('dummy@dummy.com');
next();
});
},
function(next) {
server.savePreferences({
language: null,
unit: 'bit',
}, next);
},
function(next) {
server.getPreferences({}, function(err, preferences) {
should.not.exist(err);
should.exist(preferences);
preferences.unit.should.equal('bit');
should.not.exist(preferences.language);
preferences.email.should.equal('dummy@dummy.com');
next();
});
},
], function(err) {
should.not.exist(err);
done();
});
});
it.skip('should save preferences only for requesting wallet', function(done) {}); it.skip('should save preferences only for requesting wallet', function(done) {});
it('should validate entries', function(done) { it('should validate entries', function(done) {
var invalid = [{ var invalid = [{

Loading…
Cancel
Save