@doctocar/tooling 0.3.1-34 → 0.3.1-36

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.
Files changed (27) hide show
  1. package/dist/firebase/firestore/types/order/FirestoreOrderDocument.type.d.ts +6 -2
  2. package/dist/firebase/firestore/utils/dataValidators/slots/__tests__/isValidOneTimeSlot.test.d.ts +1 -0
  3. package/dist/firebase/firestore/utils/dataValidators/slots/__tests__/isValidOneTimeSlot.test.js +287 -0
  4. package/dist/firebase/firestore/utils/dataValidators/slots/__tests__/isValidRecurringSlot.test.d.ts +1 -0
  5. package/dist/firebase/firestore/utils/dataValidators/slots/__tests__/isValidRecurringSlot.test.js +527 -0
  6. package/dist/firebase/firestore/utils/dataValidators/slots/__tests__/isValidTimeOffSlot.test.d.ts +1 -0
  7. package/dist/firebase/firestore/utils/dataValidators/slots/__tests__/isValidTimeOffSlot.test.js +272 -0
  8. package/dist/firebase/firestore/utils/dataValidators/slots/index.d.ts +3 -3
  9. package/dist/firebase/firestore/utils/dataValidators/slots/index.js +3 -3
  10. package/dist/firebase/firestore/utils/dataValidators/slots/isValidOneTimeSlot.d.ts +2 -0
  11. package/dist/firebase/firestore/utils/dataValidators/slots/isValidOneTimeSlot.js +45 -0
  12. package/dist/firebase/firestore/utils/dataValidators/slots/isValidRecurringSlot.d.ts +2 -0
  13. package/dist/firebase/firestore/utils/dataValidators/slots/isValidRecurringSlot.js +83 -0
  14. package/dist/firebase/firestore/utils/dataValidators/slots/isValidTimeOffSlot.d.ts +2 -0
  15. package/dist/firebase/firestore/utils/dataValidators/slots/isValidTimeOffSlot.js +45 -0
  16. package/dist/gcp/pubsub/enums/PubSubTopics.enum.d.ts +1 -1
  17. package/dist/gcp/pubsub/enums/PubSubTopics.enum.js +1 -1
  18. package/dist/gcp/pubsub/maps/PubSubTopicMessageMap.map.d.ts +2 -2
  19. package/dist/gcp/pubsub/types/orders/PubSubOrderInvoicedMessage.type.d.ts +3 -0
  20. package/dist/gcp/pubsub/types/orders/PubSubOrderInvoicedMessage.type.js +2 -0
  21. package/dist/gcp/pubsub/types/orders/index.d.ts +1 -1
  22. package/dist/gcp/pubsub/types/orders/index.js +1 -1
  23. package/dist/gcp/pubsub/utils/stubs/index.d.ts +1 -1
  24. package/dist/gcp/pubsub/utils/stubs/index.js +1 -1
  25. package/dist/gcp/pubsub/utils/stubs/pubSubOrderInvoicedMessageStub.d.ts +2 -0
  26. package/dist/gcp/pubsub/utils/stubs/pubSubOrderInvoicedMessageStub.js +9 -0
  27. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import type { SupportedIsoCurrency } from "../../../../enums";
1
2
  import type { FirestoreOpType, OrderInvoiceGenerationStatus, OrderIssueSeverityLevel, OrderStatusTypes } from "../../enums";
2
3
  import type { FirestoreTimestamp } from "../FirestoreTimestamp.type";
3
4
  import type { DoctoCarLocation } from "../location";
@@ -44,6 +45,7 @@ export type FirestoreOrderDocument = {
44
45
  serviceCompletedAt?: FirestoreTimestamp;
45
46
  issueReportedByCustomerAt?: FirestoreTimestamp;
46
47
  completedAt?: FirestoreTimestamp;
48
+ invoicedAt?: FirestoreTimestamp;
47
49
  cancelledAt?: FirestoreTimestamp;
48
50
  };
49
51
  publicReference: string;
@@ -138,8 +140,10 @@ export type FirestoreOrderDocument = {
138
140
  };
139
141
  execution?: {
140
142
  serviceProviderEntityWalletCredit?: {
141
- walletLedgerEntryId?: string;
142
- creditedAt?: FirestoreTimestamp;
143
+ walletLedgerEntryId: string;
144
+ creditedAt: FirestoreTimestamp;
145
+ amountInCents: number;
146
+ currency: SupportedIsoCurrency;
143
147
  };
144
148
  };
145
149
  metadata?: Record<string, string>;
@@ -0,0 +1,287 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ const constants_1 = require("../../../../../../constants");
5
+ const constants_2 = require("../../../../constants");
6
+ const enums_1 = require("../../../../enums");
7
+ const stubs_1 = require("../../../stubs");
8
+ const constants_3 = require("../constants");
9
+ const isValidOneTimeSlot_1 = require("../isValidOneTimeSlot");
10
+ describe("isValidOneTimeSlot", () => {
11
+ const baseValidSlot = {
12
+ type: enums_1.SlotType.ONE_TIME,
13
+ capacity: 3,
14
+ createdAt: (0, stubs_1.firestoreTimestampStub)(),
15
+ updatedAt: (0, stubs_1.firestoreTimestampStub)(),
16
+ timeZone: "Europe/Paris",
17
+ };
18
+ beforeEach(() => {
19
+ jest
20
+ .useFakeTimers()
21
+ .setSystemTime(new Date("2024-01-01T12:00:00Z").getTime());
22
+ });
23
+ afterEach(() => {
24
+ jest.useRealTimers();
25
+ });
26
+ it("returns true for a valid slot", () => {
27
+ const slot = {
28
+ ...baseValidSlot,
29
+ timestampRange: {
30
+ startAt: (0, stubs_1.firestoreTimestampStub)({
31
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
32
+ }),
33
+ endAt: (0, stubs_1.firestoreTimestampStub)({
34
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
35
+ }),
36
+ },
37
+ };
38
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(slot)).toBe(true);
39
+ });
40
+ it("return true for differents valid timezones", () => {
41
+ const validTimezones = [
42
+ "Europe/Paris",
43
+ "Europe/Berlin",
44
+ "Europe/Madrid",
45
+ "Europe/Rome",
46
+ "Europe/Brussels",
47
+ "Europe/Moscow",
48
+ "America/New_York",
49
+ "Asia/Tokyo",
50
+ "Australia/Sydney",
51
+ "UTC",
52
+ "Europe/London",
53
+ "America/Los_Angeles",
54
+ "Asia/Kolkata",
55
+ "America/Argentina/Buenos_Aires",
56
+ "Asia/Shanghai",
57
+ ];
58
+ validTimezones.forEach((timezone) => {
59
+ const slot = {
60
+ ...baseValidSlot,
61
+ timeZone: timezone,
62
+ timestampRange: {
63
+ startAt: (0, stubs_1.firestoreTimestampStub)({
64
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
65
+ }),
66
+ endAt: (0, stubs_1.firestoreTimestampStub)({
67
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
68
+ }),
69
+ },
70
+ };
71
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(slot)).toBe(true);
72
+ });
73
+ });
74
+ it("return false if timeZone is missing or invalid", () => {
75
+ const missingTimeZone = {
76
+ ...baseValidSlot,
77
+ timeZone: undefined,
78
+ timestampRange: {
79
+ startAt: (0, stubs_1.firestoreTimestampStub)({
80
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
81
+ }),
82
+ endAt: (0, stubs_1.firestoreTimestampStub)({
83
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
84
+ }),
85
+ },
86
+ };
87
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(missingTimeZone)).toBe(false);
88
+ const slot = {
89
+ ...baseValidSlot,
90
+ timeZone: "",
91
+ timestampRange: {
92
+ startAt: (0, stubs_1.firestoreTimestampStub)({
93
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
94
+ }),
95
+ endAt: (0, stubs_1.firestoreTimestampStub)({
96
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
97
+ }),
98
+ },
99
+ };
100
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(slot)).toBe(false);
101
+ const invalidSlot = {
102
+ ...baseValidSlot,
103
+ timeZone: "Invalid/Timezone",
104
+ timestampRange: {
105
+ startAt: (0, stubs_1.firestoreTimestampStub)({
106
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
107
+ }),
108
+ endAt: (0, stubs_1.firestoreTimestampStub)({
109
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
110
+ }),
111
+ },
112
+ };
113
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(invalidSlot)).toBe(false);
114
+ });
115
+ it("return false if type is not ONE_TIME", () => {
116
+ const slot = {
117
+ ...baseValidSlot,
118
+ type: enums_1.SlotType.RECURRING,
119
+ timestampRange: {
120
+ startAt: (0, stubs_1.firestoreTimestampStub)({
121
+ toMillis: () => 0,
122
+ }),
123
+ endAt: (0, stubs_1.firestoreTimestampStub)({
124
+ toMillis: () => 1,
125
+ }),
126
+ },
127
+ };
128
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(slot)).toBe(false);
129
+ });
130
+ it("return false if timestampRange, startAt or endAt is missing", () => {
131
+ const missingTimeRange = {
132
+ ...baseValidSlot,
133
+ timestampRange: undefined,
134
+ };
135
+ const missingStart = {
136
+ ...baseValidSlot,
137
+ timestampRange: {
138
+ startAt: undefined,
139
+ endAt: (0, stubs_1.firestoreTimestampStub)({
140
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
141
+ }),
142
+ },
143
+ };
144
+ const missingEnd = {
145
+ ...baseValidSlot,
146
+ timestampRange: {
147
+ startAt: (0, stubs_1.firestoreTimestampStub)({
148
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
149
+ }),
150
+ endAt: undefined,
151
+ },
152
+ };
153
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(missingTimeRange)).toBe(false);
154
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(missingStart)).toBe(false);
155
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(missingEnd)).toBe(false);
156
+ });
157
+ it("return false if capacity is not an integer ≥ 1 <= MAXIMUM_SLOT_CAPACITY", () => {
158
+ const zeroCap = {
159
+ ...baseValidSlot,
160
+ capacity: 0,
161
+ timestampRange: {
162
+ startAt: (0, stubs_1.firestoreTimestampStub)({
163
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
164
+ }),
165
+ endAt: (0, stubs_1.firestoreTimestampStub)({
166
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
167
+ }),
168
+ },
169
+ };
170
+ const negCap = {
171
+ ...baseValidSlot,
172
+ capacity: -5,
173
+ timestampRange: {
174
+ startAt: (0, stubs_1.firestoreTimestampStub)({
175
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
176
+ }),
177
+ endAt: (0, stubs_1.firestoreTimestampStub)({
178
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
179
+ }),
180
+ },
181
+ };
182
+ const floatCap = {
183
+ ...baseValidSlot,
184
+ capacity: 2.5,
185
+ timestampRange: {
186
+ startAt: (0, stubs_1.firestoreTimestampStub)({
187
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
188
+ }),
189
+ endAt: (0, stubs_1.firestoreTimestampStub)({
190
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
191
+ }),
192
+ },
193
+ };
194
+ const tooBigCap = {
195
+ ...baseValidSlot,
196
+ capacity: constants_2.MAXIMUM_SLOT_CAPACITY + 1,
197
+ timestampRange: {
198
+ startAt: (0, stubs_1.firestoreTimestampStub)({
199
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
200
+ }),
201
+ endAt: (0, stubs_1.firestoreTimestampStub)({
202
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
203
+ }),
204
+ },
205
+ };
206
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(zeroCap)).toBe(false);
207
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(negCap)).toBe(false);
208
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(floatCap)).toBe(false);
209
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(tooBigCap)).toBe(false);
210
+ });
211
+ it("return false if startAt or endAt does not have toMillis()", () => {
212
+ const badStart = {
213
+ ...baseValidSlot,
214
+ timestampRange: {
215
+ startAt: { toMillis: undefined },
216
+ endAt: (0, stubs_1.firestoreTimestampStub)({
217
+ toMillis: () => 1,
218
+ }),
219
+ },
220
+ };
221
+ const badEnd = {
222
+ ...baseValidSlot,
223
+ timestampRange: {
224
+ startAt: (0, stubs_1.firestoreTimestampStub)({
225
+ toMillis: () => 0,
226
+ }),
227
+ endAt: { toMillis: undefined },
228
+ },
229
+ };
230
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(badStart)).toBe(false);
231
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(badEnd)).toBe(false);
232
+ });
233
+ it("return false if startAt ≥ endAt", () => {
234
+ const equalTimes = {
235
+ ...baseValidSlot,
236
+ timestampRange: {
237
+ startAt: (0, stubs_1.firestoreTimestampStub)({
238
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
239
+ }),
240
+ endAt: (0, stubs_1.firestoreTimestampStub)({
241
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
242
+ }),
243
+ },
244
+ };
245
+ const backwards = {
246
+ ...baseValidSlot,
247
+ timestampRange: {
248
+ startAt: (0, stubs_1.firestoreTimestampStub)({
249
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS * 2,
250
+ }),
251
+ endAt: (0, stubs_1.firestoreTimestampStub)({
252
+ toMillis: () => new Date().getTime() + constants_1.ONE_HOUR_IN_MS,
253
+ }),
254
+ },
255
+ };
256
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(equalTimes)).toBe(false);
257
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(backwards)).toBe(false);
258
+ });
259
+ it("return false if startAt is in the past", () => {
260
+ const pastStart = {
261
+ ...baseValidSlot,
262
+ timestampRange: {
263
+ startAt: (0, stubs_1.firestoreTimestampStub)({
264
+ toMillis: () => new Date().getTime() - constants_1.ONE_HOUR_IN_MS,
265
+ }),
266
+ endAt: (0, stubs_1.firestoreTimestampStub)({
267
+ toMillis: () => Date.now() + constants_1.ONE_HOUR_IN_MS,
268
+ }),
269
+ },
270
+ };
271
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(pastStart)).toBe(false);
272
+ });
273
+ it("return false if endAt is more than MAX_ year in the future", () => {
274
+ const farFuture = {
275
+ ...baseValidSlot,
276
+ timestampRange: {
277
+ startAt: (0, stubs_1.firestoreTimestampStub)({
278
+ toMillis: () => Date.now(),
279
+ }),
280
+ endAt: (0, stubs_1.firestoreTimestampStub)({
281
+ toMillis: () => Date.now() + constants_3.MAX_SLOT_END_DATE_IN_MS + constants_1.ONE_DAY_IN_MS,
282
+ }),
283
+ },
284
+ };
285
+ expect((0, isValidOneTimeSlot_1.isValidOneTimeSlot)(farFuture)).toBe(false);
286
+ });
287
+ });