Skip to content

Commit cf660c7

Browse files
committed
Revert "added chance as testing random examples provider"
This reverts commit 8c36d5e.
1 parent 793b72b commit cf660c7

15 files changed

Lines changed: 238 additions & 331 deletions

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,13 @@
7070
"@internxt/prettier-config": "internxt/prettier-config#v1.0.2",
7171
"@oclif/test": "4.1.4",
7272
"@openpgp/web-stream-tools": "0.0.11-patch-0",
73-
"@types/chance": "1.1.6",
7473
"@types/cli-progress": "3.11.6",
7574
"@types/express": "5.0.0",
7675
"@types/mime-types": "2.1.4",
7776
"@types/node": "22.10.2",
7877
"@types/range-parser": "1.2.7",
7978
"@vitest/coverage-istanbul": "2.1.8",
8079
"@vitest/spy": "2.1.8",
81-
"chance": "1.1.12",
8280
"eslint": "9.17.0",
8381
"husky": "9.1.7",
8482
"lint-staged": "15.2.11",

test/commands/login.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('Login Command', () => {
135135
.spyOn(CLIUtils, 'getValueFromFlag')
136136
.mockResolvedValueOnce(UserLoginFixture.email) // email
137137
.mockResolvedValueOnce(UserLoginFixture.password) // password
138-
.mockResolvedValueOnce(UserLoginFixture.tfaCode!) // two factor code
138+
.mockResolvedValueOnce(UserLoginFixture.twoFactor) // two factor code
139139
.mockRejectedValue(new Error()); // default
140140
const is2FaNeededSpy = vi.spyOn(AuthService.instance, 'is2FANeeded').mockResolvedValue(true);
141141
const doLoginSpy = vi.spyOn(AuthService.instance, 'doLogin').mockResolvedValue(UserCredentialsFixture);
@@ -149,7 +149,7 @@ describe('Login Command', () => {
149149
const result = await Login.run([
150150
`--email="${UserLoginFixture.email}"`,
151151
`--password="${UserLoginFixture.password}"`,
152-
`--twofactor="${UserLoginFixture.tfaCode}"`,
152+
`--twofactor="${UserLoginFixture.twoFactor}"`,
153153
]);
154154

155155
expect(result).to.be.deep.equal(expected);

test/fixtures/auth.fixture.ts

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,41 @@
11
import { UserSettings } from '@internxt/sdk/dist/shared/types/userSettings';
2-
import Chance from 'chance';
3-
import { generateMnemonic } from 'bip39';
4-
5-
const randomDataGenerator = new Chance();
2+
import crypto from 'node:crypto';
63

74
export const UserFixture: UserSettings = {
8-
userId: randomDataGenerator.natural({ min: 1 }).toString(),
9-
uuid: randomDataGenerator.guid({ version: 4 }),
10-
email: randomDataGenerator.email(),
11-
name: randomDataGenerator.name(),
12-
lastname: randomDataGenerator.name(),
13-
username: randomDataGenerator.word(),
14-
bridgeUser: randomDataGenerator.email(),
15-
bucket: randomDataGenerator.string({ length: 24, pool: 'abcdef0123456789' }),
16-
backupsBucket: randomDataGenerator.string({ length: 24, pool: 'abcdef0123456789' }),
17-
root_folder_id: randomDataGenerator.natural({ min: 1 }),
18-
rootFolderId: randomDataGenerator.guid({ version: 4 }),
19-
rootFolderUuid: randomDataGenerator.guid({ version: 4 }),
5+
userId: crypto.randomBytes(16).toString('hex'),
6+
uuid: crypto.randomBytes(16).toString('hex'),
7+
email: crypto.randomBytes(16).toString('hex'),
8+
name: crypto.randomBytes(16).toString('hex'),
9+
lastname: crypto.randomBytes(16).toString('hex'),
10+
username: crypto.randomBytes(16).toString('hex'),
11+
bridgeUser: crypto.randomBytes(16).toString('hex'),
12+
bucket: crypto.randomBytes(16).toString('hex'),
13+
backupsBucket: crypto.randomBytes(16).toString('hex'),
14+
root_folder_id: crypto.randomInt(1, 9999),
15+
rootFolderId: crypto.randomBytes(16).toString('hex'),
16+
rootFolderUuid: crypto.randomBytes(16).toString('hex'),
2017
sharedWorkspace: false,
21-
credit: randomDataGenerator.natural({ min: 1, max: 9999 }),
22-
mnemonic: generateMnemonic(),
23-
privateKey: randomDataGenerator.string({
24-
length: randomDataGenerator.integer({ min: 500, max: 1000 }),
25-
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
26-
}),
27-
publicKey: randomDataGenerator.string({
28-
length: randomDataGenerator.integer({ min: 500, max: 1000 }),
29-
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
30-
}),
31-
revocationKey: randomDataGenerator.string({
32-
length: randomDataGenerator.integer({ min: 500, max: 1000 }),
33-
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
34-
}),
18+
credit: crypto.randomInt(1, 9999),
19+
mnemonic: crypto.randomBytes(16).toString('hex'),
20+
privateKey: crypto.randomBytes(16).toString('hex'),
21+
publicKey: crypto.randomBytes(16).toString('hex'),
22+
revocationKey: crypto.randomBytes(16).toString('hex'),
3523
teams: false,
3624
appSumoDetails: null,
3725
registerCompleted: true,
3826
hasReferralsProgram: false,
39-
createdAt: randomDataGenerator.date(),
40-
avatar: randomDataGenerator.url(),
27+
createdAt: new Date(),
28+
avatar: crypto.randomBytes(16).toString('hex'),
4129
emailVerified: true,
4230
keys: {
4331
ecc: {
44-
privateKey: randomDataGenerator.string({
45-
length: randomDataGenerator.integer({ min: 500, max: 1000 }),
46-
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
47-
}),
48-
publicKey: randomDataGenerator.string({
49-
length: randomDataGenerator.integer({ min: 500, max: 1000 }),
50-
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
51-
}),
52-
revocationKey: randomDataGenerator.string({
53-
length: randomDataGenerator.integer({ min: 500, max: 1000 }),
54-
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
55-
}),
32+
privateKey: crypto.randomBytes(16).toString('hex'),
33+
publicKey: crypto.randomBytes(16).toString('hex'),
34+
revocationKey: crypto.randomBytes(16).toString('hex'),
5635
},
5736
kyber: {
58-
privateKyberKey: randomDataGenerator.string({
59-
length: randomDataGenerator.integer({ min: 500, max: 1000 }),
60-
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
61-
}),
62-
publicKyberKey: randomDataGenerator.string({
63-
length: randomDataGenerator.integer({ min: 500, max: 1000 }),
64-
pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
65-
}),
37+
privateKyberKey: crypto.randomBytes(16).toString('hex'),
38+
publicKyberKey: crypto.randomBytes(16).toString('hex'),
6639
},
6740
},
6841
};

test/fixtures/common.fixture.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const CommonFixture = {
2+
createObjectId: () => {
3+
const timestamp = ((new Date().getTime() / 1000) | 0).toString(16);
4+
return (
5+
timestamp +
6+
'xxxxxxxxxxxxxxxx'
7+
.replace(/[x]/g, function () {
8+
return ((Math.random() * 16) | 0).toString(16);
9+
})
10+
.toLowerCase()
11+
);
12+
},
13+
};

test/fixtures/drive-database.fixture.ts

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,37 @@ import { DriveFolder } from '../../src/services/database/drive-folder/drive-fold
44
import { DriveDatabaseManager } from '../../src/services/database/drive-database-manager.service';
55
import { DriveFileRepository } from '../../src/services/database/drive-file/drive-file.repository';
66
import { DriveFolderRepository } from '../../src/services/database/drive-folder/drive-folder.repository';
7-
import Chance from 'chance';
8-
9-
const randomDataGenerator = new Chance();
7+
import { randomInt, randomUUID } from 'node:crypto';
108

119
export const getDriveFileDatabaseFixture = (): DriveFile => {
12-
const createdAt = randomDataGenerator.date();
13-
const name = randomDataGenerator.word();
14-
const ext = randomDataGenerator.word();
15-
const filePath = `/${name}.${ext}`;
1610
const object: DriveFile = new DriveFile({
17-
uuid: randomDataGenerator.guid({ version: 4 }),
18-
id: randomDataGenerator.natural({ min: 1 }),
19-
name: name,
20-
type: ext,
21-
relativePath: filePath,
22-
createdAt,
23-
updatedAt: new Date(randomDataGenerator.date({ min: createdAt })),
24-
fileId: randomDataGenerator.string({ length: 24, pool: 'abcdef0123456789' }),
25-
bucket: randomDataGenerator.string({ length: 24, pool: 'abcdef0123456789' }),
26-
size: randomDataGenerator.natural({ min: 1 }),
27-
folderId: randomDataGenerator.natural({ min: 1 }),
28-
folderUuid: randomDataGenerator.guid({ version: 4 }),
11+
id: randomInt(2000),
12+
name: `file_${new Date().getTime().toString()}`,
13+
uuid: randomUUID(),
14+
relativePath: `file_${new Date().getTime().toString()}.txt`,
15+
createdAt: new Date(),
16+
updatedAt: new Date(),
2917
status: 'EXISTS',
18+
fileId: `file_id_${new Date().getTime().toString()}`,
19+
folderId: randomInt(2000),
20+
bucket: new Date().getTime().toString(),
21+
size: randomInt(2000),
22+
folderUuid: randomUUID(),
23+
type: 'txt',
3024
});
3125
return object;
3226
};
3327

3428
export const getDriveFolderDatabaseFixture = (): DriveFolder => {
35-
const createdAt = randomDataGenerator.date();
36-
const name = randomDataGenerator.word();
37-
const folderPath = `/${name}`;
3829
const object: DriveFolder = new DriveFolder({
39-
id: randomDataGenerator.natural({ min: 1 }),
40-
name: name,
41-
uuid: randomDataGenerator.guid({ version: 4 }),
42-
relativePath: folderPath,
43-
createdAt: createdAt,
44-
updatedAt: new Date(randomDataGenerator.date({ min: createdAt })),
45-
parentId: randomDataGenerator.natural({ min: 1 }),
46-
parentUuid: randomDataGenerator.guid({ version: 4 }),
30+
id: randomInt(2000),
31+
name: `folder_${new Date().getTime().toString()}`,
32+
uuid: randomUUID(),
33+
relativePath: '',
34+
createdAt: new Date(),
35+
updatedAt: new Date(),
36+
parentId: randomInt(2000),
37+
parentUuid: randomUUID(),
4738
status: 'EXISTS',
4839
});
4940

0 commit comments

Comments
 (0)