1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
import { afterEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
const seededRuns = [
{
seed: 42,
expectations: {
column: 'token',
type: 'smallint',
collation: 'utf8_bin',
engine: 'MEMORY',
},
},
{
seed: 1337,
expectations: {
column: 'email',
type: 'time',
collation: 'utf8_general_ci',
engine: 'MyISAM',
},
},
{
seed: 1211,
expectations: {
column: 'createdAt',
type: 'geometry',
collation: 'cp1250_general_ci',
engine: 'ARCHIVE',
},
},
];
const NON_SEEDED_BASED_RUN = 5;
const functionNames = ['column', 'type', 'collation', 'engine'];
describe('database', () => {
afterEach(() => {
faker.locale = 'en';
});
for (const { seed, expectations } of seededRuns) {
describe(`seed: ${seed}`, () => {
for (const functionName of functionNames) {
it(`${functionName}()`, () => {
faker.seed(seed);
const actual = faker.database[functionName]();
expect(actual).toEqual(expectations[functionName]);
});
}
});
}
// Create and log-back the seed for debug purposes
faker.seed(Math.ceil(Math.random() * 1_000_000_000));
describe(`random seeded tests for seed ${JSON.stringify(
faker.seedValue
)}`, () => {
for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) {
describe('column()', () => {
it('should return a column name from array', () => {
const column = faker.database.column();
expect(column).toBeTruthy();
expect(column).toBeTypeOf('string');
expect(faker.definitions.database.column).toContain(column);
});
});
describe('collation()', () => {
it('should return a collation from array', () => {
const collation = faker.database.collation();
expect(collation).toBeTruthy();
expect(collation).toBeTypeOf('string');
expect(faker.definitions.database.collation).toContain(collation);
});
});
describe('engine()', () => {
it('should return an engine from array', () => {
const engine = faker.database.engine();
expect(engine).toBeTruthy();
expect(engine).toBeTypeOf('string');
expect(faker.definitions.database.engine).toContain(engine);
});
});
describe('type()', () => {
it('should return a column type from array', () => {
const type = faker.database.type();
expect(type).toBeTruthy();
expect(type).toBeTypeOf('string');
expect(faker.definitions.database.type).toContain(type);
});
});
}
});
});
|