forked from FirebaseExtended/angularfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request FirebaseExtended#703 from firebase/de-provider
AngularFire 1.2 - firebaseRefProvider and $firebaseAuthService
- Loading branch information
Showing
4 changed files
with
140 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,12 @@ | ||
(function() { | ||
"use strict"; | ||
|
||
function FirebaseAuthService($firebaseAuth, $firebaseRef) { | ||
return $firebaseAuth($firebaseRef.default); | ||
} | ||
FirebaseAuthService.$inject = ['$firebaseAuth', '$firebaseRef']; | ||
|
||
angular.module('firebase') | ||
.factory('$firebaseAuthService', FirebaseAuthService); | ||
|
||
})(); |
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,46 @@ | ||
(function() { | ||
"use strict"; | ||
|
||
function FirebaseRef() { | ||
this.urls = null; | ||
this.registerUrl = function registerUrl(urlOrConfig) { | ||
|
||
if (typeof urlOrConfig === 'string') { | ||
this.urls = {}; | ||
this.urls.default = urlOrConfig; | ||
} | ||
|
||
if (angular.isObject(urlOrConfig)) { | ||
this.urls = urlOrConfig; | ||
} | ||
|
||
}; | ||
|
||
this.$$checkUrls = function $$checkUrls(urlConfig) { | ||
if (!urlConfig) { | ||
return new Error('No Firebase URL registered. Use firebaseRefProvider.registerUrl() in the config phase. This is required if you are using $firebaseAuthService.'); | ||
} | ||
if (!urlConfig.default) { | ||
return new Error('No default Firebase URL registered. Use firebaseRefProvider.registerUrl({ default: "https://<my-firebase-app>.firebaseio.com/"}).'); | ||
} | ||
}; | ||
|
||
this.$$createRefsFromUrlConfig = function $$createMultipleRefs(urlConfig) { | ||
var refs = {}; | ||
var error = this.$$checkUrls(urlConfig); | ||
if (error) { throw error; } | ||
angular.forEach(urlConfig, function(value, key) { | ||
refs[key] = new Firebase(value); | ||
}); | ||
return refs; | ||
}; | ||
|
||
this.$get = function FirebaseRef_$get() { | ||
return this.$$createRefsFromUrlConfig(this.urls); | ||
}; | ||
} | ||
|
||
angular.module('firebase') | ||
.provider('$firebaseRef', FirebaseRef); | ||
|
||
})(); |
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,27 @@ | ||
'use strict'; | ||
describe('$firebaseAuthService', function () { | ||
var $firebaseRefProvider; | ||
var MOCK_URL = 'https://stub.firebaseio-demo.com/' | ||
|
||
beforeEach(module('firebase', function(_$firebaseRefProvider_) { | ||
$firebaseRefProvider = _$firebaseRefProvider_; | ||
$firebaseRefProvider.registerUrl(MOCK_URL); | ||
})); | ||
|
||
describe('<constructor>', function() { | ||
|
||
var $firebaseAuthService; | ||
beforeEach(function() { | ||
module('firebase'); | ||
inject(function (_$firebaseAuthService_) { | ||
$firebaseAuthService = _$firebaseAuthService_; | ||
}); | ||
}); | ||
|
||
it('should exist because we called $firebaseRefProvider.registerUrl()', inject(function() { | ||
expect($firebaseAuthService).not.toBe(null); | ||
})); | ||
|
||
}); | ||
|
||
}); |
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,55 @@ | ||
'use strict'; | ||
describe('firebaseRef', function () { | ||
|
||
var $firebaseRefProvider; | ||
var MOCK_URL = 'https://stub.firebaseio-demo.com/' | ||
|
||
beforeEach(module('firebase', function(_$firebaseRefProvider_) { | ||
$firebaseRefProvider = _$firebaseRefProvider_; | ||
})); | ||
|
||
describe('registerUrl', function() { | ||
|
||
it('creates a single reference with a url', inject(function() { | ||
$firebaseRefProvider.registerUrl(MOCK_URL); | ||
expect($firebaseRefProvider.$get().default).toBeAFirebaseRef(); | ||
})); | ||
|
||
it('creates a default reference with a config object', inject(function() { | ||
$firebaseRefProvider.registerUrl({ | ||
default: MOCK_URL | ||
}); | ||
var firebaseRef = $firebaseRefProvider.$get(); | ||
expect(firebaseRef.default).toBeAFirebaseRef(); | ||
})); | ||
|
||
it('creates multiple references with a config object', inject(function() { | ||
$firebaseRefProvider.registerUrl({ | ||
default: MOCK_URL, | ||
messages: MOCK_URL + 'messages' | ||
}); | ||
var firebaseRef = $firebaseRefProvider.$get(); | ||
expect(firebaseRef.default).toBeAFirebaseRef(); | ||
expect(firebaseRef.messages).toBeAFirebaseRef(); | ||
})); | ||
|
||
it('should throw an error when no url is provided', inject(function () { | ||
function errorWrapper() { | ||
$firebaseRefProvider.registerUrl(); | ||
$firebaseRefProvider.$get(); | ||
} | ||
expect(errorWrapper).toThrow(); | ||
})); | ||
|
||
it('should throw an error when no default url is provided', inject(function() { | ||
function errorWrapper() { | ||
$firebaseRefProvider.registerUrl({ messages: MOCK_URL + 'messages' }); | ||
$firebaseRefProvider.$get(); | ||
} | ||
expect(errorWrapper).toThrow(); | ||
})); | ||
|
||
|
||
}); | ||
|
||
}); |