From ccaee4488ed5883482dd718f57ec4b870d6f6903 Mon Sep 17 00:00:00 2001 From: thenamesben Date: Wed, 7 Feb 2018 20:23:58 -0800 Subject: [PATCH 1/2] add default value for createdAt on account creation. followed suggestions from https://github.com/hoodiehq/hoodie-account-server-api/issues/66 --- lib/accounts/add.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 76ffe40f60e7c6e805546b1be922f5d45fbd9031 Mon Sep 17 00:00:00 2001 From: thenamesben Date: Wed, 7 Feb 2018 21:14:11 -0800 Subject: [PATCH 2/2] Created test for createdAt default value --- test/unit/accounts/add-test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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)