@unchainedshop/core-worker 4.3.4 → 4.4.0

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.
@@ -1,211 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
- import { WorkStatus } from '../worker-index.js';
4
- import { buildQuerySelector } from './configureWorkerModule.js';
5
-
6
- describe('Worker', () => {
7
- describe('buildQuerySelector', () => {
8
- it('Return correct filter object when passed no argument', () => {
9
- assert.deepStrictEqual(buildQuerySelector({}), { deleted: { $exists: false } });
10
- });
11
-
12
- it('Return correct filter object when passed create, queryString, scheduled, status, types & workId', () => {
13
- const selector = buildQuerySelector({
14
- created: {
15
- start: new Date('2022-12-04T17:13:09.285Z'),
16
- end: new Date('2022-12-04T17:13:09.285Z'),
17
- },
18
- queryString: 'hello world',
19
- scheduled: {
20
- end: new Date('2022-12-04T17:13:09.285Z'),
21
- start: new Date('2022-12-04T17:13:09.285Z'),
22
- },
23
- status: [WorkStatus.ALLOCATED],
24
- types: ['EMAIL'],
25
- workId: 'work-id',
26
- });
27
- assert.deepStrictEqual(selector, {
28
- _id: 'work-id',
29
- $or: [
30
- {
31
- started: { $exists: true },
32
- finished: { $exists: false },
33
- deleted: { $exists: false },
34
- },
35
- ],
36
- created: {
37
- $gte: new Date('2022-12-04T17:13:09.285Z'),
38
- $lte: new Date('2022-12-04T17:13:09.285Z'),
39
- },
40
- scheduled: {
41
- $gte: new Date('2022-12-04T17:13:09.285Z'),
42
- $lte: new Date('2022-12-04T17:13:09.285Z'),
43
- },
44
- type: { $in: ['EMAIL'] },
45
- $text: { $search: 'hello world' },
46
- });
47
- });
48
-
49
- it('Return correct filter object when passed queryString, scheduled, status, types & workId', () => {
50
- const selector = buildQuerySelector({
51
- queryString: 'hello world',
52
- scheduled: {
53
- end: new Date('2022-12-04T17:13:09.285Z'),
54
- start: new Date('2022-12-04T17:13:09.285Z'),
55
- },
56
- status: [WorkStatus.ALLOCATED],
57
- types: ['EMAIL'],
58
- workId: 'work-id',
59
- });
60
- assert.deepStrictEqual(selector, {
61
- _id: 'work-id',
62
- $or: [
63
- {
64
- started: { $exists: true },
65
- finished: { $exists: false },
66
- deleted: { $exists: false },
67
- },
68
- ],
69
- scheduled: {
70
- $gte: new Date('2022-12-04T17:13:09.285Z'),
71
- $lte: new Date('2022-12-04T17:13:09.285Z'),
72
- },
73
- type: { $in: ['EMAIL'] },
74
- $text: { $search: 'hello world' },
75
- });
76
- });
77
-
78
- it('Return correct filter object when passed scheduled, status, types & workId', () => {
79
- const selector = buildQuerySelector({
80
- scheduled: {
81
- end: new Date('2022-12-04T17:13:09.285Z'),
82
- start: new Date('2022-12-04T17:13:09.285Z'),
83
- },
84
- status: [WorkStatus.ALLOCATED],
85
- types: ['EMAIL'],
86
- workId: 'work-id',
87
- });
88
- assert.deepStrictEqual(selector, {
89
- _id: 'work-id',
90
- $or: [
91
- {
92
- started: { $exists: true },
93
- finished: { $exists: false },
94
- deleted: { $exists: false },
95
- },
96
- ],
97
- scheduled: {
98
- $gte: new Date('2022-12-04T17:13:09.285Z'),
99
- $lte: new Date('2022-12-04T17:13:09.285Z'),
100
- },
101
- type: { $in: ['EMAIL'] },
102
- });
103
- });
104
-
105
- it('Return correct filter object when passed status, types & workId', () => {
106
- const selector = buildQuerySelector({
107
- status: [WorkStatus.ALLOCATED],
108
- types: ['EMAIL'],
109
- workId: 'work-id',
110
- });
111
- assert.deepStrictEqual(selector, {
112
- _id: 'work-id',
113
- $or: [
114
- {
115
- started: { $exists: true },
116
- finished: { $exists: false },
117
- deleted: { $exists: false },
118
- },
119
- ],
120
- type: { $in: ['EMAIL'] },
121
- });
122
- });
123
-
124
- it('Return correct filter object when passed types & workId', () => {
125
- const selector = buildQuerySelector({ types: ['EMAIL'], workId: 'work-id' });
126
- assert.deepStrictEqual(selector, {
127
- _id: 'work-id',
128
- deleted: { $exists: false },
129
- type: { $in: ['EMAIL'] },
130
- });
131
- });
132
-
133
- it('Return correct filter object when passed workId', () => {
134
- const selector = buildQuerySelector({ workId: 'work-id' });
135
- assert.deepStrictEqual(selector, {
136
- _id: 'work-id',
137
- deleted: { $exists: false },
138
- });
139
- });
140
-
141
- it('Create start should be set to start of unix timestamp if created.start not provided', () => {
142
- const selector = buildQuerySelector({
143
- workId: 'work-id',
144
- created: { end: new Date('2022-12-04T17:13:09.285Z') },
145
- });
146
-
147
- assert.deepStrictEqual(selector, {
148
- _id: 'work-id',
149
- deleted: { $exists: false },
150
- created: {
151
- $gte: new Date(0),
152
- $lte: new Date('2022-12-04T17:13:09.285Z'),
153
- },
154
- });
155
- });
156
-
157
- it('Create start should be set to start or unix timestamp if created.end not provided', () => {
158
- const selector = buildQuerySelector({
159
- workId: 'work-id',
160
- created: { start: new Date('2022-12-04T17:13:09.285Z') },
161
- });
162
-
163
- assert.deepStrictEqual(selector, {
164
- _id: 'work-id',
165
- deleted: { $exists: false },
166
- created: { $gte: new Date('2022-12-04T17:13:09.285Z') },
167
- });
168
-
169
- assert.deepStrictEqual(buildQuerySelector({ workId: 'work-id', created: {} }), {
170
- _id: 'work-id',
171
- deleted: { $exists: false },
172
- created: { $gte: new Date(0) },
173
- });
174
- });
175
-
176
- it('scheduled start should be set to start of unix timestamp if scheduled.start not provided', () => {
177
- const selector = buildQuerySelector({
178
- workId: 'work-id',
179
- scheduled: { end: new Date('2022-12-04T17:13:09.285Z') },
180
- });
181
-
182
- assert.deepStrictEqual(selector, {
183
- _id: 'work-id',
184
- deleted: { $exists: false },
185
- scheduled: {
186
- $gte: new Date(0),
187
- $lte: new Date('2022-12-04T17:13:09.285Z'),
188
- },
189
- });
190
- });
191
-
192
- it('Scheduled start should be set to start or unix timestamp if scheduled.end not provided', () => {
193
- const selector = buildQuerySelector({
194
- workId: 'work-id',
195
- scheduled: { start: new Date('2022-12-04T17:13:09.285Z') },
196
- });
197
-
198
- assert.deepStrictEqual(selector, {
199
- _id: 'work-id',
200
- deleted: { $exists: false },
201
- scheduled: { $gte: new Date('2022-12-04T17:13:09.285Z') },
202
- });
203
-
204
- assert.deepStrictEqual(buildQuerySelector({ workId: 'work-id', scheduled: {} }), {
205
- _id: 'work-id',
206
- deleted: { $exists: false },
207
- scheduled: { $gte: new Date(0) },
208
- });
209
- });
210
- });
211
- });