dyo-tools 0.1.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.c8rc.json +4 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +41 -0
- package/Makefile +34 -0
- package/README.md +0 -0
- package/TODO.md +18 -0
- package/babel.config.js +1 -0
- package/dist/core/DTBunch.d.ts +32 -0
- package/dist/core/DTBunch.js +283 -0
- package/dist/core/DTBunch.js.map +1 -0
- package/dist/core/DTComponent.d.ts +20 -0
- package/dist/core/DTComponent.js +41 -0
- package/dist/core/DTComponent.js.map +1 -0
- package/dist/core/DTComponentWithMeta.d.ts +9 -0
- package/dist/core/DTComponentWithMeta.js +32 -0
- package/dist/core/DTComponentWithMeta.js.map +1 -0
- package/dist/core/DTElement.d.ts +13 -0
- package/dist/core/DTElement.js +46 -0
- package/dist/core/DTElement.js.map +1 -0
- package/dist/core/DTError.d.ts +13 -0
- package/dist/core/DTError.js +28 -0
- package/dist/core/DTError.js.map +1 -0
- package/dist/core/DTPlayer.d.ts +8 -0
- package/dist/core/DTPlayer.js +30 -0
- package/dist/core/DTPlayer.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1321 -0
- package/dist/types/index.d.ts +58 -0
- package/dist/types/index.js +15 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/filters.d.ts +6 -0
- package/dist/utils/filters.js +39 -0
- package/dist/utils/filters.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/icons.css +1043 -0
- package/docs/assets/icons.png +0 -0
- package/docs/assets/icons@2x.png +0 -0
- package/docs/assets/main.js +52 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1388 -0
- package/docs/assets/widgets.png +0 -0
- package/docs/assets/widgets@2x.png +0 -0
- package/docs/classes/DTBunch.html +265 -0
- package/docs/classes/DTComponent.html +49 -0
- package/docs/classes/DTComponentWithMeta.html +73 -0
- package/docs/classes/DTElement.html +95 -0
- package/docs/classes/DTError.html +32 -0
- package/docs/classes/DTPlayer.html +86 -0
- package/docs/index.html +1 -0
- package/docs/modules.html +1 -0
- package/jest.config.js +6 -0
- package/package.json +41 -0
- package/src/core/DTBunch.ts +600 -0
- package/src/core/DTComponent.ts +135 -0
- package/src/core/DTComponentWithMeta.ts +62 -0
- package/src/core/DTElement.ts +96 -0
- package/src/core/DTError.ts +78 -0
- package/src/core/DTPlayer.ts +57 -0
- package/src/index.ts +7 -0
- package/src/types/index.ts +76 -0
- package/src/utils/filters.ts +64 -0
- package/test/core/DTBunch.double.ts +150 -0
- package/test/core/DTBunch.spec.ts +1374 -0
- package/test/core/DTComponent.double.ts +69 -0
- package/test/core/DTComponent.spec.ts +182 -0
- package/test/core/DTComponentWithMeta.double.ts +88 -0
- package/test/core/DTComponentWithMeta.spec.ts +112 -0
- package/test/core/DTElement.double.ts +27 -0
- package/test/core/DTElement.spec.ts +181 -0
- package/test/core/DTError.double.ts +43 -0
- package/test/core/DTError.spec.ts +106 -0
- package/test/core/DTPlayer.double.ts +49 -0
- package/test/core/DTPlayer.spec.ts +102 -0
- package/test/utils/filters.spec.ts +109 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
afterEach, beforeEach, describe, expect, jest, test,
|
|
3
|
+
} from '@jest/globals';
|
|
4
|
+
import {
|
|
5
|
+
CodeTest, DTErrorMock, MessageTest, TimestampTest,
|
|
6
|
+
} from './DTError.double';
|
|
7
|
+
import { DTError } from '../../src';
|
|
8
|
+
import { DTComponentStub, IDTest as ComponentIdTest } from './DTComponent.double';
|
|
9
|
+
|
|
10
|
+
describe('class DYOToolsError', () => {
|
|
11
|
+
let errorMock: DTErrorMock;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
errorMock = new DTErrorMock();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
jest.restoreAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('constructor()', () => {
|
|
22
|
+
test('creation with standard field (code, message and timestamp)', () => {
|
|
23
|
+
const newError = new DTError(CodeTest, MessageTest);
|
|
24
|
+
const currentDate = new Date();
|
|
25
|
+
jest.spyOn(newError, 'getCode').mockImplementation(function () {
|
|
26
|
+
return this.code;
|
|
27
|
+
});
|
|
28
|
+
jest.spyOn(newError, 'getMessage').mockImplementation(function () {
|
|
29
|
+
return this.message;
|
|
30
|
+
});
|
|
31
|
+
jest.spyOn(newError, 'getTimestamp').mockImplementation(function () {
|
|
32
|
+
return this.timestamp;
|
|
33
|
+
});
|
|
34
|
+
jest.spyOn(newError, 'getInitiator').mockImplementation(function () {
|
|
35
|
+
return this.initiator;
|
|
36
|
+
});
|
|
37
|
+
jest.spyOn(newError, 'getConvicted').mockImplementation(function () {
|
|
38
|
+
return this.convicted;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(newError.getCode()).toBe(CodeTest);
|
|
42
|
+
expect(newError.getMessage()).toBe(MessageTest);
|
|
43
|
+
expect(newError.getTimestamp().toDateString()).toBe(currentDate.toDateString());
|
|
44
|
+
expect(newError.getTimestamp().toTimeString()).toBe(currentDate.toTimeString());
|
|
45
|
+
expect(newError.getInitiator()).toBeUndefined();
|
|
46
|
+
expect(newError.getConvicted()).toBeUndefined();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('creation with initiator component', () => {
|
|
50
|
+
const initiatorMock = new DTComponentStub('initiator');
|
|
51
|
+
const newError = new DTError(CodeTest, MessageTest, initiatorMock);
|
|
52
|
+
jest.spyOn(newError, 'getInitiator').mockImplementation(function () {
|
|
53
|
+
return this.initiator;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(newError.getInitiator().getId()).toBe(`${ComponentIdTest}-initiator`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('creation with initiator and convicted component', () => {
|
|
60
|
+
const initiatorMock = new DTComponentStub('initiator');
|
|
61
|
+
const convictedMock = new DTComponentStub('convicted');
|
|
62
|
+
const newError = new DTError(CodeTest, MessageTest, initiatorMock, convictedMock);
|
|
63
|
+
jest.spyOn(newError, 'getConvicted').mockImplementation(function () {
|
|
64
|
+
return this.convicted;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(newError.getConvicted().getId()).toBe(`${ComponentIdTest}-convicted`);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('getCode()', () => {
|
|
72
|
+
test('return code property', () => {
|
|
73
|
+
expect(errorMock.getCode()).toBe(CodeTest);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('getMessage()', () => {
|
|
78
|
+
test('return message property', () => {
|
|
79
|
+
expect(errorMock.getMessage()).toBe(MessageTest);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('getTimestamp()', () => {
|
|
84
|
+
test('return timestamp property', () => {
|
|
85
|
+
expect(errorMock.getTimestamp().getTime()).toBe(TimestampTest);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('getInitiator()', () => {
|
|
90
|
+
test('return initiator component', () => {
|
|
91
|
+
const errorMockSet = new DTErrorMock(true);
|
|
92
|
+
|
|
93
|
+
expect(errorMock.getInitiator()).toBeUndefined();
|
|
94
|
+
expect(errorMockSet.getInitiator().getId()).toBe(`${ComponentIdTest}-initiator`);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('getConvicted()', () => {
|
|
99
|
+
test('return convicted component', () => {
|
|
100
|
+
const errorMockSet = new DTErrorMock(true);
|
|
101
|
+
|
|
102
|
+
expect(errorMock.getConvicted()).toBeUndefined();
|
|
103
|
+
expect(errorMockSet.getConvicted().getId()).toBe(`${ComponentIdTest}-convicted`);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DTPlayer } from '../../src';
|
|
2
|
+
import { IMetaDataTest, PlayerMetaData } from './DTComponentWithMeta.double';
|
|
3
|
+
|
|
4
|
+
// Global Variables
|
|
5
|
+
export const IDTest = 'DTPlayer-id-1234567';
|
|
6
|
+
export const KeyTest = 'DTPlayer-key-1234567';
|
|
7
|
+
export const toStringTest = 'DTPlayer Stub toString';
|
|
8
|
+
|
|
9
|
+
// Stub for Player (used for other tests)
|
|
10
|
+
export class DTPlayerStub extends DTPlayer<{}> {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this._id = IDTest;
|
|
14
|
+
this._key = KeyTest;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getKey(): string {
|
|
18
|
+
return KeyTest;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getId(): string {
|
|
22
|
+
return IDTest;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString(): string {
|
|
26
|
+
return toStringTest;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Mock Constructor and parent methods for DTPlayer
|
|
31
|
+
export class DTPlayerMock extends DTPlayer<IMetaDataTest> {
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
this._id = IDTest;
|
|
35
|
+
this._key = KeyTest;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getComponentType(): string {
|
|
39
|
+
return this._componentType;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setManyMeta(metaValues: Partial<IMetaDataTest>) {
|
|
43
|
+
this._meta = PlayerMetaData;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getManyMeta(metaKeys: Array<keyof IMetaDataTest> = []): Partial<IMetaDataTest> {
|
|
47
|
+
return this._meta;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { beforeEach, describe, test } from '@jest/globals';
|
|
2
|
+
import { DTPlayerMock, IDTest, KeyTest } from './DTPlayer.double';
|
|
3
|
+
import { DTComponentTestMock } from './DTComponent.double';
|
|
4
|
+
import { PlayerMetaData } from './DTComponentWithMeta.double';
|
|
5
|
+
|
|
6
|
+
describe('class DYOToolsPlayer', () => {
|
|
7
|
+
let playerMock: DTPlayerMock;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
playerMock = new DTPlayerMock();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
jest.restoreAllMocks();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('_componentType', () => {
|
|
18
|
+
test('componentType must be "player"', () => {
|
|
19
|
+
expect(playerMock.getComponentType()).toBe('player');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('copy()', () => {
|
|
24
|
+
test('copy a player - simple case with id and key', () => {
|
|
25
|
+
// This test doesn't mock the DOC (Depended-on Component) correctly
|
|
26
|
+
// Need to change implementation to implement correct testing
|
|
27
|
+
const playerMockCopy = playerMock.copy();
|
|
28
|
+
jest.spyOn(playerMock, 'getId').mockImplementation(function () {
|
|
29
|
+
return this._id;
|
|
30
|
+
});
|
|
31
|
+
jest.spyOn(playerMockCopy, 'getId').mockImplementation(function () {
|
|
32
|
+
return this._id;
|
|
33
|
+
});
|
|
34
|
+
jest.spyOn(playerMock, 'getKey').mockImplementation(function () {
|
|
35
|
+
return this._key;
|
|
36
|
+
});
|
|
37
|
+
jest.spyOn(playerMockCopy, 'getKey').mockImplementation(function () {
|
|
38
|
+
return this._key;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(playerMock.getId() === playerMockCopy.getId()).toBeFalsy();
|
|
42
|
+
expect(playerMock.getKey() === playerMockCopy.getKey()).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('copy a player - not copy context', () => {
|
|
46
|
+
// This test doesn't mock the DOC (Depended-on Component) correctly
|
|
47
|
+
// Need to change implementation to implement correct testing
|
|
48
|
+
jest.spyOn(playerMock, 'setContext').mockImplementation(function (context) {
|
|
49
|
+
this._context = context;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
playerMock.setContext(new DTComponentTestMock());
|
|
53
|
+
|
|
54
|
+
const playerMockCopy = playerMock.copy();
|
|
55
|
+
jest.spyOn(playerMockCopy, 'getContext').mockImplementation(function () {
|
|
56
|
+
return this._context;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(playerMockCopy.getContext()).toBeUndefined();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('copy a player - copy meta-data', () => {
|
|
63
|
+
// This test doesn't mock the DOC (Depended-on Component) correctly
|
|
64
|
+
// Need to change implementation to implement correct testing
|
|
65
|
+
playerMock.setManyMeta({});
|
|
66
|
+
|
|
67
|
+
const playerMockCopy = playerMock.copy();
|
|
68
|
+
jest.spyOn(playerMockCopy, 'getManyMeta').mockImplementation(function () {
|
|
69
|
+
return this._meta;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(playerMockCopy.getManyMeta()).toStrictEqual(PlayerMetaData);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('toObject()', () => {
|
|
77
|
+
test('toObject output standard', () => {
|
|
78
|
+
const toObjectPlayer = playerMock.toObject();
|
|
79
|
+
|
|
80
|
+
expect(Object.keys(toObjectPlayer)).toStrictEqual(['id', 'key', 'type']);
|
|
81
|
+
expect(toObjectPlayer.id).toBe(IDTest);
|
|
82
|
+
expect(toObjectPlayer.key).toBe(KeyTest);
|
|
83
|
+
expect(toObjectPlayer.type).toBe('player');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('toObject output standard with meta', () => {
|
|
87
|
+
playerMock.setManyMeta({});
|
|
88
|
+
|
|
89
|
+
const toObjectPlayer = playerMock.toObject();
|
|
90
|
+
expect(Object.keys(toObjectPlayer)).toStrictEqual(['id', 'key', 'type', 'meta']);
|
|
91
|
+
expect(toObjectPlayer.meta).toStrictEqual(PlayerMetaData);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('toString()', () => {
|
|
96
|
+
test('string output standard', () => {
|
|
97
|
+
const toStringElement = playerMock.toString();
|
|
98
|
+
|
|
99
|
+
expect(toStringElement).toBe(`Component ${KeyTest} - Type: Player`);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { describe } from '@jest/globals';
|
|
2
|
+
import { validFiltersForItem } from '../../src/utils/filters';
|
|
3
|
+
import { FilterOperatorType } from '../../src/types';
|
|
4
|
+
|
|
5
|
+
describe('validFiltersForItem', () => {
|
|
6
|
+
test('valid value for $eq equivalency', () => {
|
|
7
|
+
expect(validFiltersForItem('filter-id', 'filter-id', FilterOperatorType.EQ)).toBe(true);
|
|
8
|
+
expect(validFiltersForItem('12345', 'filter-id', FilterOperatorType.EQ)).toBe(false);
|
|
9
|
+
expect(validFiltersForItem(12345, '12345', FilterOperatorType.EQ)).toBe(false);
|
|
10
|
+
expect(validFiltersForItem(true, true, FilterOperatorType.EQ)).toBe(true);
|
|
11
|
+
expect(validFiltersForItem(false, true, FilterOperatorType.EQ)).toBe(false);
|
|
12
|
+
expect(validFiltersForItem(null, null, FilterOperatorType.EQ)).toBe(true);
|
|
13
|
+
expect(validFiltersForItem(0, null, FilterOperatorType.EQ)).toBe(false);
|
|
14
|
+
expect(validFiltersForItem(undefined, null, FilterOperatorType.EQ)).toBe(false);
|
|
15
|
+
expect(validFiltersForItem(12345, 12345, FilterOperatorType.EQ)).toBe(true);
|
|
16
|
+
expect(validFiltersForItem(45678, 12345, FilterOperatorType.EQ)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('valid value for $in operator', () => {
|
|
20
|
+
expect(validFiltersForItem('filter-id', ['filter-id'], FilterOperatorType.IN)).toBe(true);
|
|
21
|
+
expect(validFiltersForItem('filter-id', ['filter-id', '12345'], FilterOperatorType.IN)).toBe(true);
|
|
22
|
+
expect(validFiltersForItem('filter-id', ['12345', 'filter-key'], FilterOperatorType.IN)).toBe(false);
|
|
23
|
+
expect(validFiltersForItem(true, [true, 12345, 'filter-id'], FilterOperatorType.IN)).toBe(true);
|
|
24
|
+
expect(validFiltersForItem(false, [true, 12345, 'filter-id'], FilterOperatorType.IN)).toBe(false);
|
|
25
|
+
expect(validFiltersForItem(null, [null, 12345, 'filter-id'], FilterOperatorType.IN)).toBe(true);
|
|
26
|
+
expect(validFiltersForItem(undefined, [null, 12345, 'filter-id'], FilterOperatorType.IN)).toBe(false);
|
|
27
|
+
expect(validFiltersForItem(12345, ['filter-id', 12345, 45678, true], FilterOperatorType.IN)).toBe(true);
|
|
28
|
+
expect(validFiltersForItem(17, ['filter-id', 12345, 45678, true], FilterOperatorType.IN)).toBe(false);
|
|
29
|
+
expect(validFiltersForItem('filter-id', null, FilterOperatorType.IN)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('valid value for $nin operator', () => {
|
|
33
|
+
expect(validFiltersForItem('filter-id', ['filter-id'], FilterOperatorType.NIN)).toBe(false);
|
|
34
|
+
expect(validFiltersForItem('filter-id', ['filter-id', '12345'], FilterOperatorType.NIN)).toBe(false);
|
|
35
|
+
expect(validFiltersForItem('filter-id', ['12345', 'filter-key'], FilterOperatorType.NIN)).toBe(true);
|
|
36
|
+
expect(validFiltersForItem(true, [true, 12345, 'filter-id'], FilterOperatorType.NIN)).toBe(false);
|
|
37
|
+
expect(validFiltersForItem(false, [true, 12345, 'filter-id'], FilterOperatorType.NIN)).toBe(true);
|
|
38
|
+
expect(validFiltersForItem(null, [null, 12345, 'filter-id'], FilterOperatorType.NIN)).toBe(false);
|
|
39
|
+
expect(validFiltersForItem(undefined, [null, 12345, 'filter-id'], FilterOperatorType.NIN)).toBe(true);
|
|
40
|
+
expect(validFiltersForItem(12345, ['filter-id', 12345, 45678, true], FilterOperatorType.NIN)).toBe(false);
|
|
41
|
+
expect(validFiltersForItem(17, ['filter-id', 12345, 45678, true], FilterOperatorType.NIN)).toBe(true);
|
|
42
|
+
expect(validFiltersForItem('filter-id', null, FilterOperatorType.NIN)).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('valid value for $ne operator', () => {
|
|
46
|
+
expect(validFiltersForItem('filter-id', 'filter-id', FilterOperatorType.NE)).toBe(false);
|
|
47
|
+
expect(validFiltersForItem('12345', 'filter-id', FilterOperatorType.NE)).toBe(true);
|
|
48
|
+
expect(validFiltersForItem(12345, '12345', FilterOperatorType.NE)).toBe(true);
|
|
49
|
+
expect(validFiltersForItem(true, true, FilterOperatorType.NE)).toBe(false);
|
|
50
|
+
expect(validFiltersForItem(false, true, FilterOperatorType.NE)).toBe(true);
|
|
51
|
+
expect(validFiltersForItem(null, null, FilterOperatorType.NE)).toBe(false);
|
|
52
|
+
expect(validFiltersForItem(0, null, FilterOperatorType.NE)).toBe(true);
|
|
53
|
+
expect(validFiltersForItem(undefined, null, FilterOperatorType.NE)).toBe(true);
|
|
54
|
+
expect(validFiltersForItem(12345, 12345, FilterOperatorType.NE)).toBe(false);
|
|
55
|
+
expect(validFiltersForItem(45678, 12345, FilterOperatorType.NE)).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('valid value for $lte operator', () => {
|
|
59
|
+
expect(validFiltersForItem(1, 3, FilterOperatorType.LTE)).toBe(true);
|
|
60
|
+
expect(validFiltersForItem(5, 3, FilterOperatorType.LTE)).toBe(false);
|
|
61
|
+
expect(validFiltersForItem(3, 3, FilterOperatorType.LTE)).toBe(true);
|
|
62
|
+
expect(validFiltersForItem(0, 0, FilterOperatorType.LTE)).toBe(true);
|
|
63
|
+
expect(validFiltersForItem(-11, 0, FilterOperatorType.LTE)).toBe(true);
|
|
64
|
+
expect(validFiltersForItem(-7, -11, FilterOperatorType.LTE)).toBe(false);
|
|
65
|
+
expect(validFiltersForItem(null, -11, FilterOperatorType.LTE)).toBe(false);
|
|
66
|
+
expect(validFiltersForItem(undefined, -11, FilterOperatorType.LTE)).toBe(false);
|
|
67
|
+
expect(validFiltersForItem(0, null, FilterOperatorType.LTE)).toBe(false);
|
|
68
|
+
expect(validFiltersForItem(0, undefined, FilterOperatorType.LTE)).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('valid value for $gte operator', () => {
|
|
72
|
+
expect(validFiltersForItem(1, 3, FilterOperatorType.GTE)).toBe(false);
|
|
73
|
+
expect(validFiltersForItem(5, 3, FilterOperatorType.GTE)).toBe(true);
|
|
74
|
+
expect(validFiltersForItem(3, 3, FilterOperatorType.GTE)).toBe(true);
|
|
75
|
+
expect(validFiltersForItem(0, 0, FilterOperatorType.GTE)).toBe(true);
|
|
76
|
+
expect(validFiltersForItem(-11, 0, FilterOperatorType.GTE)).toBe(false);
|
|
77
|
+
expect(validFiltersForItem(-7, -11, FilterOperatorType.GTE)).toBe(true);
|
|
78
|
+
expect(validFiltersForItem(null, -7, FilterOperatorType.GTE)).toBe(false);
|
|
79
|
+
expect(validFiltersForItem(undefined, -7, FilterOperatorType.GTE)).toBe(false);
|
|
80
|
+
expect(validFiltersForItem(0, null, FilterOperatorType.GTE)).toBe(false);
|
|
81
|
+
expect(validFiltersForItem(0, undefined, FilterOperatorType.GTE)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('valid value for $contains operator', () => {
|
|
85
|
+
expect(validFiltersForItem(['filter-id'], 'filter-id', FilterOperatorType.CONTAINS)).toBe(true);
|
|
86
|
+
expect(validFiltersForItem(['filter-id', '12345'], 'filter-id', FilterOperatorType.CONTAINS)).toBe(true);
|
|
87
|
+
expect(validFiltersForItem(['12345', 'filter-key'], 'filter-id', FilterOperatorType.CONTAINS)).toBe(false);
|
|
88
|
+
expect(validFiltersForItem([true, 12345, 'filter-id'], true, FilterOperatorType.CONTAINS)).toBe(true);
|
|
89
|
+
expect(validFiltersForItem([true, 12345, 'filter-id'], false, FilterOperatorType.CONTAINS)).toBe(false);
|
|
90
|
+
expect(validFiltersForItem([null, 12345, 'filter-id'], null, FilterOperatorType.CONTAINS)).toBe(true);
|
|
91
|
+
expect(validFiltersForItem([null, 12345, 'filter-id'], undefined, FilterOperatorType.CONTAINS)).toBe(false);
|
|
92
|
+
expect(validFiltersForItem(['filter-id', 12345, 45678, true], 12345, FilterOperatorType.CONTAINS)).toBe(true);
|
|
93
|
+
expect(validFiltersForItem(['filter-id', 12345, 45678, true], 17, FilterOperatorType.CONTAINS)).toBe(false);
|
|
94
|
+
expect(validFiltersForItem(null, 'filter-id', FilterOperatorType.CONTAINS)).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('valid value for $ncontains operator', () => {
|
|
98
|
+
expect(validFiltersForItem(['filter-id'], 'filter-id', FilterOperatorType.NCONTAINS)).toBe(false);
|
|
99
|
+
expect(validFiltersForItem(['filter-id', '12345'], 'filter-id', FilterOperatorType.NCONTAINS)).toBe(false);
|
|
100
|
+
expect(validFiltersForItem(['12345', 'filter-key'], 'filter-id', FilterOperatorType.NCONTAINS)).toBe(true);
|
|
101
|
+
expect(validFiltersForItem([true, 12345, 'filter-id'], true, FilterOperatorType.NCONTAINS)).toBe(false);
|
|
102
|
+
expect(validFiltersForItem([true, 12345, 'filter-id'], false, FilterOperatorType.NCONTAINS)).toBe(true);
|
|
103
|
+
expect(validFiltersForItem([null, 12345, 'filter-id'], null, FilterOperatorType.NCONTAINS)).toBe(false);
|
|
104
|
+
expect(validFiltersForItem([null, 12345, 'filter-id'], undefined, FilterOperatorType.NCONTAINS)).toBe(true);
|
|
105
|
+
expect(validFiltersForItem(['filter-id', 12345, 45678, true], 12345, FilterOperatorType.NCONTAINS)).toBe(false);
|
|
106
|
+
expect(validFiltersForItem(['filter-id', 12345, 45678, true], 17, FilterOperatorType.NCONTAINS)).toBe(true);
|
|
107
|
+
expect(validFiltersForItem(null, 'filter-id', FilterOperatorType.NCONTAINS)).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"target": "es2015",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"incremental": true
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"src/**/*.ts"
|
|
17
|
+
],
|
|
18
|
+
"exclude": [
|
|
19
|
+
"node_modules"
|
|
20
|
+
]
|
|
21
|
+
}
|