Skip to content

Commit b5a8d3a

Browse files
committed
Adding create tests to auth_test.js
1 parent 0116259 commit b5a8d3a

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/simperium/auth_test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff 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
} )

0 commit comments

Comments
 (0)