My test accesses the class-level `load` method of a CoffeeScript class (
FooBar) that extends AngularJS's $resource.
I expect that, when trying to access a protected URL via 'FooBar.load(...)`,
that the URL will be re-directed to the sign-in page. That's how the
regular app (when testing it within Chrome/Firefox) works.
describe 'Resource', ->
# load the filter's module
beforeEach module 'myApp'
describe "accessing an endpoint when not authenticated", ->
$location = FooBar = $state = $httpBackend = {}
beforeEach inject ['$location', 'FooBar', '$stateParams',
'$httpBackend', (_$location_, _FooBar_, _$state_, _$httpBackend_) ->
$location = _$location_
FooBar = _FooBar_
$state = _$state_
$httpBackend = _$httpBackend_
]
beforeEach ->
protectedResource= '//localhost:3000/path/to/protected/resource/1'
signin = '/sign-in.html'
$httpBackend.expect('GET', protectedResource).respond(
->
{}
)
$httpBackend.expect('GET', signin).respond(
->
{}
)
afterEach ->
$httpBackend.verifyNoOutstandingExpectation()
$httpBackend.verifyNoOutstandingRequest()
it "result in accessing the sign-in page since we're not yet
authenticated", ->
loadUrl = '/path/to/protected/resource/1'
FooBar.load(loadUrl, 'GET')
$httpBackend.flush() # fire the
async HTTP requests
console.log "$location.absUrl():", $location.absUrl() # LOG:
'$location.absUrl():', 'http://server/'
console.log "$state.current:", $state.current # LOG:
'$state.current', Object{name: '', url: '^', views: null, abstract: true}
How can I test that, when accessing my protected resource, that I get
re-directed to the sign-in page?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.