diff --git a/lib/accounts/add.js b/lib/accounts/add.js index d90b3bd..3d7a331 100644 --- a/lib/accounts/add.js +++ b/lib/accounts/add.js @@ -39,7 +39,7 @@ function addAccount (state, properties, options) { type: 'user', name: lowercaseUsername, password: properties.password, - createdAt: properties.createdAt, + createdAt: properties.createdAt || new Date().toISOString(), signedUpAt: properties.signedUpAt, roles: [ 'id:' + accountId diff --git a/test/unit/accounts/add-test.js b/test/unit/accounts/add-test.js index ba61d5f..7515c17 100644 --- a/test/unit/accounts/add-test.js +++ b/test/unit/accounts/add-test.js @@ -81,6 +81,28 @@ test('addAccount', function (group) { .catch(t.catch) }) + group.test('sets default createdAt', function (t) { + t.plan(1) + + var state = { + cache: { + set: simple.stub().resolveWith({}) + }, + setupPromise: Promise.resolve() + } + + addAccount(state, { + username: 'foo' + }) + + .then(function () { + var doc = state.cache.set.lastCall.arg + t.notEqual(doc.createdAt, undefined) + }) + + .catch(t.catch) + }) + group.test('with existing username', function (t) { t.plan(3)