|
1 | 1 | /* eslint-disable @typescript-eslint/no-var-requires */
|
2 |
| -import chai, { expect } from 'chai' |
3 |
| -import sinonChai from 'sinon-chai' |
4 |
| -import { AvailableTestModels } from './utils/available-test-models' |
| 2 | +import chai, { expect } from 'chai'; |
| 3 | +import sinonChai from 'sinon-chai'; |
| 4 | +import { AvailableTestModels } from './utils/available-test-models'; |
5 | 5 |
|
6 |
| -import Property from './property' |
| 6 | +import Property from './property'; |
7 | 7 |
|
8 |
| -chai.use(sinonChai) |
| 8 | +chai.use(sinonChai); |
9 | 9 |
|
10 |
| -const db = require('../models/index.js') |
| 10 | +const db = require('../models/index.js'); |
11 | 11 |
|
12 | 12 | const getRawProperty = (modelName: AvailableTestModels, propertyName) => {
|
13 |
| - const model = db.sequelize.models[modelName] |
14 |
| - const propertyAttrs = model.attributes || model.rawAttributes |
15 |
| - return propertyAttrs[propertyName] |
16 |
| -} |
| 13 | + const model = db.sequelize.models[modelName]; |
| 14 | + const propertyAttrs = model.attributes || model.rawAttributes; |
| 15 | + return propertyAttrs[propertyName]; |
| 16 | +}; |
17 | 17 |
|
18 | 18 | describe('Property', () => {
|
19 | 19 | describe('#isArray', () => {
|
20 | 20 | it('returns false for regular (not arrayed) property', () => {
|
21 |
| - const property = new Property(getRawProperty('User', 'email')) |
22 |
| - expect(property.isArray()).to.equal(false) |
23 |
| - }) |
| 21 | + const property = new Property(getRawProperty('User', 'email')); |
| 22 | + expect(property.isArray()).to.equal(false); |
| 23 | + }); |
24 | 24 |
|
25 | 25 | it('returns true for array property', () => {
|
26 |
| - const property = new Property(getRawProperty('User', 'arrayed')) |
27 |
| - expect(property.isArray()).to.equal(true) |
28 |
| - }) |
29 |
| - }) |
| 26 | + const property = new Property(getRawProperty('User', 'arrayed')); |
| 27 | + expect(property.isArray()).to.equal(true); |
| 28 | + }); |
| 29 | + }); |
30 | 30 |
|
31 | 31 | describe('#type', () => {
|
32 | 32 | it('returns correct string type', () => {
|
33 |
| - const property = new Property(getRawProperty('User', 'firstName')) |
34 |
| - expect(property.type()).to.equal('string') |
35 |
| - }) |
| 33 | + const property = new Property(getRawProperty('User', 'firstName')); |
| 34 | + expect(property.type()).to.equal('string'); |
| 35 | + }); |
36 | 36 |
|
37 | 37 | it('returns correct integer type', () => {
|
38 |
| - const property = new Property(getRawProperty('User', 'id')) |
39 |
| - expect(property.type()).to.equal('number') |
40 |
| - }) |
| 38 | + const property = new Property(getRawProperty('User', 'id')); |
| 39 | + expect(property.type()).to.equal('number'); |
| 40 | + }); |
41 | 41 |
|
42 | 42 | it('returns correct date type', () => {
|
43 |
| - const property = new Property(getRawProperty('User', 'createdAt')) |
44 |
| - expect(property.type()).to.equal('datetime') |
45 |
| - }) |
| 43 | + const property = new Property(getRawProperty('User', 'createdAt')); |
| 44 | + expect(property.type()).to.equal('datetime'); |
| 45 | + }); |
46 | 46 |
|
47 | 47 | it('returns string when property is an array of strings', () => {
|
48 |
| - const property = new Property(getRawProperty('User', 'arrayed')) |
49 |
| - expect(property.type()).to.equal('string') |
50 |
| - }) |
51 |
| - }) |
| 48 | + const property = new Property(getRawProperty('User', 'arrayed')); |
| 49 | + expect(property.type()).to.equal('string'); |
| 50 | + }); |
| 51 | + }); |
52 | 52 |
|
53 | 53 | describe('#availableValues', () => {
|
54 | 54 | it('returns null for all standard (Non enum) values', () => {
|
55 |
| - const property = new Property(getRawProperty('User', 'email')) |
56 |
| - expect(property.availableValues()).to.equal(null) |
57 |
| - }) |
| 55 | + const property = new Property(getRawProperty('User', 'email')); |
| 56 | + expect(property.availableValues()).to.equal(null); |
| 57 | + }); |
58 | 58 |
|
59 | 59 | it('returns array of values for the enum field', () => {
|
60 |
| - const property = new Property(getRawProperty('User', 'gender')) |
61 |
| - expect(property.availableValues()).to.deep.equal(['male', 'female']) |
62 |
| - }) |
63 |
| - }) |
| 60 | + const property = new Property(getRawProperty('User', 'gender')); |
| 61 | + expect(property.availableValues()).to.deep.equal(['male', 'female']); |
| 62 | + }); |
| 63 | + }); |
64 | 64 |
|
65 | 65 | describe('#isEditable', () => {
|
66 | 66 | it('returns false for UUID property', () => {
|
67 |
| - const property = new Property(getRawProperty('Comment', 'id')) |
68 |
| - expect(property.isEditable()).to.equal(false) |
69 |
| - }) |
70 |
| - }) |
| 67 | + const property = new Property(getRawProperty('Comment', 'id')); |
| 68 | + expect(property.isEditable()).to.equal(false); |
| 69 | + }); |
| 70 | + }); |
71 | 71 |
|
72 | 72 | describe('#isId', () => {
|
73 | 73 | it('returns true for id when its default', () => {
|
74 |
| - const property = new Property(getRawProperty('User', 'id')) |
75 |
| - expect(property.isId()).to.eq(true) |
76 |
| - }) |
| 74 | + const property = new Property(getRawProperty('User', 'id')); |
| 75 | + expect(property.isId()).to.eq(true); |
| 76 | + }); |
77 | 77 |
|
78 | 78 | it('returns true for id when its uuid', () => {
|
79 |
| - const property = new Property(getRawProperty('Comment', 'id')) |
80 |
| - expect(property.isId()).to.eq(true) |
81 |
| - }) |
82 |
| - }) |
| 79 | + const property = new Property(getRawProperty('Comment', 'id')); |
| 80 | + expect(property.isId()).to.eq(true); |
| 81 | + }); |
| 82 | + }); |
83 | 83 |
|
84 | 84 | describe('isRequired', () => {
|
85 | 85 | it('returns true for required fields', () => {
|
86 |
| - const property = new Property(getRawProperty('User', 'email')) |
87 |
| - expect(property.isRequired()).to.equal(true) |
88 |
| - }) |
| 86 | + const property = new Property(getRawProperty('User', 'email')); |
| 87 | + expect(property.isRequired()).to.equal(true); |
| 88 | + }); |
89 | 89 |
|
90 | 90 | it('returns false for not required fields', () => {
|
91 |
| - const property = new Property(getRawProperty('User', 'gender')) |
92 |
| - expect(property.isRequired()).to.eq(false) |
93 |
| - }) |
94 |
| - }) |
95 |
| -}) |
| 91 | + const property = new Property(getRawProperty('User', 'gender')); |
| 92 | + expect(property.isRequired()).to.eq(false); |
| 93 | + }); |
| 94 | + }); |
| 95 | +}); |
0 commit comments