aboutsummaryrefslogtreecommitdiff
path: root/test/modules/vehicle.spec.ts
blob: 93f93b916266f2ceda5b9127f299f4d32da4d225 (plain)
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
import { describe, expect, it } from 'vitest';
import { faker } from '../../src';
import { seededTests } from '../support/seeded-runs';
import { times } from './../support/times';

const NON_SEEDED_BASED_RUN = 5;

describe('vehicle', () => {
  seededTests(faker, 'vehicle', (t) => {
    t.itEach(
      'vehicle',
      'manufacturer',
      'model',
      'type',
      'fuel',
      'vin',
      'color',
      'vrm',
      'bicycle'
    );
  });

  describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))(
    'random seeded tests for seed %i',
    () => {
      describe('vehicle()', () => {
        it('should return a random vehicle', () => {
          const vehicle = faker.vehicle.vehicle();

          expect(vehicle).toBeTruthy();
          expect(vehicle).toBeTypeOf('string');
          expect(vehicle.split(' ').length).toBeGreaterThanOrEqual(2);
        });
      });

      describe('manufacturer()', () => {
        it('should return random manufacturer', () => {
          const manufacturer = faker.vehicle.manufacturer();

          expect(manufacturer).toBeTruthy();
          expect(manufacturer).toBeTypeOf('string');
          expect(faker.definitions.vehicle.manufacturer).toContain(
            manufacturer
          );
        });
      });

      describe('model()', () => {
        it('should return random vehicle model', () => {
          const model = faker.vehicle.model();

          expect(model).toBeTruthy();
          expect(model).toBeTypeOf('string');
          expect(faker.definitions.vehicle.model).toContain(model);
        });
      });

      describe('type()', () => {
        it('should return random vehicle type', () => {
          const type = faker.vehicle.type();

          expect(type).toBeTruthy();
          expect(type).toBeTypeOf('string');
          expect(faker.definitions.vehicle.type).toContain(type);
        });
      });

      describe('fuel()', () => {
        it('should return a fuel type', () => {
          const fuel = faker.vehicle.fuel();

          expect(fuel).toBeTruthy();
          expect(fuel).toBeTypeOf('string');
          expect(faker.definitions.vehicle.fuel).toContain(fuel);
        });
      });

      describe('color()', () => {
        it('should return a random color', () => {
          const color = faker.vehicle.color();

          expect(color).toBeTruthy();
          expect(color).toBeTypeOf('string');
          expect(faker.definitions.color.human).toContain(color);
        });
      });

      describe('vin()', () => {
        it('returns valid vin number', () => {
          const vin = faker.vehicle.vin();
          expect(vin).toMatch(
            /^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/
          );
        });

        it('should return valid vin number', () => {
          const vin = faker.vehicle.vin();

          expect(vin).toBeTruthy();
          expect(vin).toBeTypeOf('string');
          expect(vin).toMatch(
            /^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/
          );
        });
      });

      describe('vrm()', () => {
        it('should return a random vrm', () => {
          const vrm = faker.vehicle.vrm();

          expect(vrm).toBeTruthy();
          expect(vrm).toBeTypeOf('string');
          expect(vrm).toMatch(/^[A-Z]{2}[0-9]{2}[A-Z]{3}$/);
        });
      });

      describe('bicycle()', () => {
        it('should return a random type of bicycle', () => {
          const bicycle = faker.vehicle.bicycle();

          expect(bicycle).toBeTruthy();
          expect(bicycle).toBeTypeOf('string');
          expect(faker.definitions.vehicle.bicycle_type).toContain(bicycle);
        });
      });
    }
  );
});