-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: account.profile.update() bug (hoodiehq-archive/hoodie-account#38)
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"links": { | ||
"self": "https://example.com/session/account" | ||
}, | ||
"data": { | ||
"id": "abc123-profile", | ||
"type": "profile", | ||
"attributes": { | ||
"fullName": "Docs Chicken", | ||
"favoriteClothing": "Hoodie" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var store = require('humble-localstorage') | ||
|
||
var test = require('tape') | ||
var nock = require('nock') | ||
|
||
var Account = require('../../index') | ||
|
||
var baseURL = 'http://localhost:3000' | ||
|
||
var signInResponse = require('../fixtures/signin.json') | ||
var updateResponse = require('../fixtures/update-profile.json') | ||
|
||
var options = { | ||
username: '[email protected]', | ||
password: 'secret' | ||
} | ||
|
||
test('sign in and change username', function (t) { | ||
store.clear() | ||
|
||
t.plan(4) | ||
|
||
var account = new Account({ | ||
url: baseURL, | ||
id: 'abc4567' | ||
}) | ||
|
||
nock(baseURL) | ||
.put('/session', function (body) { | ||
return body.data.attributes.password === 'secret' | ||
}) | ||
.reply(201, signInResponse) | ||
.patch('/session/account/profile', function (body) { | ||
t.is(body.data.attributes.fullName, 'Docs Chicken', 'request sends profile properties') | ||
return true | ||
}) | ||
.reply(200, updateResponse) | ||
|
||
account.signIn(options) | ||
|
||
.then(function (signInResult) { | ||
t.pass('signs in') | ||
t.is(signInResult.username, '[email protected]') | ||
|
||
return account.profile.update({ | ||
fullName: 'Docs Chicken', | ||
favoriteClothing: 'Clothing' | ||
}) | ||
}) | ||
|
||
.then(function (profileProperties) { | ||
t.is(profileProperties.fullName, 'Docs Chicken', 'profile.update() resolves with profile properties') | ||
}) | ||
|
||
.catch(t.error) | ||
}) |