@@ -4,7 +4,7 @@ import { ApiResponse, AuthToken, Authorizer } from '../lib';
44const authorizerConfig = {
55 authorizerURL : 'http://localhost:8080' ,
66 redirectURL : 'http://localhost:8080/app' ,
7- clientID : '3fab5e58-5693-46f2-8123-83db8133cd22' ,
7+ // clientID: '3fab5e58-5693-46f2-8123-83db8133cd22',
88 adminSecret : 'secret' ,
99} ;
1010
@@ -24,17 +24,21 @@ const authorizerENV = {
2424 DATABASE_URL : 'data.db' ,
2525 DATABASE_TYPE : 'sqlite' ,
2626 CUSTOM_ACCESS_TOKEN_SCRIPT :
27- ' function(user,tokenPayload){var data = tokenPayload;data.extra = {\ 'x-extra-id\ ': user.id};return data;}' ,
27+ " function(user,tokenPayload){var data = tokenPayload;data.extra = {'x-extra-id': user.id};return data;}" ,
2828 DISABLE_PLAYGROUND : 'true' ,
2929 SMTP_HOST : 'smtp.ethereal.email' ,
3030 SMTP_PASSWORD : 'WncNxwVFqb6nBjKDQJ' ,
3131 SMTP_USERNAME : 'sydnee.lesch77@ethereal.email' ,
32+ LOG_LELVEL : 'debug' ,
3233 SMTP_PORT : '587' ,
3334 SENDER_EMAIL : 'test@authorizer.dev' ,
3435 ADMIN_SECRET : 'secret' ,
3536} ;
3637
37- const verificationRequests = 'query {_verification_requests { verification_requests { id token email expires identifier } } }' ;
38+ // const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
39+
40+ const verificationRequests =
41+ 'query {_verification_requests { verification_requests { id token email expires identifier } } }' ;
3842
3943describe ( 'Integration Tests - authorizer-js' , ( ) => {
4044 let container : StartedTestContainer ;
@@ -45,21 +49,30 @@ describe('Integration Tests - authorizer-js', () => {
4549 container = await new GenericContainer ( 'lakhansamani/authorizer:latest' )
4650 . withEnvironment ( authorizerENV )
4751 . withExposedPorts ( 8080 )
48- . withWaitStrategy ( Wait . forHttp ( '/userinfo ' , 8080 ) . forStatusCode ( 401 ) )
52+ . withWaitStrategy ( Wait . forHttp ( '/health ' , 8080 ) . forStatusCode ( 200 ) )
4953 . start ( ) ;
5054
51- authorizerConfig . authorizerURL = `http://${ container . getHost ( ) } :${ container . getFirstMappedPort ( ) } ` ;
52- authorizerConfig . redirectURL = `http://${ container . getHost ( ) } :${ container . getFirstMappedPort ( ) } /app` ;
53-
55+ authorizerConfig . authorizerURL = `http://${ container . getHost ( ) } :${ container . getMappedPort (
56+ 8080 ,
57+ ) } `;
58+ authorizerConfig . redirectURL = `http://${ container . getHost ( ) } :${ container . getMappedPort (
59+ 8080 ,
60+ ) } /app`;
61+ console . log ( 'Authorizer URL:' , authorizerConfig . authorizerURL ) ;
5462 authorizer = new Authorizer ( authorizerConfig ) ;
5563 // get metadata
5664 const metadataRes = await authorizer . getMetaData ( ) ;
65+ // await sleep(50000);
5766 expect ( metadataRes ?. data ) . toBeDefined ( ) ;
5867 if ( metadataRes ?. data ?. client_id ) {
5968 authorizer . config . clientID = metadataRes ?. data ?. client_id ;
6069 }
6170 } ) ;
6271
72+ afterAll ( async ( ) => {
73+ await container . stop ( ) ;
74+ } ) ;
75+
6376 it ( 'should signup with email verification enabled' , async ( ) => {
6477 const signupRes = await authorizer . signup ( {
6578 email : testConfig . email ,
@@ -85,7 +98,7 @@ describe('Integration Tests - authorizer-js', () => {
8598 expect ( verificationRequestsRes ?. data ) . toBeDefined ( ) ;
8699 expect ( verificationRequestsRes ?. errors ) . toHaveLength ( 0 ) ;
87100 const item = requests . find (
88- ( i : { email : string } ) => i . email === testConfig . email
101+ ( i : { email : string } ) => i . email === testConfig . email ,
89102 ) ;
90103 expect ( item ) . not . toBeNull ( ) ;
91104
@@ -95,7 +108,7 @@ describe('Integration Tests - authorizer-js', () => {
95108 expect ( verifyEmailRes ?. data ?. access_token ?. length ) . toBeGreaterThan ( 0 ) ;
96109 } ) ;
97110
98- let loginRes :ApiResponse < AuthToken > | null ;
111+ let loginRes : ApiResponse < AuthToken > | null ;
99112 it ( 'should log in successfully' , async ( ) => {
100113 loginRes = await authorizer . login ( {
101114 email : testConfig . email ,
@@ -127,7 +140,7 @@ describe('Integration Tests - authorizer-js', () => {
127140 } ,
128141 {
129142 Authorization : `Bearer ${ loginRes ?. data ?. access_token } ` ,
130- }
143+ } ,
131144 ) ;
132145 expect ( updateProfileRes ?. data ) . toBeDefined ( ) ;
133146 expect ( updateProfileRes ?. errors ) . toHaveLength ( 0 ) ;
@@ -186,16 +199,21 @@ describe('Integration Tests - authorizer-js', () => {
186199 'x-authorizer-admin-secret' : authorizerConfig . adminSecret ,
187200 } ,
188201 } ) ;
189- const requests
190- = verificationRequestsRes ?. data ?. _verification_requests . verification_requests ;
191- const item = requests . find ( ( i :{ email : string } ) => i . email === testConfig . maginLinkLoginEmail ) ;
192- expect ( item ) . not . toBeNull ( ) ;
202+ const requests =
203+ verificationRequestsRes ?. data ?. _verification_requests
204+ . verification_requests ;
205+ const item = requests . find (
206+ ( i : { email : string } ) => i . email === testConfig . maginLinkLoginEmail ,
207+ ) ;
208+ expect ( item ) . not . toBeNull ( ) ;
193209 const verifyEmailRes = await authorizer . verifyEmail ( {
194210 token : item . token ,
195211 } ) ;
196212 expect ( verifyEmailRes ?. data ) . toBeDefined ( ) ;
197213 expect ( verifyEmailRes ?. errors ) . toHaveLength ( 0 ) ;
198- expect ( verifyEmailRes ?. data ?. user ?. signup_methods ) . toContain ( 'magic_link_login' ) ;
214+ expect ( verifyEmailRes ?. data ?. user ?. signup_methods ) . toContain (
215+ 'magic_link_login' ,
216+ ) ;
199217 } ) ;
200218 } ) ;
201219} ) ;
0 commit comments