@@ -2,7 +2,7 @@ import { Http, BaseRequestOptions, Response, ResponseOptions, Headers, RequestMe
22import { MockBackend } from '@angular/http/testing' ;
33import { provide } from '@angular/core' ;
44import { inject , addProviders } from '@angular/core/testing' ;
5- import { Router } from '@angular/router' ;
5+ import { Router , ActivatedRoute , RouterOutletMap , RouterState } from '@angular/router' ;
66
77import { Angular2TokenService } from './' ;
88
@@ -39,19 +39,19 @@ describe('Angular2TokenService', () => {
3939 confirm_success_url : window . location . href
4040 }
4141
42+ class Mock { }
43+
4244 beforeEach ( ( ) => {
4345 // Inject HTTP and Angular2TokenService
4446 addProviders ( [
4547 BaseRequestOptions ,
4648 MockBackend ,
47- Router ,
48- provide ( Http , {
49- useFactory :
50- function ( backend , defaultOptions ) {
51- return new Http ( backend , defaultOptions ) ;
52- } ,
49+ { provide : Router , useClass : Mock } ,
50+ {
51+ provide : Http ,
52+ useFactory : ( backend , defaultOptions ) => { return new Http ( backend , defaultOptions ) } ,
5353 deps : [ MockBackend , BaseRequestOptions ]
54- } ) ,
54+ } ,
5555 Angular2TokenService
5656 ] ) ;
5757
@@ -115,18 +115,78 @@ describe('Angular2TokenService', () => {
115115 tokenService . registerAccount ( registerData . email , registerData . password , registerData . password_confirmation ) ;
116116 } ) ) ;
117117
118- // Testing Configured Configuration
118+ // Testing Custom Configuration
119119
120- it ( 'signIn method should send to configured api path' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
120+ it ( 'Methods should send to configured path' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
121121
122122 mockBackend . connections . subscribe (
123- c => expect ( c . request . url ) . toEqual ( 'myapi/auth/sign_in ' )
123+ c => expect ( c . request . url ) . toEqual ( 'myapi/myauth/mysignin ' )
124124 ) ;
125125
126- tokenService . init ( { apiPath : 'myapi' } ) ;
126+ tokenService . init ( { apiPath : 'myapi' , signInPath : 'myauth/mysignin' } ) ;
127127 tokenService . signIn ( signInData . email , signInData . password ) ;
128128 } ) ) ;
129129
130+ it ( 'signOut should send to configured path' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
131+
132+ mockBackend . connections . subscribe (
133+ c => expect ( c . request . url ) . toEqual ( 'myapi/myauth/mysignout' )
134+ ) ;
135+
136+ tokenService . init ( { apiPath : 'myapi' , signOutPath : 'myauth/mysignout' } ) ;
137+ tokenService . signOut ( ) ;
138+ } ) ) ;
139+
140+ it ( 'registerAccount should send to configured path' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
141+
142+ mockBackend . connections . subscribe (
143+ c => expect ( c . request . url ) . toEqual ( 'myapi/myauth/myregister' )
144+ ) ;
145+
146+ tokenService . init ( { apiPath : 'myapi' , registerAccountPath : 'myauth/myregister' } ) ;
147+ tokenService . registerAccount ( 'example@example.org' , 'password' , 'password' ) ;
148+ } ) ) ;
149+
150+ it ( 'deleteAccount should send to configured path' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
151+
152+ mockBackend . connections . subscribe (
153+ c => expect ( c . request . url ) . toEqual ( 'myapi/myauth/mydelete' )
154+ ) ;
155+
156+ tokenService . init ( { apiPath : 'myapi' , deleteAccountPath : 'myauth/mydelete' } ) ;
157+ tokenService . deleteAccount ( ) ;
158+ } ) ) ;
159+
160+ it ( 'validateToken should send to configured path' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
161+
162+ mockBackend . connections . subscribe (
163+ c => expect ( c . request . url ) . toEqual ( 'myapi/myauth/myvalidate' )
164+ ) ;
165+
166+ tokenService . init ( { apiPath : 'myapi' , validateTokenPath : 'myauth/myvalidate' } ) ;
167+ tokenService . validateToken ( ) ;
168+ } ) ) ;
169+
170+ it ( 'updatePasswordPath should send to configured path' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
171+
172+ mockBackend . connections . subscribe (
173+ c => expect ( c . request . url ) . toEqual ( 'myapi/myauth/myupdate' )
174+ ) ;
175+
176+ tokenService . init ( { apiPath : 'myapi' , updatePasswordPath : 'myauth/myupdate' } ) ;
177+ tokenService . updatePassword ( 'password' , 'password' ) ;
178+ } ) ) ;
179+
180+ it ( 'resetPasswordPath should send to configured path' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
181+
182+ mockBackend . connections . subscribe (
183+ c => expect ( c . request . url ) . toEqual ( 'myapi/myauth/myreset' )
184+ ) ;
185+
186+ tokenService . init ( { apiPath : 'myapi' , resetPasswordPath : 'myauth/myreset' } ) ;
187+ tokenService . resetPassword ( 'emxaple@example.org' ) ;
188+ } ) ) ;
189+
130190 // Testing Token handling
131191
132192 it ( 'signIn method should receive headers and set local storage' , inject ( [ Angular2TokenService , MockBackend ] , ( tokenService , mockBackend ) => {
0 commit comments