@@ -16,14 +16,16 @@ import {
1616import { UserCredentialsFixture } from '../fixtures/login.fixture' ;
1717import { fail } from 'node:assert' ;
1818import { paths } from '@internxt/sdk/dist/schema' ;
19+ import { CacheService } from '../../src/services/cache.service' ;
1920
2021describe ( 'Auth service' , ( ) => {
2122 beforeEach ( ( ) => {
2223 vi . spyOn ( ConfigService . instance , 'readUser' ) . mockResolvedValue ( UserCredentialsFixture ) ;
2324 vi . spyOn ( ConfigService . instance , 'saveUser' ) . mockResolvedValue ( undefined ) ;
25+ vi . spyOn ( CacheService . instance , 'get' ) . mockReturnValue ( undefined ) ;
2426 } ) ;
2527
26- it ( 'When user logs in, then login user credentials are generated ' , async ( ) => {
28+ it ( 'should generate login user credentials when user logs in ' , async ( ) => {
2729 const loginResponse = {
2830 token : crypto . randomBytes ( 16 ) . toString ( 'hex' ) ,
2931 newToken : crypto . randomBytes ( 16 ) . toString ( 'hex' ) ,
@@ -48,7 +50,7 @@ describe('Auth service', () => {
4850 expect ( responseLogin ) . to . be . deep . equal ( expectedResponseLogin ) ;
4951 } ) ;
5052
51- it ( 'When user logs in and credentials are not correct, then an error is thrown ' , async ( ) => {
53+ it ( 'should throw an error when user logs in and credentials are not correct' , async ( ) => {
5254 const loginDetails : LoginDetails = {
5355 email : crypto . randomBytes ( 16 ) . toString ( 'hex' ) ,
5456 password : crypto . randomBytes ( 8 ) . toString ( 'hex' ) ,
@@ -67,7 +69,7 @@ describe('Auth service', () => {
6769 expect ( loginStub ) . toHaveBeenCalledOnce ( ) ;
6870 } ) ;
6971
70- it ( 'When two factor authentication is enabled, then it is returned from is2FANeeded functionality ' , async ( ) => {
72+ it ( 'should return true from is2FANeeded when two factor authentication is enabled ' , async ( ) => {
7173 const email = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
7274 const securityDetails : SecurityDetails = {
7375 encryptedSalt : crypto . randomBytes ( 16 ) . toString ( 'hex' ) ,
@@ -83,7 +85,7 @@ describe('Auth service', () => {
8385 expect ( responseLogin ) . to . be . equal ( securityDetails . tfaEnabled ) ;
8486 } ) ;
8587
86- it ( 'When email is not correct when checking two factor authentication, then an error is thrown ' , async ( ) => {
88+ it ( 'should throw an error when checking two factor authentication with an incorrect email ' , async ( ) => {
8789 const email = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
8890
8991 const securityStub = vi . spyOn ( Auth . prototype , 'securityDetails' ) . mockRejectedValue ( new Error ( ) ) ;
@@ -98,7 +100,7 @@ describe('Auth service', () => {
98100 expect ( securityStub ) . toHaveBeenCalledOnce ( ) ;
99101 } ) ;
100102
101- it ( 'When getting auth details, should get them if all are found' , async ( ) => {
103+ it ( 'should return auth details when all credentials are found' , async ( ) => {
102104 const sut = AuthService . instance ;
103105
104106 const loginCreds : LoginCredentials = UserCredentialsFixture ;
@@ -125,7 +127,7 @@ describe('Auth service', () => {
125127 expect ( result ) . to . deep . equal ( loginCreds ) ;
126128 } ) ;
127129
128- it ( 'When credentials are missing, should throw an error' , async ( ) => {
130+ it ( 'should throw an error when credentials are missing ' , async ( ) => {
129131 const sut = AuthService . instance ;
130132
131133 const readUserStub = vi . spyOn ( ConfigService . instance , 'readUser' ) . mockResolvedValue ( undefined ) ;
@@ -139,7 +141,7 @@ describe('Auth service', () => {
139141 expect ( readUserStub ) . toHaveBeenCalledOnce ( ) ;
140142 } ) ;
141143
142- it ( 'When auth token is missing, should throw an error ' , async ( ) => {
144+ it ( 'should throw an error when auth token is missing ' , async ( ) => {
143145 const sut = AuthService . instance ;
144146
145147 const readUserStub = vi . spyOn ( ConfigService . instance , 'readUser' ) . mockResolvedValue ( {
@@ -157,7 +159,7 @@ describe('Auth service', () => {
157159 expect ( readUserStub ) . toHaveBeenCalledOnce ( ) ;
158160 } ) ;
159161
160- it ( 'When mnemonic is invalid, should throw an error' , async ( ) => {
162+ it ( 'should throw an error when mnemonic is invalid ' , async ( ) => {
161163 const sut = AuthService . instance ;
162164
163165 const mockToken = {
@@ -185,7 +187,7 @@ describe('Auth service', () => {
185187 expect ( validateMnemonicStub ) . toHaveBeenCalledWith ( UserCredentialsFixture . user . mnemonic ) ;
186188 } ) ;
187189
188- it ( 'When token has expired, should throw an error' , async ( ) => {
190+ it ( 'should throw an error when token has expired ' , async ( ) => {
189191 const sut = AuthService . instance ;
190192
191193 const mockToken = {
@@ -213,7 +215,7 @@ describe('Auth service', () => {
213215 expect ( validateMnemonicStub ) . toHaveBeenCalledWith ( UserCredentialsFixture . user . mnemonic ) ;
214216 } ) ;
215217
216- it ( 'When tokens are going to expire soon, then they are refreshed ' , async ( ) => {
218+ it ( 'should refresh tokens when they are going to expire soon' , async ( ) => {
217219 const sut = AuthService . instance ;
218220
219221 const mockToken = {
0 commit comments