1- import { beforeEach , describe , expect , it , vi } from 'vitest' ;
1+ import { beforeEach , describe , expect , test , vi } from 'vitest' ;
22import crypto from 'node:crypto' ;
33import { Auth , LoginDetails , SecurityDetails } from '@internxt/sdk' ;
44import { AuthService } from '../../src/services/auth.service' ;
@@ -25,7 +25,7 @@ describe('Auth service', () => {
2525 vi . spyOn ( CacheService . instance , 'get' ) . mockReturnValue ( undefined ) ;
2626 } ) ;
2727
28- it ( 'should generate login user credentials when user logs in ', async ( ) => {
28+ test ( 'when the user logs in successfully, then login credentials are generated ', async ( ) => {
2929 const loginResponse = {
3030 token : crypto . randomBytes ( 16 ) . toString ( 'hex' ) ,
3131 newToken : crypto . randomBytes ( 16 ) . toString ( 'hex' ) ,
@@ -50,7 +50,7 @@ describe('Auth service', () => {
5050 expect ( responseLogin ) . to . be . deep . equal ( expectedResponseLogin ) ;
5151 } ) ;
5252
53- it ( 'should throw an error when user logs in and credentials are not correct ', async ( ) => {
53+ test ( ' when the user provides incorrect login credentials, then an error is thrown ', async ( ) => {
5454 const loginDetails : LoginDetails = {
5555 email : crypto . randomBytes ( 16 ) . toString ( 'hex' ) ,
5656 password : crypto . randomBytes ( 8 ) . toString ( 'hex' ) ,
@@ -69,7 +69,7 @@ describe('Auth service', () => {
6969 expect ( loginStub ) . toHaveBeenCalledOnce ( ) ;
7070 } ) ;
7171
72- it ( 'should return true from is2FANeeded when two factor authentication is enabled', async ( ) => {
72+ test ( ' when two- factor authentication is enabled on the account, then the system reports it as required ', async ( ) => {
7373 const email = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
7474 const securityDetails : SecurityDetails = {
7575 encryptedSalt : crypto . randomBytes ( 16 ) . toString ( 'hex' ) ,
@@ -85,7 +85,7 @@ describe('Auth service', () => {
8585 expect ( responseLogin ) . to . be . equal ( securityDetails . tfaEnabled ) ;
8686 } ) ;
8787
88- it ( 'should throw an error when checking two factor authentication with an incorrect email ', async ( ) => {
88+ test ( 'when an invalid email is provided for authentication validation, then an error is thrown ', async ( ) => {
8989 const email = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
9090
9191 const securityStub = vi . spyOn ( Auth . prototype , 'securityDetails' ) . mockRejectedValue ( new Error ( ) ) ;
@@ -100,7 +100,7 @@ describe('Auth service', () => {
100100 expect ( securityStub ) . toHaveBeenCalledOnce ( ) ;
101101 } ) ;
102102
103- it ( 'should return auth details when all credentials are found ', async ( ) => {
103+ test ( 'when all stored credentials are complete and valid, then authentication details are returned ', async ( ) => {
104104 const sut = AuthService . instance ;
105105
106106 const loginCreds : LoginCredentials = UserCredentialsFixture ;
@@ -127,7 +127,7 @@ describe('Auth service', () => {
127127 expect ( result ) . to . deep . equal ( loginCreds ) ;
128128 } ) ;
129129
130- it ( 'should throw an error when credentials are missing ', async ( ) => {
130+ test ( 'when no stored credentials exist, then an error is thrown ', async ( ) => {
131131 const sut = AuthService . instance ;
132132
133133 const readUserStub = vi . spyOn ( ConfigService . instance , 'readUser' ) . mockResolvedValue ( undefined ) ;
@@ -141,7 +141,7 @@ describe('Auth service', () => {
141141 expect ( readUserStub ) . toHaveBeenCalledOnce ( ) ;
142142 } ) ;
143143
144- it ( 'should throw an error when auth token is missing ', async ( ) => {
144+ test ( 'when the session token is missing from stored credentials, then an error is thrown ', async ( ) => {
145145 const sut = AuthService . instance ;
146146
147147 const readUserStub = vi . spyOn ( ConfigService . instance , 'readUser' ) . mockResolvedValue ( {
@@ -159,7 +159,7 @@ describe('Auth service', () => {
159159 expect ( readUserStub ) . toHaveBeenCalledOnce ( ) ;
160160 } ) ;
161161
162- it ( 'should throw an error when mnemonic is invalid ', async ( ) => {
162+ test ( 'when the recovery phrase is invalid, then an error is thrown ', async ( ) => {
163163 const sut = AuthService . instance ;
164164
165165 const mockToken = {
@@ -187,7 +187,7 @@ describe('Auth service', () => {
187187 expect ( validateMnemonicStub ) . toHaveBeenCalledWith ( UserCredentialsFixture . user . mnemonic ) ;
188188 } ) ;
189189
190- it ( 'should throw an error when token has expired', async ( ) => {
190+ test ( 'when the session token has expired, then an error is thrown ', async ( ) => {
191191 const sut = AuthService . instance ;
192192
193193 const mockToken = {
@@ -215,7 +215,7 @@ describe('Auth service', () => {
215215 expect ( validateMnemonicStub ) . toHaveBeenCalledWith ( UserCredentialsFixture . user . mnemonic ) ;
216216 } ) ;
217217
218- it ( 'should refresh tokens when they are going to expire soon ', async ( ) => {
218+ test ( 'when the session token is about to expire, then it is refreshed automatically ', async ( ) => {
219219 const sut = AuthService . instance ;
220220
221221 const mockToken = {
@@ -240,7 +240,7 @@ describe('Auth service', () => {
240240 expect ( refreshTokensStub ) . toHaveBeenCalledOnce ( ) ;
241241 } ) ;
242242
243- it ( 'should clear and throw exception when exception is thrown while refreshing user token ', async ( ) => {
243+ test ( 'when the token refresh fails, then stored credentials are cleared and an error is thrown ', async ( ) => {
244244 const sut = AuthService . instance ;
245245
246246 const mockToken = {
0 commit comments