@wix/headless-bookings 0.0.44 → 0.0.45

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,9 +1,14 @@
1
- /**
2
- * Shared mock data for booking service tests
3
- */
4
1
  import type { Resource } from '@wix/auto_sdk_bookings_availability-time-slots';
5
2
  import type { FormValues } from '@wix/form-public';
6
- import type { ServiceSelection, ServiceSelectionTimeSlot, BookingServiceConfig } from '../services/booking/booking.js';
3
+ import type { ServiceSelection, ServiceSelectionTimeSlot, BookingServiceConfig, BookingService } from '../services/booking/booking.js';
4
+ import type { Signal } from '@wix/services-definitions/core-services/signals';
5
+ export declare function mockSignal<T>(initialValue: T): Signal<T>;
6
+ export declare function createMockSignalsService(): {
7
+ signal: typeof mockSignal;
8
+ computed: <T>(fn: () => T) => Signal<T>;
9
+ effect: (fn: () => void) => void;
10
+ };
11
+ export declare function createMockBookingService(initialSelections?: ServiceSelection[]): BookingService;
7
12
  /**
8
13
  * Mock resource (staff member)
9
14
  */
@@ -1,7 +1,52 @@
1
- /**
2
- * Shared mock data for booking service tests
3
- */
4
1
  import { mockService, mockServiceClass } from './services.js';
2
+ import { vi } from 'vitest';
3
+ export function mockSignal(initialValue) {
4
+ let value = initialValue;
5
+ return {
6
+ get: () => value,
7
+ peek: () => value,
8
+ set: (newValue) => {
9
+ value = newValue;
10
+ },
11
+ };
12
+ }
13
+ export function createMockSignalsService() {
14
+ return {
15
+ signal: mockSignal,
16
+ computed: (fn) => mockSignal(fn()),
17
+ effect: vi.fn((fn) => {
18
+ fn();
19
+ }),
20
+ };
21
+ }
22
+ export function createMockBookingService(initialSelections = []) {
23
+ const serviceSelectionsSignal = mockSignal(initialSelections);
24
+ const locationSignal = mockSignal(null);
25
+ const timezoneSignal = mockSignal('UTC');
26
+ const formSubmissionSignal = mockSignal(null);
27
+ return {
28
+ serviceSelections: serviceSelectionsSignal,
29
+ location: locationSignal,
30
+ timezone: timezoneSignal,
31
+ formSubmission: formSubmissionSignal,
32
+ actions: {
33
+ updateItem: vi.fn(),
34
+ setItem: vi.fn(),
35
+ addItem: vi.fn(),
36
+ removeItem: vi.fn(),
37
+ clearItems: vi.fn(),
38
+ setResourceById: vi.fn(),
39
+ getResourceById: vi.fn(),
40
+ setLocation: vi.fn(),
41
+ clearLocation: vi.fn(),
42
+ setTimezone: vi.fn(),
43
+ setFormSubmission: vi.fn(),
44
+ clearFormSubmission: vi.fn(),
45
+ clearAll: vi.fn(),
46
+ book: vi.fn(),
47
+ },
48
+ };
49
+ }
5
50
  /**
6
51
  * Mock resource (staff member)
7
52
  */
@@ -0,0 +1,28 @@
1
+ import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
2
+ import type { TimeSlotListServiceConfig, TimeSlotListServiceAPI } from '../services/time-slot-list/time-slot-list.def.js';
3
+ import type { BookingService } from '../services/booking/booking.js';
4
+ export declare function createTimeSlotListService(overrides?: Partial<TimeSlotListServiceConfig>): {
5
+ service: TimeSlotListServiceAPI;
6
+ bookingService: BookingService;
7
+ };
8
+ export declare function createTimeSlot(overrides?: Partial<TimeSlot>): TimeSlot;
9
+ export declare function createTimeSlots(count: number): TimeSlot[];
10
+ export declare function createTimeSlotListConfig(overrides?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceConfig;
11
+ export declare const mockTimeSlot: TimeSlot;
12
+ export declare const mockTimeSlotMultipleStaff: TimeSlot;
13
+ export declare const mockTimeSlotNotBookable: TimeSlot;
14
+ export declare const mockTimeSlots: TimeSlot[];
15
+ export declare const mockStartDate: Date;
16
+ export declare const mockEndDate: Date;
17
+ export declare const mockTimezone = "America/New_York";
18
+ export declare const mockTimeSlotListConfig: TimeSlotListServiceConfig;
19
+ export declare const mockEmptyTimeSlotListConfig: TimeSlotListServiceConfig;
20
+ export declare const mockCursorPagingMetadataWithMore: {
21
+ cursors: {
22
+ next: string;
23
+ };
24
+ };
25
+ export declare const mockCursorPagingMetadataNoMore: {
26
+ cursors: {};
27
+ };
28
+ export declare function createMockTimeSlotListService(config?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceAPI;
@@ -0,0 +1,116 @@
1
+ import { vi } from 'vitest';
2
+ import { TimeSlotListService } from '../services/time-slot-list/time-slot-list.js';
3
+ import { createMockBookingService, createMockSignalsService, mockSignal, } from './booking.js';
4
+ export function createTimeSlotListService(overrides = {}) {
5
+ const config = createTimeSlotListConfig(overrides);
6
+ const mockBookingService = createMockBookingService();
7
+ const mockSignalsService = createMockSignalsService();
8
+ const getService = (definition) => {
9
+ const def = definition;
10
+ if (def.name === 'signals') {
11
+ return mockSignalsService;
12
+ }
13
+ if (def.name === 'booking') {
14
+ return mockBookingService;
15
+ }
16
+ throw new Error(`Unknown service: ${def.name}`);
17
+ };
18
+ const service = TimeSlotListService({
19
+ getService,
20
+ config,
21
+ });
22
+ return {
23
+ service,
24
+ bookingService: mockBookingService,
25
+ };
26
+ }
27
+ export function createTimeSlot(overrides = {}) {
28
+ return {
29
+ localStartDate: '2024-01-15T10:00:00',
30
+ localEndDate: '2024-01-15T11:00:00',
31
+ bookable: true,
32
+ totalCapacity: 10,
33
+ remainingCapacity: 5,
34
+ scheduleId: 'schedule-1',
35
+ location: { _id: 'loc-1', name: 'Main Office' },
36
+ availableResources: [{ resources: [{ _id: 'staff-1', name: 'John Doe' }] }],
37
+ ...overrides,
38
+ };
39
+ }
40
+ export function createTimeSlots(count) {
41
+ return Array.from({ length: count }, (_, i) => createTimeSlot({
42
+ localStartDate: `2024-01-15T${String(9 + (i % 8)).padStart(2, '0')}:00:00`,
43
+ localEndDate: `2024-01-15T${String(10 + (i % 8)).padStart(2, '0')}:00:00`,
44
+ scheduleId: `schedule-${i}`,
45
+ }));
46
+ }
47
+ export function createTimeSlotListConfig(overrides = {}) {
48
+ const { startDate = new Date('2024-01-15T00:00:00'), endDate = new Date('2024-01-22T00:00:00'), timezone = 'America/New_York', timeSlots, ...rest } = overrides;
49
+ return {
50
+ startDate,
51
+ endDate,
52
+ timezone,
53
+ ...rest,
54
+ ...(timeSlots !== undefined ? { timeSlots } : {}),
55
+ };
56
+ }
57
+ export const mockTimeSlot = createTimeSlot();
58
+ export const mockTimeSlotMultipleStaff = createTimeSlot({
59
+ availableResources: [
60
+ {
61
+ resources: [
62
+ { _id: 'staff-1', name: 'John Doe' },
63
+ { _id: 'staff-2', name: 'Jane Smith' },
64
+ ],
65
+ },
66
+ ],
67
+ });
68
+ export const mockTimeSlotNotBookable = createTimeSlot({
69
+ localStartDate: '2024-01-15T14:00:00',
70
+ localEndDate: '2024-01-15T15:00:00',
71
+ bookable: false,
72
+ remainingCapacity: 0,
73
+ location: { _id: 'loc-2', name: 'Downtown Branch' },
74
+ });
75
+ export const mockTimeSlots = [
76
+ mockTimeSlot,
77
+ mockTimeSlotMultipleStaff,
78
+ mockTimeSlotNotBookable,
79
+ ];
80
+ export const mockStartDate = new Date('2024-01-15T00:00:00');
81
+ export const mockEndDate = new Date('2024-01-22T00:00:00');
82
+ export const mockTimezone = 'America/New_York';
83
+ export const mockTimeSlotListConfig = createTimeSlotListConfig({
84
+ timeSlots: mockTimeSlots,
85
+ });
86
+ export const mockEmptyTimeSlotListConfig = createTimeSlotListConfig();
87
+ export const mockCursorPagingMetadataWithMore = {
88
+ cursors: { next: 'next-cursor-token' },
89
+ };
90
+ export const mockCursorPagingMetadataNoMore = { cursors: {} };
91
+ export function createMockTimeSlotListService(config = {}) {
92
+ const timeSlotsSignal = mockSignal(config.timeSlots || []);
93
+ const isLoadingSignal = mockSignal(false);
94
+ const errorSignal = mockSignal(null);
95
+ const hasMoreSignal = mockSignal(false);
96
+ const dateRangeSignal = mockSignal({
97
+ start: config.startDate || mockStartDate,
98
+ end: config.endDate || mockEndDate,
99
+ });
100
+ return {
101
+ timeSlots: timeSlotsSignal,
102
+ isLoading: isLoadingSignal,
103
+ error: errorSignal,
104
+ hasMore: hasMoreSignal,
105
+ dateRange: dateRangeSignal,
106
+ actions: {
107
+ selectSlot: vi.fn(),
108
+ selectStaffMember: vi.fn(),
109
+ clearStaffSelection: vi.fn(),
110
+ loadMore: vi.fn(),
111
+ setDateRange: vi.fn((start, end) => {
112
+ dateRangeSignal.set({ start, end });
113
+ }),
114
+ },
115
+ };
116
+ }
@@ -1,9 +1,14 @@
1
- /**
2
- * Shared mock data for booking service tests
3
- */
4
1
  import type { Resource } from '@wix/auto_sdk_bookings_availability-time-slots';
5
2
  import type { FormValues } from '@wix/form-public';
6
- import type { ServiceSelection, ServiceSelectionTimeSlot, BookingServiceConfig } from '../services/booking/booking.js';
3
+ import type { ServiceSelection, ServiceSelectionTimeSlot, BookingServiceConfig, BookingService } from '../services/booking/booking.js';
4
+ import type { Signal } from '@wix/services-definitions/core-services/signals';
5
+ export declare function mockSignal<T>(initialValue: T): Signal<T>;
6
+ export declare function createMockSignalsService(): {
7
+ signal: typeof mockSignal;
8
+ computed: <T>(fn: () => T) => Signal<T>;
9
+ effect: (fn: () => void) => void;
10
+ };
11
+ export declare function createMockBookingService(initialSelections?: ServiceSelection[]): BookingService;
7
12
  /**
8
13
  * Mock resource (staff member)
9
14
  */
@@ -1,7 +1,52 @@
1
- /**
2
- * Shared mock data for booking service tests
3
- */
4
1
  import { mockService, mockServiceClass } from './services.js';
2
+ import { vi } from 'vitest';
3
+ export function mockSignal(initialValue) {
4
+ let value = initialValue;
5
+ return {
6
+ get: () => value,
7
+ peek: () => value,
8
+ set: (newValue) => {
9
+ value = newValue;
10
+ },
11
+ };
12
+ }
13
+ export function createMockSignalsService() {
14
+ return {
15
+ signal: mockSignal,
16
+ computed: (fn) => mockSignal(fn()),
17
+ effect: vi.fn((fn) => {
18
+ fn();
19
+ }),
20
+ };
21
+ }
22
+ export function createMockBookingService(initialSelections = []) {
23
+ const serviceSelectionsSignal = mockSignal(initialSelections);
24
+ const locationSignal = mockSignal(null);
25
+ const timezoneSignal = mockSignal('UTC');
26
+ const formSubmissionSignal = mockSignal(null);
27
+ return {
28
+ serviceSelections: serviceSelectionsSignal,
29
+ location: locationSignal,
30
+ timezone: timezoneSignal,
31
+ formSubmission: formSubmissionSignal,
32
+ actions: {
33
+ updateItem: vi.fn(),
34
+ setItem: vi.fn(),
35
+ addItem: vi.fn(),
36
+ removeItem: vi.fn(),
37
+ clearItems: vi.fn(),
38
+ setResourceById: vi.fn(),
39
+ getResourceById: vi.fn(),
40
+ setLocation: vi.fn(),
41
+ clearLocation: vi.fn(),
42
+ setTimezone: vi.fn(),
43
+ setFormSubmission: vi.fn(),
44
+ clearFormSubmission: vi.fn(),
45
+ clearAll: vi.fn(),
46
+ book: vi.fn(),
47
+ },
48
+ };
49
+ }
5
50
  /**
6
51
  * Mock resource (staff member)
7
52
  */
@@ -0,0 +1,28 @@
1
+ import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
2
+ import type { TimeSlotListServiceConfig, TimeSlotListServiceAPI } from '../services/time-slot-list/time-slot-list.def.js';
3
+ import type { BookingService } from '../services/booking/booking.js';
4
+ export declare function createTimeSlotListService(overrides?: Partial<TimeSlotListServiceConfig>): {
5
+ service: TimeSlotListServiceAPI;
6
+ bookingService: BookingService;
7
+ };
8
+ export declare function createTimeSlot(overrides?: Partial<TimeSlot>): TimeSlot;
9
+ export declare function createTimeSlots(count: number): TimeSlot[];
10
+ export declare function createTimeSlotListConfig(overrides?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceConfig;
11
+ export declare const mockTimeSlot: TimeSlot;
12
+ export declare const mockTimeSlotMultipleStaff: TimeSlot;
13
+ export declare const mockTimeSlotNotBookable: TimeSlot;
14
+ export declare const mockTimeSlots: TimeSlot[];
15
+ export declare const mockStartDate: Date;
16
+ export declare const mockEndDate: Date;
17
+ export declare const mockTimezone = "America/New_York";
18
+ export declare const mockTimeSlotListConfig: TimeSlotListServiceConfig;
19
+ export declare const mockEmptyTimeSlotListConfig: TimeSlotListServiceConfig;
20
+ export declare const mockCursorPagingMetadataWithMore: {
21
+ cursors: {
22
+ next: string;
23
+ };
24
+ };
25
+ export declare const mockCursorPagingMetadataNoMore: {
26
+ cursors: {};
27
+ };
28
+ export declare function createMockTimeSlotListService(config?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceAPI;
@@ -0,0 +1,116 @@
1
+ import { vi } from 'vitest';
2
+ import { TimeSlotListService } from '../services/time-slot-list/time-slot-list.js';
3
+ import { createMockBookingService, createMockSignalsService, mockSignal, } from './booking.js';
4
+ export function createTimeSlotListService(overrides = {}) {
5
+ const config = createTimeSlotListConfig(overrides);
6
+ const mockBookingService = createMockBookingService();
7
+ const mockSignalsService = createMockSignalsService();
8
+ const getService = (definition) => {
9
+ const def = definition;
10
+ if (def.name === 'signals') {
11
+ return mockSignalsService;
12
+ }
13
+ if (def.name === 'booking') {
14
+ return mockBookingService;
15
+ }
16
+ throw new Error(`Unknown service: ${def.name}`);
17
+ };
18
+ const service = TimeSlotListService({
19
+ getService,
20
+ config,
21
+ });
22
+ return {
23
+ service,
24
+ bookingService: mockBookingService,
25
+ };
26
+ }
27
+ export function createTimeSlot(overrides = {}) {
28
+ return {
29
+ localStartDate: '2024-01-15T10:00:00',
30
+ localEndDate: '2024-01-15T11:00:00',
31
+ bookable: true,
32
+ totalCapacity: 10,
33
+ remainingCapacity: 5,
34
+ scheduleId: 'schedule-1',
35
+ location: { _id: 'loc-1', name: 'Main Office' },
36
+ availableResources: [{ resources: [{ _id: 'staff-1', name: 'John Doe' }] }],
37
+ ...overrides,
38
+ };
39
+ }
40
+ export function createTimeSlots(count) {
41
+ return Array.from({ length: count }, (_, i) => createTimeSlot({
42
+ localStartDate: `2024-01-15T${String(9 + (i % 8)).padStart(2, '0')}:00:00`,
43
+ localEndDate: `2024-01-15T${String(10 + (i % 8)).padStart(2, '0')}:00:00`,
44
+ scheduleId: `schedule-${i}`,
45
+ }));
46
+ }
47
+ export function createTimeSlotListConfig(overrides = {}) {
48
+ const { startDate = new Date('2024-01-15T00:00:00'), endDate = new Date('2024-01-22T00:00:00'), timezone = 'America/New_York', timeSlots, ...rest } = overrides;
49
+ return {
50
+ startDate,
51
+ endDate,
52
+ timezone,
53
+ ...rest,
54
+ ...(timeSlots !== undefined ? { timeSlots } : {}),
55
+ };
56
+ }
57
+ export const mockTimeSlot = createTimeSlot();
58
+ export const mockTimeSlotMultipleStaff = createTimeSlot({
59
+ availableResources: [
60
+ {
61
+ resources: [
62
+ { _id: 'staff-1', name: 'John Doe' },
63
+ { _id: 'staff-2', name: 'Jane Smith' },
64
+ ],
65
+ },
66
+ ],
67
+ });
68
+ export const mockTimeSlotNotBookable = createTimeSlot({
69
+ localStartDate: '2024-01-15T14:00:00',
70
+ localEndDate: '2024-01-15T15:00:00',
71
+ bookable: false,
72
+ remainingCapacity: 0,
73
+ location: { _id: 'loc-2', name: 'Downtown Branch' },
74
+ });
75
+ export const mockTimeSlots = [
76
+ mockTimeSlot,
77
+ mockTimeSlotMultipleStaff,
78
+ mockTimeSlotNotBookable,
79
+ ];
80
+ export const mockStartDate = new Date('2024-01-15T00:00:00');
81
+ export const mockEndDate = new Date('2024-01-22T00:00:00');
82
+ export const mockTimezone = 'America/New_York';
83
+ export const mockTimeSlotListConfig = createTimeSlotListConfig({
84
+ timeSlots: mockTimeSlots,
85
+ });
86
+ export const mockEmptyTimeSlotListConfig = createTimeSlotListConfig();
87
+ export const mockCursorPagingMetadataWithMore = {
88
+ cursors: { next: 'next-cursor-token' },
89
+ };
90
+ export const mockCursorPagingMetadataNoMore = { cursors: {} };
91
+ export function createMockTimeSlotListService(config = {}) {
92
+ const timeSlotsSignal = mockSignal(config.timeSlots || []);
93
+ const isLoadingSignal = mockSignal(false);
94
+ const errorSignal = mockSignal(null);
95
+ const hasMoreSignal = mockSignal(false);
96
+ const dateRangeSignal = mockSignal({
97
+ start: config.startDate || mockStartDate,
98
+ end: config.endDate || mockEndDate,
99
+ });
100
+ return {
101
+ timeSlots: timeSlotsSignal,
102
+ isLoading: isLoadingSignal,
103
+ error: errorSignal,
104
+ hasMore: hasMoreSignal,
105
+ dateRange: dateRangeSignal,
106
+ actions: {
107
+ selectSlot: vi.fn(),
108
+ selectStaffMember: vi.fn(),
109
+ clearStaffSelection: vi.fn(),
110
+ loadMore: vi.fn(),
111
+ setDateRange: vi.fn((start, end) => {
112
+ dateRangeSignal.set({ start, end });
113
+ }),
114
+ },
115
+ };
116
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-bookings",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -72,5 +72,5 @@
72
72
  "groupId": "com.wixpress.headless-components"
73
73
  }
74
74
  },
75
- "falconPackageHash": "19b1f6d53395376a842a3c82dc37ea2471b330c496d10797ede1623e"
75
+ "falconPackageHash": "122a9bd0c5095741e936f6e76ab60fa20cb7c69c33763af1a38937c5"
76
76
  }