-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proof of concept for account profiles. #158
base: master
Are you sure you want to change the base?
Changes from all commits
1a7a9b6
5fca7ce
cb223fa
940ff81
b3f2a75
b4d1f66
aa21170
e545911
1a20c96
95c58d2
f69ffa9
ed53fe9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,16 @@ function accountRoutes (server, options, next) { | |
handler: function (request, reply) { | ||
var username = request.payload.data.attributes.username | ||
var password = request.payload.data.attributes.password | ||
var profile = request.payload.data.attributes.profile | ||
var id = request.payload.data.id | ||
var query = request.query | ||
accounts.add({ | ||
username: username, | ||
password: password, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gr2m is this correct? Or the below? My understanding is that this should be an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you got it right, good catch |
||
include: query.include, | ||
profile: profile, | ||
id: id | ||
}, { | ||
include: query.include || null | ||
}) | ||
|
||
.then(serialise) | ||
|
@@ -126,6 +129,7 @@ function accountRoutes (server, options, next) { | |
|
||
var newUsername = request.payload.data.attributes.username | ||
var newPassword = request.payload.data.attributes.password | ||
var newProfile = request.payload.data.attributes.profile | ||
var id = request.payload.data.id | ||
|
||
admins.validateSession(sessionId) | ||
|
@@ -154,7 +158,8 @@ function accountRoutes (server, options, next) { | |
} | ||
return accounts.update(session.account, { | ||
username: newUsername, | ||
password: newPassword | ||
password: newPassword, | ||
profile: newProfile | ||
}, { | ||
include: request.query.include | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,8 @@ var mockCouchDbPutUser = nock('http://localhost:5984') | |
derived_key: Joi.string().required(), | ||
iterations: Joi.any().only(10).required(), | ||
password_scheme: Joi.any().only('pbkdf2').required(), | ||
roles: Joi.array().items(Joi.string().regex(/^id:[0-9a-f]{12}$/)).max(1).min(1) | ||
roles: Joi.array().items(Joi.string().regex(/^id:[0-9a-f]{12}$/)).max(1).min(1), | ||
profile: Joi.object().required() | ||
}).validate(body.docs[0]).error === null | ||
}) | ||
.query(true) | ||
|
@@ -76,6 +77,42 @@ getServer(function (error, server) { | |
}) | ||
}) | ||
|
||
group.test('User added with profile', function (t) { | ||
var couchdb = mockCouchDbPutUser | ||
.reply(201, [{ | ||
id: 'org.couchdb.user:pat-doe', | ||
rev: '1-234' | ||
}]) | ||
|
||
var options = _.defaultsDeep({ | ||
url: '/session/account?include=profile', | ||
payload: { | ||
data: { | ||
attributes: { | ||
profile: { | ||
fullName: 'pat Doe', | ||
email: '[email protected]' | ||
} | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}, routeOptions) | ||
|
||
var accountWithProfileFixture = require('../../fixtures/account-with-profile.json') | ||
|
||
server.inject(options, function (response) { | ||
t.is(couchdb.pendingMocks()[0], undefined, 'CouchDB received request') | ||
delete response.result.meta | ||
|
||
t.is(response.statusCode, 201, 'returns 201 status') | ||
response.result.data.id = 'userid123' | ||
response.result.data.relationships.profile.data.id = 'userid123-profile' | ||
response.result.included[0].id = 'userid123-profile' | ||
t.deepEqual(response.result, accountWithProfileFixture, 'returns account in right format') | ||
t.end() | ||
}) | ||
}) | ||
|
||
group.test('CouchDB User already exists', function (t) { | ||
var couchdb = mockCouchDbPutUser | ||
.reply(201, [{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave that in, but replace
account.profile = doc.profile
withaccount.profile = doc.profile || {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restored here: cb223fa