Skip to content

Commit 8c36d5e

Browse files
committed
added chance as testing random examples provider
1 parent adf2285 commit 8c36d5e

15 files changed

Lines changed: 331 additions & 238 deletions

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@
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",
7374
"@types/cli-progress": "3.11.6",
7475
"@types/express": "5.0.0",
7576
"@types/mime-types": "2.1.4",
7677
"@types/node": "22.10.2",
7778
"@types/range-parser": "1.2.7",
7879
"@vitest/coverage-istanbul": "2.1.8",
7980
"@vitest/spy": "2.1.8",
81+
"chance": "1.1.12",
8082
"eslint": "9.17.0",
8183
"husky": "9.1.7",
8284
"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.twoFactor) // two factor code
138+
.mockResolvedValueOnce(UserLoginFixture.tfaCode!) // 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.twoFactor}"`,
152+
`--twofactor="${UserLoginFixture.tfaCode}"`,
153153
]);
154154

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

test/fixtures/auth.fixture.ts

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

47
export const UserFixture: UserSettings = {
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'),
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 }),
1720
sharedWorkspace: false,
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'),
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+
}),
2335
teams: false,
2436
appSumoDetails: null,
2537
registerCompleted: true,
2638
hasReferralsProgram: false,
27-
createdAt: new Date(),
28-
avatar: crypto.randomBytes(16).toString('hex'),
39+
createdAt: randomDataGenerator.date(),
40+
avatar: randomDataGenerator.url(),
2941
emailVerified: true,
3042
keys: {
3143
ecc: {
32-
privateKey: crypto.randomBytes(16).toString('hex'),
33-
publicKey: crypto.randomBytes(16).toString('hex'),
34-
revocationKey: crypto.randomBytes(16).toString('hex'),
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+
}),
3556
},
3657
kyber: {
37-
privateKyberKey: crypto.randomBytes(16).toString('hex'),
38-
publicKyberKey: crypto.randomBytes(16).toString('hex'),
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+
}),
3966
},
4067
},
4168
};

test/fixtures/common.fixture.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/fixtures/drive-database.fixture.ts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,46 @@ 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 { randomInt, randomUUID } from 'node:crypto';
7+
import Chance from 'chance';
8+
9+
const randomDataGenerator = new Chance();
810

911
export const getDriveFileDatabaseFixture = (): DriveFile => {
12+
const createdAt = randomDataGenerator.date();
13+
const name = randomDataGenerator.word();
14+
const ext = randomDataGenerator.word();
15+
const filePath = `/${name}.${ext}`;
1016
const object: DriveFile = new DriveFile({
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(),
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 }),
1729
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',
2430
});
2531
return object;
2632
};
2733

2834
export const getDriveFolderDatabaseFixture = (): DriveFolder => {
35+
const createdAt = randomDataGenerator.date();
36+
const name = randomDataGenerator.word();
37+
const folderPath = `/${name}`;
2938
const object: DriveFolder = new DriveFolder({
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(),
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 }),
3847
status: 'EXISTS',
3948
});
4049

0 commit comments

Comments
 (0)