Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import eslintConfigInternxt from '@internxt/eslint-config-internxt';

export default [
{
ignores: ['dist', 'tmp', 'scripts'],
{
ignores: ['dist', 'tmp', 'scripts'],
},
...eslintConfigInternxt,
{
files: ['test/**/*.test.ts'],
rules: {
'max-len': 'off',
},
...eslintConfigInternxt,
},
];
12 changes: 6 additions & 6 deletions test/commands/login.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it, vi } from 'vitest';
import { describe, expect, test, vi } from 'vitest';
import { ConfigService } from '../../src/services/config.service';
import { UserCredentialsFixture, UserLoginFixture } from '../fixtures/login.fixture';
import { fail } from 'node:assert';
Expand All @@ -7,7 +7,7 @@ import { AuthService } from '../../src/services/auth.service';
import { CLIUtils, NoFlagProvidedError } from '../../src/utils/cli.utils';

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

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

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

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

it('When two factor is needed, then it saves and returns the credentials', async () => {
test('When two factor is needed, then it saves and returns the credentials', async () => {
const getValueFromFlagsSpy = vi
.spyOn(CLIUtils, 'getValueFromFlag')
.mockResolvedValueOnce(UserLoginFixture.email) // email
Expand Down
6 changes: 3 additions & 3 deletions test/commands/logout.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, expect, it, vi } from 'vitest';
import { describe, expect, test, vi } from 'vitest';
import { ConfigService } from '../../src/services/config.service';
import { UserCredentialsFixture } from '../fixtures/login.fixture';
import Logout from '../../src/commands/logout';
import { AuthService } from '../../src/services/auth.service';

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

it('When user is logged in, then the current user logged out', async () => {
test('When user is logged in, then the user is logged out', async () => {
const readUserSpy = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(UserCredentialsFixture);
const networkLogout = vi.spyOn(AuthService.instance, 'logout').mockResolvedValue();
const clearUserSpy = vi.spyOn(ConfigService.instance, 'clearUser').mockResolvedValue();
Expand Down
20 changes: 10 additions & 10 deletions test/commands/upload-folder.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, MockInstance, vi } from 'vitest';
import { beforeEach, describe, expect, test, MockInstance, vi } from 'vitest';
import UploadFolder from '../../src/commands/upload-folder';
import { LoginCredentials } from '../../src/types/command.types';
import { ValidationService } from '../../src/services/validation.service';
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('Upload Folder Command', () => {
vi.spyOn(AsyncUtils, 'sleep').mockResolvedValue(undefined);
});

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

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

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

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

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

expect(UploadFacadeSpy).toHaveBeenCalledWith(
Expand All @@ -83,7 +83,7 @@ describe('Upload Folder Command', () => {
);
});

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

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

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

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

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

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

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

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

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

expect(validateDirectoryExistsSpy).toHaveBeenCalledWith('/explicit/folder/path');
Expand Down
8 changes: 4 additions & 4 deletions test/commands/whoami.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { describe, expect, it, vi } from 'vitest';
import { describe, expect, test, vi } from 'vitest';
import { ConfigService } from '../../src/services/config.service';
import { UserCredentialsFixture } from '../fixtures/login.fixture';
import Whoami from '../../src/commands/whoami';
import { ValidationService } from '../../src/services/validation.service';

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

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

it('When user is logged in with valid credentials, then it returns the user credentials', async () => {
test('When user is logged in with valid credentials, then it returns the user credentials', async () => {
const readUserSpy = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(UserCredentialsFixture);
const clearUserSpy = vi.spyOn(ConfigService.instance, 'clearUser').mockResolvedValue();
const validateTokensSpy = vi
Expand Down
24 changes: 12 additions & 12 deletions test/services/auth.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import crypto from 'node:crypto';
import { Auth, LoginDetails, SecurityDetails } from '@internxt/sdk';
import { AuthService } from '../../src/services/auth.service';
Expand All @@ -25,7 +25,7 @@ describe('Auth service', () => {
vi.spyOn(CacheService.instance, 'get').mockReturnValue(undefined);
});

it('should generate login user credentials when user logs in', async () => {
test('when the user logs in successfully, then login credentials are generated', async () => {
const loginResponse = {
token: crypto.randomBytes(16).toString('hex'),
newToken: crypto.randomBytes(16).toString('hex'),
Expand All @@ -50,7 +50,7 @@ describe('Auth service', () => {
expect(responseLogin).to.be.deep.equal(expectedResponseLogin);
});

it('should throw an error when user logs in and credentials are not correct', async () => {
test('when the user provides incorrect login credentials, then an error is thrown', async () => {
const loginDetails: LoginDetails = {
email: crypto.randomBytes(16).toString('hex'),
password: crypto.randomBytes(8).toString('hex'),
Expand All @@ -69,7 +69,7 @@ describe('Auth service', () => {
expect(loginStub).toHaveBeenCalledOnce();
});

it('should return true from is2FANeeded when two factor authentication is enabled', async () => {
test('when two-factor authentication is enabled on the account, then the system reports it as required', async () => {
const email = crypto.randomBytes(16).toString('hex');
const securityDetails: SecurityDetails = {
encryptedSalt: crypto.randomBytes(16).toString('hex'),
Expand All @@ -85,7 +85,7 @@ describe('Auth service', () => {
expect(responseLogin).to.be.equal(securityDetails.tfaEnabled);
});

it('should throw an error when checking two factor authentication with an incorrect email', async () => {
test('when an invalid email is provided for authentication validation, then an error is thrown', async () => {
const email = crypto.randomBytes(16).toString('hex');

const securityStub = vi.spyOn(Auth.prototype, 'securityDetails').mockRejectedValue(new Error());
Expand All @@ -100,7 +100,7 @@ describe('Auth service', () => {
expect(securityStub).toHaveBeenCalledOnce();
});

it('should return auth details when all credentials are found', async () => {
test('when all stored credentials are complete and valid, then authentication details are returned', async () => {
const sut = AuthService.instance;

const loginCreds: LoginCredentials = UserCredentialsFixture;
Expand All @@ -127,7 +127,7 @@ describe('Auth service', () => {
expect(result).to.deep.equal(loginCreds);
});

it('should throw an error when credentials are missing', async () => {
test('when no stored credentials exist, then an error is thrown', async () => {
const sut = AuthService.instance;

const readUserStub = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue(undefined);
Expand All @@ -141,7 +141,7 @@ describe('Auth service', () => {
expect(readUserStub).toHaveBeenCalledOnce();
});

it('should throw an error when auth token is missing', async () => {
test('when the session token is missing from stored credentials, then an error is thrown', async () => {
const sut = AuthService.instance;

const readUserStub = vi.spyOn(ConfigService.instance, 'readUser').mockResolvedValue({
Expand All @@ -159,7 +159,7 @@ describe('Auth service', () => {
expect(readUserStub).toHaveBeenCalledOnce();
});

it('should throw an error when mnemonic is invalid', async () => {
test('when the recovery phrase is invalid, then an error is thrown', async () => {
const sut = AuthService.instance;

const mockToken = {
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('Auth service', () => {
expect(validateMnemonicStub).toHaveBeenCalledWith(UserCredentialsFixture.user.mnemonic);
});

it('should throw an error when token has expired', async () => {
test('when the session token has expired, then an error is thrown', async () => {
const sut = AuthService.instance;

const mockToken = {
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('Auth service', () => {
expect(validateMnemonicStub).toHaveBeenCalledWith(UserCredentialsFixture.user.mnemonic);
});

it('should refresh tokens when they are going to expire soon', async () => {
test('when the session token is about to expire, then it is refreshed automatically', async () => {
const sut = AuthService.instance;

const mockToken = {
Expand All @@ -240,7 +240,7 @@ describe('Auth service', () => {
expect(refreshTokensStub).toHaveBeenCalledOnce();
});

it('should clear and throw exception when exception is thrown while refreshing user token', async () => {
test('when the token refresh fails, then stored credentials are cleared and an error is thrown', async () => {
const sut = AuthService.instance;

const mockToken = {
Expand Down
Loading
Loading