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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
import { describe, expect, it } from 'vitest';
import { Aircraft, faker } from '../../src';
import { seededTests } from '../support/seeded-runs';
import { times } from './../support/times';
const NON_SEEDED_BASED_RUN = 5;
describe('airline', () => {
seededTests(faker, 'airline', (t) => {
t.itEach('airport', 'airline', 'airplane', 'aircraftType');
t.describe('recordLocator', (t) => {
t.it('noArgs')
.it('allowNumerics', { allowNumerics: true })
.it('allowVisuallySimilarCharacters', {
allowVisuallySimilarCharacters: true,
})
.it('both allowNumerics and allowVisuallySimilarCharacters', {
allowNumerics: true,
allowVisuallySimilarCharacters: true,
});
});
t.describe('seat', (t) => {
t.it('noArgs')
.it('aircraftType narrowbody', { aircraftType: 'narrowbody' })
.it('aircraftType regional', { aircraftType: 'regional' })
.it('aircraftType widebody', { aircraftType: 'widebody' });
});
t.describe('flightNumber', (t) => {
t.it('noArgs')
.it('flightNumber length 3', { length: 3 })
.it('flightNumber length 2 to 4', { length: { min: 2, max: 4 } })
.it('flightNumber addLeadingZeros', { addLeadingZeros: true })
.it('flightNumber length 3 and addLeadingZeros', {
length: 3,
addLeadingZeros: true,
})
.it('flightNumber length 2 to 4 and addLeadingZeros', {
length: { min: 2, max: 4 },
addLeadingZeros: true,
});
});
});
describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
'random seeded tests for seed %i',
() => {
describe(`airport()`, () => {
it('should return a random value from airport array', () => {
const airport = faker.airline.airport();
expect(faker.definitions.airline.airport).toContainEqual(airport);
});
});
describe(`airline()`, () => {
it('should return a random value from airline array', () => {
const airline = faker.airline.airline();
expect(faker.definitions.airline.airline).toContainEqual(airline);
});
});
describe(`airplane()`, () => {
it('should return a random value from airplane array', () => {
const airplane = faker.airline.airplane();
expect(faker.definitions.airline.airplane).toContainEqual(airplane);
});
});
describe(`recordLocator()`, () => {
it('should use the default values when not passing arguments', () => {
const recordLocator = faker.airline.recordLocator();
expect(recordLocator).toMatch(/^[A-HJ-KM-NP-Z]{6}$/);
});
it('should allow numeric characters', () => {
const recordLocator = faker.airline.recordLocator({
allowNumerics: true,
});
expect(recordLocator).toMatch(/^[2-9A-HJ-KM-NP-Z]{6}$/);
});
it('should allow visually similar characters', () => {
const recordLocator = faker.airline.recordLocator({
allowVisuallySimilarCharacters: true,
});
expect(recordLocator).toMatch(/^[A-Z]{6}$/);
});
it('should allow both numeric and visually similar characters', () => {
const recordLocator = faker.airline.recordLocator({
allowNumerics: true,
allowVisuallySimilarCharacters: true,
});
expect(recordLocator).toMatch(/^[0-9A-Z]{6}$/);
});
});
describe(`seat()`, () => {
const seatRegex = /^(\d{1,2})([A-K])$/;
it('should return a random narrowbody seat when not passing an argument', () => {
const seat = faker.airline.seat();
const matchResult = seatRegex.exec(seat);
expectNotNull(matchResult);
const row = matchResult[1];
const seatLetter = matchResult[2];
expect(row).toSatisfy((row: number) => row >= 1 && row <= 35);
expect(seatLetter).toMatch(/^[A-F]$/);
});
it('should return a random narrowbody seat', () => {
const seat = faker.airline.seat({
aircraftType: Aircraft.Narrowbody,
});
const matchResult = seatRegex.exec(seat);
expectNotNull(matchResult);
const row = matchResult[1];
const seatLetter = matchResult[2];
expect(row).toSatisfy((row: number) => row >= 1 && row <= 35);
expect(seatLetter).toMatch(/^[A-F]$/);
});
it('should return a random regional seat', () => {
const seat = faker.airline.seat({ aircraftType: Aircraft.Regional });
const matchResult = seatRegex.exec(seat);
expectNotNull(matchResult);
const row = matchResult[1];
const seatLetter = matchResult[2];
expect(row).toSatisfy((row: number) => row >= 1 && row <= 20);
expect(seatLetter).toMatch(/^[A-D]$/);
});
it('should return a random widebody seat', () => {
const seat = faker.airline.seat({ aircraftType: Aircraft.Widebody });
const matchResult = seatRegex.exec(seat);
expectNotNull(matchResult);
const row = matchResult[1];
const seatLetter = matchResult[2];
expect(row).toSatisfy((row: number) => row >= 1 && row <= 60);
expect(seatLetter).toMatch(/^[A-HJ-K]$/);
});
});
describe(`aircraftType()`, () => {
it('should return a random aircraft type from the Aircraft enum', () => {
const aircraft = faker.airline.aircraftType();
expect(Object.values(Aircraft)).toContain(aircraft);
});
});
describe(`flightNumber()`, () => {
it('should return a random flight number', () => {
const flightNumber = faker.airline.flightNumber();
expect(flightNumber).toMatch(/^[1-9][0-9]{0,3}$/);
});
it('should return a random flight number with 3 digits', () => {
const flightNumber = faker.airline.flightNumber({ length: 3 });
expect(flightNumber).toMatch(/^[1-9][0-9]{2}$/);
});
it('should return a random flight number with 2 to 4 digits', () => {
const flightNumber = faker.airline.flightNumber({
length: { min: 2, max: 4 },
});
expect(flightNumber).toMatch(/^[1-9][0-9]{1,3}$/);
});
it('should return a random flight number with leading zeros', () => {
const flightNumber = faker.airline.flightNumber({
addLeadingZeros: true,
});
expect(flightNumber).toMatch(/^[0-9]{4}$/);
});
it('should return a random flight number with 3 digits and leading zeros', () => {
const flightNumber = faker.airline.flightNumber({
length: 3,
addLeadingZeros: true,
});
expect(flightNumber).toMatch(/^[0-9][1-9][0-9]{2}$/);
});
it('should return a random flight number with 2 to 4 digits and leading zeros', () => {
const flightNumber = faker.airline.flightNumber({
length: { min: 2, max: 4 },
addLeadingZeros: true,
});
expect(flightNumber).toMatch(/^[0-9]{1,4}$/);
});
});
}
);
});
function expectNotNull<T>(value: T): asserts value is NonNullable<T> {
expect(value).not.toBeNull();
}
|