Skip to content

Commit

Permalink
test: account.profile.update() bug (hoodiehq-archive/hoodie-account#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jul 18, 2016
1 parent 309807c commit ec46f7b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/fixtures/update-profile.json
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"
}
}
}
56 changes: 56 additions & 0 deletions test/integration/update-profile-test.js
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)
})

0 comments on commit ec46f7b

Please sign in to comment.