Set application's id property only if it's empty.
Fix `Application.resetKeys()` to reset instance id only if it is not already set. This fixes a bug where each call of resetKeys created a new instance.
This commit is contained in:
parent
34fca67ee0
commit
ce48521efb
|
@ -92,7 +92,9 @@ module.exports = function(Application) {
|
|||
|
||||
var app = ctx.instance;
|
||||
app.created = app.modified = new Date();
|
||||
if (!app.id) {
|
||||
app.id = generateKey('id', 'md5');
|
||||
}
|
||||
app.clientKey = generateKey('client');
|
||||
app.javaScriptKey = generateKey('javaScript');
|
||||
app.restApiKey = generateKey('restApi');
|
||||
|
|
|
@ -174,6 +174,30 @@ describe('Application', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('Reset keys without create a new instance', function(done) {
|
||||
Application.resetKeys(registeredApp.id, function(err, result) {
|
||||
var app = result;
|
||||
assert(app.id);
|
||||
assert(app.id === registeredApp.id);
|
||||
registeredApp = app;
|
||||
done(err, result);
|
||||
});
|
||||
});
|
||||
|
||||
it('Reset keys without create a new instance - promise variant', function(done) {
|
||||
Application.resetKeys(registeredApp.id)
|
||||
.then(function(result) {
|
||||
var app = result;
|
||||
assert(app.id);
|
||||
assert(app.id === registeredApp.id);
|
||||
registeredApp = app;
|
||||
done();
|
||||
})
|
||||
.catch(function(err) {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('Authenticate with application id & clientKey', function(done) {
|
||||
Application.authenticate(registeredApp.id, registeredApp.clientKey,
|
||||
function(err, result) {
|
||||
|
|
Loading…
Reference in New Issue