File tree Expand file tree Collapse file tree 3 files changed +25
-9
lines changed
Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ _.extend(Promise, /** @lends AV.Promise */ {
7878 */
7979 as : function ( ) {
8080 var promise = new Promise ( ) ;
81- if ( _ . isFunction ( arguments [ 0 ] ) ) {
81+ if ( arguments [ 0 ] && _ . isFunction ( arguments [ 0 ] . then ) ) {
8282 arguments [ 0 ] . then ( function ( data ) {
8383 promise . resolve . call ( promise , data ) ;
8484 } , function ( err ) {
Original file line number Diff line number Diff line change @@ -415,14 +415,14 @@ module.exports = function(AV) {
415415 dataObject . _MasterKey = AV . masterKey ;
416416 dataObject . _ClientVersion = AV . VERSION ;
417417 // Pass the session token on every request.
418- var currentUser = AV . User . current ( ) ;
419- if ( currentUser && currentUser . _sessionToken ) {
420- dataObject . _SessionToken = currentUser . _sessionToken ;
421- }
422-
423- return AV . _getInstallationId ( ) . then ( function ( _InstallationId ) {
418+ return AV . User . currentAsync ( ) . then ( function ( currentUser ) {
419+ if ( currentUser && currentUser . _sessionToken ) {
420+ dataObject . _SessionToken = currentUser . _sessionToken ;
421+ }
422+ return AV . _getInstallationId ( ) ;
423+ } ) . then ( function ( _InstallationId ) {
424424 dataObject . _InstallationId = _InstallationId ;
425- } ) . then ( function ( ) {
425+
426426 var data = JSON . stringify ( dataObject ) ;
427427 return AV . _ajax ( method , url , data ) . then ( null , function ( response ) {
428428 // Transform the error into an instance of AV.Error by trying to parse
Original file line number Diff line number Diff line change 11describe ( 'promise' , function ( ) {
22 describe ( 'constructor' , function ( ) {
3- it ( 'shoud be resolve with 42.' , function ( done ) {
3+ it ( 'shoud be resolved with 42.' , function ( done ) {
44 var promise = new AV . Promise ( function ( resolve ) {
55 resolve ( 42 ) ;
66 } ) ;
@@ -11,6 +11,22 @@ describe('promise', function() {
1111 } ) ;
1212 } ) ;
1313
14+ describe ( 'as' , function ( ) {
15+ it ( 'should be resolved.' , function ( done ) {
16+ AV . Promise . as ( 42 ) . then ( function ( ret ) {
17+ expect ( ret ) . to . be ( 42 ) ;
18+ done ( ) ;
19+ } ) ;
20+ } ) ;
21+ it ( 'should be resolved when got a Promise.' , function ( done ) {
22+ AV . Promise . as ( Promise . resolve ( 42 ) ) . then ( function ( ret ) {
23+ expect ( ret ) . to . be ( 42 ) ;
24+ done ( ) ;
25+ } ) ;
26+ } ) ;
27+ } ) ;
28+
29+
1430 describe ( 'catch' , function ( ) {
1531 it ( 'shoud catch exception.' , function ( done ) {
1632 var promise = new AV . Promise ( function ( resolve ) {
You can’t perform that action at this time.
0 commit comments