File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " simperium" ,
3- "version" : " 0.2.5 " ,
3+ "version" : " 0.2.6 " ,
44 "description" : " A simperium client for node.js" ,
55 "main" : " ./lib/simperium/index.js" ,
66 "repository" : {
Original file line number Diff line number Diff line change @@ -14,15 +14,17 @@ export default function Auth( appId, appSecret ) {
1414inherits ( Auth , EventEmitter ) ;
1515
1616Auth . prototype . authorize = function ( username , password ) {
17- var body = JSON . stringify ( { username : username , password : password } ) ,
17+ var body = JSON . stringify ( { username : username , password : password } ) ,
1818 promise = this . request ( 'authorize/' , body ) ;
1919
2020 return promise ;
2121}
2222
23- // TODO: username and password to create a user
24- Auth . prototype . create = function ( ) {
23+ Auth . prototype . create = function ( username , password ) {
24+ var body = JSON . stringify ( { username : username , password : password } ) ,
25+ promise = this . request ( 'create/' , body ) ;
2526
27+ return promise ;
2628}
2729
2830Auth . prototype . getUrlOptions = function ( path ) {
Original file line number Diff line number Diff line change @@ -61,4 +61,33 @@ describe( 'Auth', () => {
6161 done ( )
6262 } )
6363 } )
64+
65+ it ( 'should create an account with valid credentials' , ( done ) => {
66+ stub ( ( data , handler ) => {
67+ const { username, password } = JSON . parse ( data )
68+ const response = new EventEmitter ( )
69+ equal ( username , 'username' )
70+ equal ( password , 'password' )
71+
72+ handler ( response )
73+ response . emit ( 'data' , '{\"access_token\": \"secret-token\"}' )
74+ response . emit ( 'end' ) ;
75+ } )
76+
77+ auth . create ( 'username' , 'password' )
78+ . then ( ( user ) => {
79+ equal ( user . access_token , 'secret-token' )
80+ done ( )
81+ } )
82+ } )
83+
84+ it ( 'should fail to create an account with invalid credentials' , ( done ) => {
85+ stubResponse ( 'this is not json' )
86+
87+ auth . create ( 'username' , 'bad-password' )
88+ . catch ( ( e ) => {
89+ equal ( e . message , 'this is not json' )
90+ done ( )
91+ } )
92+ } )
6493} )
You can’t perform that action at this time.
0 commit comments