1
1
import * as jwtDecode from 'jwt-decode' ;
2
- import { AccountsServer } from '../src/accounts-server' ;
2
+ import { AccountsServer , JwtData } from '../src/accounts-server' ;
3
3
import {
4
4
bcryptPassword ,
5
5
hashPassword ,
@@ -100,10 +100,9 @@ describe('AccountsServer', () => {
100
100
) ;
101
101
102
102
const res = await accountsServer . loginWithUser ( user , { } ) ;
103
- expect ( res . user ) . toEqual ( user ) ;
104
103
const { accessToken, refreshToken } = res . tokens ;
105
- const decodedAccessToken : any = jwtDecode ( accessToken ) ;
106
- expect ( decodedAccessToken . data . sessionId ) . toEqual ( 'sessionId' ) ;
104
+ const decodedAccessToken : { data : JwtData } = jwtDecode ( accessToken ) ;
105
+ expect ( decodedAccessToken . data . token ) . toBeTruthy ( ) ;
107
106
expect ( accessToken ) . toBeTruthy ( ) ;
108
107
expect ( refreshToken ) . toBeTruthy ( ) ;
109
108
} ) ;
@@ -114,7 +113,7 @@ describe('AccountsServer', () => {
114
113
const accountsServer = new AccountsServer (
115
114
{
116
115
db : {
117
- findSessionById : ( ) =>
116
+ findSessionByToken : ( ) =>
118
117
Promise . resolve ( {
119
118
sessionId : '456' ,
120
119
valid : true ,
@@ -146,7 +145,7 @@ describe('AccountsServer', () => {
146
145
const accountsServer = new AccountsServer (
147
146
{
148
147
db : {
149
- findSessionById : ( ) =>
148
+ findSessionByToken : ( ) =>
150
149
Promise . resolve ( {
151
150
sessionId : '456' ,
152
151
valid : true ,
@@ -218,7 +217,7 @@ describe('AccountsServer', () => {
218
217
const accountsServer = new AccountsServer (
219
218
{
220
219
db : {
221
- findSessionById : ( ) =>
220
+ findSessionByToken : ( ) =>
222
221
Promise . resolve ( {
223
222
sessionId : '456' ,
224
223
valid : true ,
@@ -243,7 +242,7 @@ describe('AccountsServer', () => {
243
242
const accountsServer = new AccountsServer (
244
243
{
245
244
db : {
246
- findSessionById : ( ) =>
245
+ findSessionByToken : ( ) =>
247
246
Promise . resolve ( {
248
247
sessionId : '456' ,
249
248
valid : true ,
@@ -276,7 +275,7 @@ describe('AccountsServer', () => {
276
275
const accountsServer = new AccountsServer (
277
276
{
278
277
db : {
279
- findSessionById : ( ) =>
278
+ findSessionByToken : ( ) =>
280
279
Promise . resolve ( {
281
280
sessionId : '456' ,
282
281
valid : true ,
@@ -306,7 +305,7 @@ describe('AccountsServer', () => {
306
305
const accountsServer = new AccountsServer (
307
306
{
308
307
db : {
309
- findSessionById : ( ) =>
308
+ findSessionByToken : ( ) =>
310
309
Promise . resolve ( {
311
310
sessionId : '456' ,
312
311
valid : false ,
@@ -341,7 +340,7 @@ describe('AccountsServer', () => {
341
340
const accountsServer = new AccountsServer (
342
341
{
343
342
db : {
344
- findSessionById : ( ) => Promise . reject ( '' ) ,
343
+ findSessionByToken : ( ) => Promise . reject ( '' ) ,
345
344
findUserById : ( ) => Promise . resolve ( user ) ,
346
345
} as any ,
347
346
tokenSecret : 'secret' ,
@@ -367,7 +366,7 @@ describe('AccountsServer', () => {
367
366
const accountsServer = new AccountsServer (
368
367
{
369
368
db : {
370
- findSessionById : ( ) =>
369
+ findSessionByToken : ( ) =>
371
370
Promise . resolve ( {
372
371
valid : false ,
373
372
} ) ,
@@ -402,7 +401,7 @@ describe('AccountsServer', () => {
402
401
const accountsServer = new AccountsServer (
403
402
{
404
403
db : {
405
- findSessionById : ( ) =>
404
+ findSessionByToken : ( ) =>
406
405
Promise . resolve ( {
407
406
sessionId : '456' ,
408
407
valid : true ,
@@ -504,7 +503,7 @@ describe('AccountsServer', () => {
504
503
const accountsServer = new AccountsServer (
505
504
{
506
505
db : {
507
- findSessionById : ( ) =>
506
+ findSessionByToken : ( ) =>
508
507
Promise . resolve ( {
509
508
sessionId : '456' ,
510
509
valid : true ,
@@ -528,7 +527,10 @@ describe('AccountsServer', () => {
528
527
'ip' ,
529
528
'user agent'
530
529
) ;
531
- expect ( updateSession . mock . calls [ 0 ] ) . toEqual ( [ '456' , 'ip' , 'user agent' ] ) ;
530
+ expect ( updateSession . mock . calls [ 0 ] ) . toEqual ( [
531
+ '456' ,
532
+ { ip : 'ip' , userAgent : 'user agent' } ,
533
+ ] ) ;
532
534
expect ( res . user ) . toEqual ( {
533
535
userId : '123' ,
534
536
username : 'username' ,
@@ -577,7 +579,7 @@ describe('AccountsServer', () => {
577
579
const accountsServer = new AccountsServer (
578
580
{
579
581
db : {
580
- findSessionById : ( ) => Promise . resolve ( null ) ,
582
+ findSessionByToken : ( ) => Promise . resolve ( null ) ,
581
583
} as any ,
582
584
tokenSecret : 'secret' ,
583
585
} ,
@@ -601,7 +603,7 @@ describe('AccountsServer', () => {
601
603
const accountsServer = new AccountsServer (
602
604
{
603
605
db : {
604
- findSessionById : ( ) =>
606
+ findSessionByToken : ( ) =>
605
607
Promise . resolve ( {
606
608
valid : false ,
607
609
} ) ,
@@ -628,7 +630,7 @@ describe('AccountsServer', () => {
628
630
const accountsServer = new AccountsServer (
629
631
{
630
632
db : {
631
- findSessionById : ( ) =>
633
+ findSessionByToken : ( ) =>
632
634
Promise . resolve ( {
633
635
sessionId : '456' ,
634
636
valid : true ,
@@ -690,7 +692,7 @@ describe('AccountsServer', () => {
690
692
const accountsServer = new AccountsServer (
691
693
{
692
694
db : {
693
- findSessionById : ( ) => Promise . resolve ( null ) ,
695
+ findSessionByToken : ( ) => Promise . resolve ( null ) ,
694
696
} as any ,
695
697
tokenSecret : 'secret' ,
696
698
} ,
@@ -708,7 +710,7 @@ describe('AccountsServer', () => {
708
710
const accountsServer = new AccountsServer (
709
711
{
710
712
db : {
711
- findSessionById : ( ) =>
713
+ findSessionByToken : ( ) =>
712
714
Promise . resolve ( {
713
715
valid : false ,
714
716
} ) ,
@@ -748,7 +750,7 @@ describe('AccountsServer', () => {
748
750
const accountsServer = new AccountsServer (
749
751
{
750
752
db : {
751
- findSessionById : ( ) =>
753
+ findSessionByToken : ( ) =>
752
754
Promise . resolve ( {
753
755
sessionId : '456' ,
754
756
valid : true ,
@@ -779,7 +781,7 @@ describe('AccountsServer', () => {
779
781
const accountsServer = new AccountsServer (
780
782
{
781
783
db : {
782
- findSessionById : ( ) =>
784
+ findSessionByToken : ( ) =>
783
785
Promise . resolve ( {
784
786
sessionId : '456' ,
785
787
valid : false ,
@@ -804,7 +806,7 @@ describe('AccountsServer', () => {
804
806
const accountsServer = new AccountsServer (
805
807
{
806
808
db : {
807
- findSessionById : ( ) =>
809
+ findSessionByToken : ( ) =>
808
810
Promise . resolve ( {
809
811
sessionId : '456' ,
810
812
valid : true ,
@@ -1148,14 +1150,9 @@ describe('AccountsServer', () => {
1148
1150
tokens : { sessionId : '001' , isImpersonated : true } ,
1149
1151
user : impersonatedUser ,
1150
1152
} ) ;
1151
- expect ( createSession ) . toHaveBeenCalledWith (
1152
- impersonatedUser . id ,
1153
- null ,
1154
- null ,
1155
- {
1156
- impersonatorUserId : user . id ,
1157
- }
1158
- ) ;
1153
+ expect ( createSession . mock . calls [ 0 ] [ 3 ] ) . toEqual ( {
1154
+ impersonatorUserId : user . id ,
1155
+ } ) ;
1159
1156
} ) ;
1160
1157
} ) ;
1161
1158
0 commit comments