Skip to content

Commit b22ff36

Browse files
authored
Merge pull request #606 from internxt/feat/refactor-tests-descriptions
[_]: feat/refactor-tests-descriptions
2 parents 399c2ed + d08d03b commit b22ff36

51 files changed

Lines changed: 428 additions & 424 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

eslint.config.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import eslintConfigInternxt from '@internxt/eslint-config-internxt';
22

33
export default [
4-
{
5-
ignores: ['dist', 'tmp', 'scripts'],
4+
{
5+
ignores: ['dist', 'tmp', 'scripts'],
6+
},
7+
...eslintConfigInternxt,
8+
{
9+
files: ['test/**/*.test.ts'],
10+
rules: {
11+
'max-len': 'off',
612
},
7-
...eslintConfigInternxt,
13+
},
814
];

test/commands/login.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it, vi } from 'vitest';
1+
import { describe, expect, test, vi } from 'vitest';
22
import { ConfigService } from '../../src/services/config.service';
33
import { UserCredentialsFixture, UserLoginFixture } from '../fixtures/login.fixture';
44
import { fail } from 'node:assert';
@@ -7,7 +7,7 @@ import { AuthService } from '../../src/services/auth.service';
77
import { CLIUtils, NoFlagProvidedError } from '../../src/utils/cli.utils';
88

99
describe('Login Command', () => {
10-
it('When user logs in with non-interactive and no email, then it throws error', async () => {
10+
test('When user logs in with non-interactive and no email, then it throws error', async () => {
1111
const getValueFromFlagsSpy = vi
1212
.spyOn(CLIUtils, 'getValueFromFlag')
1313
.mockRejectedValueOnce(new NoFlagProvidedError('email')) // email
@@ -32,7 +32,7 @@ describe('Login Command', () => {
3232
expect(saveUserSpy).not.toHaveBeenCalled();
3333
});
3434

35-
it('When user logs in with non-interactive and no password, then it throws error', async () => {
35+
test('When user logs in with non-interactive and no password, then it throws error', async () => {
3636
const getValueFromFlagsSpy = vi
3737
.spyOn(CLIUtils, 'getValueFromFlag')
3838
.mockResolvedValueOnce(UserLoginFixture.email) // email
@@ -57,7 +57,7 @@ describe('Login Command', () => {
5757
expect(saveUserSpy).not.toHaveBeenCalled();
5858
});
5959

60-
it('When user logs in with non-interactive and no two factor code, then it throws error', async () => {
60+
test('When user logs in with non-interactive and no two factor code, then it throws error', async () => {
6161
const getValueFromFlagsSpy = vi
6262
.spyOn(CLIUtils, 'getValueFromFlag')
6363
.mockResolvedValueOnce(UserLoginFixture.email) // email
@@ -86,7 +86,7 @@ describe('Login Command', () => {
8686
expect(saveUserSpy).not.toHaveBeenCalled();
8787
});
8888

89-
it('When two factor is not needed, then it saves and returns the credentials', async () => {
89+
test('When two factor is not needed, then it saves and returns the credentials', async () => {
9090
const getValueFromFlagsSpy = vi
9191
.spyOn(CLIUtils, 'getValueFromFlag')
9292
.mockResolvedValueOnce(UserLoginFixture.email) // email
@@ -112,7 +112,7 @@ describe('Login Command', () => {
112112
expect(saveUserSpy).toHaveBeenCalledOnce();
113113
});
114114

115-
it('When two factor is needed, then it saves and returns the credentials', async () => {
115+
test('When two factor is needed, then it saves and returns the credentials', async () => {
116116
const getValueFromFlagsSpy = vi
117117
.spyOn(CLIUtils, 'getValueFromFlag')
118118
.mockResolvedValueOnce(UserLoginFixture.email) // email

test/commands/logout.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { describe, expect, it, vi } from 'vitest';
1+
import { describe, expect, test, vi } from 'vitest';
22
import { ConfigService } from '../../src/services/config.service';
33
import { UserCredentialsFixture } from '../fixtures/login.fixture';
44
import Logout from '../../src/commands/logout';
55
import { AuthService } from '../../src/services/auth.service';
66

77
describe('Logout Command', () => {
8-
it('When user is logged out, then it returns false', async () => {
8+
test('When user is logged out, then it returns false', async () => {
99
const readUserSpy = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(undefined);
1010
const networkLogout = vi.spyOn(AuthService.instance, 'logout').mockRejectedValue(new Error());
1111
const clearUserSpy = vi.spyOn(ConfigService.instance, 'clearUser').mockRejectedValue(new Error());
@@ -21,7 +21,7 @@ describe('Logout Command', () => {
2121
expect(clearUserSpy).not.toHaveBeenCalled();
2222
});
2323

24-
it('When user is logged in, then the current user logged out', async () => {
24+
test('When user is logged in, then the user is logged out', async () => {
2525
const readUserSpy = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(UserCredentialsFixture);
2626
const networkLogout = vi.spyOn(AuthService.instance, 'logout').mockResolvedValue();
2727
const clearUserSpy = vi.spyOn(ConfigService.instance, 'clearUser').mockResolvedValue();

test/commands/upload-folder.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, MockInstance, vi } from 'vitest';
1+
import { beforeEach, describe, expect, test, MockInstance, vi } from 'vitest';
22
import UploadFolder from '../../src/commands/upload-folder';
33
import { LoginCredentials } from '../../src/types/command.types';
44
import { ValidationService } from '../../src/services/validation.service';
@@ -37,7 +37,7 @@ describe('Upload Folder Command', () => {
3737
vi.spyOn(AsyncUtils, 'sleep').mockResolvedValue(undefined);
3838
});
3939

40-
it('should call UploadFacade when user uploads a folder with valid path', async () => {
40+
test('when user uploads a folder with a valid path, then the upload process completes successfully', async () => {
4141
await UploadFolder.run(['--folder=/valid/folder/path']);
4242

4343
expect(configReadUserSpy).toHaveBeenCalledTimes(2);
@@ -53,7 +53,7 @@ describe('Upload Folder Command', () => {
5353
expect(cliSuccessSpy).toHaveBeenCalledOnce();
5454
});
5555

56-
it('should use provided destination folder UUID when destination flag is passed', async () => {
56+
test('when a destination folder is specified, then the folder is uploaded to the chosen destination', async () => {
5757
const customDestinationId = 'custom-folder-uuid-123';
5858

5959
const getDestinationFolderUuidSpy = vi
@@ -73,7 +73,7 @@ describe('Upload Folder Command', () => {
7373
expect(cliSuccessSpy).toHaveBeenCalledOnce();
7474
});
7575

76-
it('should default to user.rootFolderId when no destination is passed', async () => {
76+
test('when no destination folder is specified, then the folder is uploaded to the default location', async () => {
7777
await UploadFolder.run(['--folder=/valid/folder/path']);
7878

7979
expect(UploadFacadeSpy).toHaveBeenCalledWith(
@@ -83,7 +83,7 @@ describe('Upload Folder Command', () => {
8383
);
8484
});
8585

86-
it('should call CLIUtils.success with proper message when upload succeeds', async () => {
86+
test('when upload succeeds, then a success message with upload time and link is displayed', async () => {
8787
const cliSuccessSpy = vi.spyOn(CLIUtils, 'success').mockImplementation(() => {});
8888

8989
await UploadFolder.run(['--folder=/valid/folder/path']);
@@ -99,7 +99,7 @@ describe('Upload Folder Command', () => {
9999
);
100100
});
101101

102-
it('should throw an error when user does not provide a valid path', async () => {
102+
test('when the folder path is invalid, then an error is shown', async () => {
103103
const validateDirectoryExistsSpy = vi
104104
.spyOn(ValidationService.instance, 'validateDirectoryExists')
105105
.mockResolvedValue(false);
@@ -117,7 +117,7 @@ describe('Upload Folder Command', () => {
117117
expect(UploadFacadeSpy).not.toHaveBeenCalled();
118118
});
119119

120-
it('should throw an error when user does not have credentials', async () => {
120+
test('when user is not logged in, then an error is shown', async () => {
121121
const readUserSpy = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(undefined);
122122

123123
const result = UploadFolder.run(['--folder=/some/folder/path']);
@@ -132,7 +132,7 @@ describe('Upload Folder Command', () => {
132132
});
133133

134134
describe('Folder path resolution (getFolderPath)', () => {
135-
it('should prompt user for folder path in interactive mode when --folder flag is not provided', async () => {
135+
test('when no folder path is given in interactive mode, then the user is prompted for one', async () => {
136136
const getValueFromFlagSpy = vi.spyOn(CLIUtils, 'getValueFromFlag').mockResolvedValue('/prompted/folder/path');
137137

138138
await UploadFolder.run([]);
@@ -157,7 +157,7 @@ describe('Upload Folder Command', () => {
157157
);
158158
});
159159

160-
it('should throw NoFlagProvidedError in non-interactive mode when --folder flag is not provided', async () => {
160+
test('when no folder path is given in non-interactive mode, then an error is shown', async () => {
161161
const getValueFromFlagSpy = vi
162162
.spyOn(CLIUtils, 'getValueFromFlag')
163163
.mockRejectedValue(new NoFlagProvidedError('folder'));
@@ -187,7 +187,7 @@ describe('Upload Folder Command', () => {
187187
expect(UploadFacadeSpy).not.toHaveBeenCalled();
188188
});
189189

190-
it('should use folder path from --folder flag when provided', async () => {
190+
test('when a folder path is provided via the folder flag, then that path is used for the upload', async () => {
191191
await UploadFolder.run(['--folder=/explicit/folder/path']);
192192

193193
expect(validateDirectoryExistsSpy).toHaveBeenCalledWith('/explicit/folder/path');

test/commands/whoami.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { describe, expect, it, vi } from 'vitest';
1+
import { describe, expect, test, vi } from 'vitest';
22
import { ConfigService } from '../../src/services/config.service';
33
import { UserCredentialsFixture } from '../fixtures/login.fixture';
44
import Whoami from '../../src/commands/whoami';
55
import { ValidationService } from '../../src/services/validation.service';
66

77
describe('Whoami Command', () => {
8-
it('When user is logged out, then it returns false', async () => {
8+
test('When user is logged out, then it returns false', async () => {
99
const readUserSpy = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(undefined);
1010
const clearUserSpy = vi.spyOn(ConfigService.instance, 'clearUser').mockRejectedValue(new Error());
1111
const validateTokensSpy = vi
@@ -25,7 +25,7 @@ describe('Whoami Command', () => {
2525
expect(validateMnemonicSpy).not.toHaveBeenCalled();
2626
});
2727

28-
it('When user is logged in with expired credentials, then it returns the user credentials', async () => {
28+
test('When user is logged in with expired credentials, then it returns the user credentials', async () => {
2929
const readUserSpy = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(UserCredentialsFixture);
3030
const clearUserSpy = vi.spyOn(ConfigService.instance, 'clearUser').mockResolvedValue();
3131
const validateTokensSpy = vi
@@ -45,7 +45,7 @@ describe('Whoami Command', () => {
4545
expect(validateMnemonicSpy).toHaveBeenCalledOnce();
4646
});
4747

48-
it('When user is logged in with valid credentials, then it returns the user credentials', async () => {
48+
test('When user is logged in with valid credentials, then it returns the user credentials', async () => {
4949
const readUserSpy = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(UserCredentialsFixture);
5050
const clearUserSpy = vi.spyOn(ConfigService.instance, 'clearUser').mockResolvedValue();
5151
const validateTokensSpy = vi

test/services/auth.service.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from 'vitest';
1+
import { beforeEach, describe, expect, test, vi } from 'vitest';
22
import crypto from 'node:crypto';
33
import { Auth, LoginDetails, SecurityDetails } from '@internxt/sdk';
44
import { 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

Comments
 (0)