fix slug and faker

This commit is contained in:
Simon Larsen 2023-08-21 12:54:19 +01:00
parent e2f885b11b
commit 0978c5a2b8
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
4 changed files with 5 additions and 8 deletions

View File

@ -2,7 +2,7 @@ import Headers from '../../../Types/API/Headers';
import Faker from '../../../Utils/Faker';
describe('Headers', () => {
test('should compile', () => {
const apiKey: string = Faker.random16Numbers();
const apiKey: string = Faker.randomNumbers(16);
const headers: Headers = {
accept: 'application/json',
'x-api-key': apiKey,

View File

@ -5,15 +5,14 @@ import Phone from '../Types/Phone';
export default class Faker {
public static generateName(): string {
return faker.person.fullName();
return faker.string.alphanumeric(10);
}
public static generateCompanyName(): string {
return faker.company.name();
}
public static random16Numbers(): string {
const count: number = 16;
public static randomNumbers(count: number): string {
const randomNumbers: Array<number> = [];
for (let i: number = 0; i < count; i++) {
randomNumbers.push(Math.floor(Math.random() * 10)); // You can adjust the range as needed

View File

@ -1,6 +1,4 @@
import slugify from 'slugify';
import { customAlphabet } from 'nanoid';
import { numbers } from 'nanoid-dictionary';
import Faker from './Faker';
export default class Slug {
@ -15,7 +13,7 @@ export default class Slug {
}
let slug: string = slugify(name, { remove: /[&*+~.,\\/()|'"!:@]+/g });
slug = `${slug}-${customAlphabet(numbers, 10)()}`;
slug = `${slug}-${Faker.randomNumbers(7)}`;
slug = slug.toLowerCase();
return slug;

View File

@ -49,7 +49,7 @@ export const testDataSourceOptions: DataSourceOptions = {
port: DatabasePort.toNumber(),
username: DatabaseUsername,
password: DatabasePassword,
database: DatabaseName + Faker.random16Numbers(),
database: DatabaseName + Faker.randomNumbers(16),
entities: Entities,
synchronize:
Env === AppEnvironment.Test || Env === AppEnvironment.Development,