|
@@ -26,6 +26,8 @@ vi.mock('@/features/inspection-reminders/Lib/booking', async (importOriginal) =>
|
|
|
const db = vi.hoisted(() => ({
|
|
const db = vi.hoisted(() => ({
|
|
|
// The job number query: nothing yet in the workshop's format.
|
|
// The job number query: nothing yet in the workshop's format.
|
|
|
$queryRaw: async () => [],
|
|
$queryRaw: async () => [],
|
|
|
|
|
+ // The lock that makes sends of one booking take turns.
|
|
|
|
|
+ $executeRaw: vi.fn(),
|
|
|
user: { findUnique: vi.fn() },
|
|
user: { findUnique: vi.fn() },
|
|
|
auditLog: { create: vi.fn() },
|
|
auditLog: { create: vi.fn() },
|
|
|
vehicle: { findFirst: vi.fn() },
|
|
vehicle: { findFirst: vi.fn() },
|
|
@@ -42,13 +44,15 @@ const db = vi.hoisted(() => ({
|
|
|
}))
|
|
}))
|
|
|
vi.mock('@/lib/db', () => ({ db }))
|
|
vi.mock('@/lib/db', () => ({ db }))
|
|
|
|
|
|
|
|
-import { createBooking } from '@/features/calendar/Actions/createBooking'
|
|
|
|
|
|
|
+import { createBookingOnce } from '@/features/calendar/Actions/createBooking'
|
|
|
import { updateBooking } from '@/features/calendar/Actions/updateBooking'
|
|
import { updateBooking } from '@/features/calendar/Actions/updateBooking'
|
|
|
import { deleteAppointment } from '@/features/calendar/Actions/deleteAppointment'
|
|
import { deleteAppointment } from '@/features/calendar/Actions/deleteAppointment'
|
|
|
import type { SaveBookingInput } from '@/features/calendar/Schema/bookingSchema'
|
|
import type { SaveBookingInput } from '@/features/calendar/Schema/bookingSchema'
|
|
|
|
|
|
|
|
const ORG = 'org-1'
|
|
const ORG = 'org-1'
|
|
|
const USER = 'user-1'
|
|
const USER = 'user-1'
|
|
|
|
|
+/** What one opened booking dialog sends with whatever it books. */
|
|
|
|
|
+const TOKEN = 'a3f1c2d4e5f60718293a4b5c6d7e8f90'
|
|
|
|
|
|
|
|
function signInAs(
|
|
function signInAs(
|
|
|
role: 'owner' | 'member' = 'owner',
|
|
role: 'owner' | 'member' = 'owner',
|
|
@@ -81,7 +85,11 @@ beforeEach(() => {
|
|
|
})
|
|
})
|
|
|
db.customer.findFirst.mockResolvedValue({ id: 'cust-1', taxExempt: false })
|
|
db.customer.findFirst.mockResolvedValue({ id: 'cust-1', taxExempt: false })
|
|
|
// The newest numbered job, for the next job number.
|
|
// The newest numbered job, for the next job number.
|
|
|
- db.serviceRecord.findFirst.mockResolvedValue({ invoiceNumber: '2026-1043' })
|
|
|
|
|
|
|
+ // And nothing booked with this dialog's token yet.
|
|
|
|
|
+ db.serviceRecord.findFirst.mockImplementation(
|
|
|
|
|
+ async (args?: { where?: { bookingToken?: string } }) =>
|
|
|
|
|
+ args?.where?.bookingToken ? null : { invoiceNumber: '2026-1043' }
|
|
|
|
|
+ )
|
|
|
db.serviceRecord.create.mockResolvedValue({ id: 'job-1' })
|
|
db.serviceRecord.create.mockResolvedValue({ id: 'job-1' })
|
|
|
db.serviceRecord.update.mockResolvedValue({
|
|
db.serviceRecord.update.mockResolvedValue({
|
|
|
id: 'job-1',
|
|
id: 'job-1',
|
|
@@ -107,6 +115,7 @@ beforeEach(() => {
|
|
|
function booking(overrides: Partial<SaveBookingInput> = {}): SaveBookingInput {
|
|
function booking(overrides: Partial<SaveBookingInput> = {}): SaveBookingInput {
|
|
|
return {
|
|
return {
|
|
|
kind: 'appointment',
|
|
kind: 'appointment',
|
|
|
|
|
+ token: TOKEN,
|
|
|
title: 'Call Kari',
|
|
title: 'Call Kari',
|
|
|
startDate: '2026-11-16',
|
|
startDate: '2026-11-16',
|
|
|
startTime: '09:30',
|
|
startTime: '09:30',
|
|
@@ -117,6 +126,14 @@ function booking(overrides: Partial<SaveBookingInput> = {}): SaveBookingInput {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/** The appointment a lookup by id finds; none is found by this dialog's token. */
|
|
|
|
|
+function appointmentOnFile(appointment: { id: string }) {
|
|
|
|
|
+ db.appointment.findFirst.mockImplementation(
|
|
|
|
|
+ async (args?: { where?: { bookingToken?: string } }) =>
|
|
|
|
|
+ args?.where?.bookingToken ? null : appointment
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/** Something already on the calendar on Monday, 08:00 to 10:00 UTC. */
|
|
/** Something already on the calendar on Monday, 08:00 to 10:00 UTC. */
|
|
|
function held(resource: { workBayId?: string; technicianId?: string }, id = 'other-job') {
|
|
function held(resource: { workBayId?: string; technicianId?: string }, id = 'other-job') {
|
|
|
return {
|
|
return {
|
|
@@ -136,7 +153,7 @@ const createdNotifications = () => db.appointmentNotification.createMany.mock.ca
|
|
|
|
|
|
|
|
describe('createBooking: an appointment', () => {
|
|
describe('createBooking: an appointment', () => {
|
|
|
it("puts it on the workshop's clock with its title, description, customer and notifications", async () => {
|
|
it("puts it on the workshop's clock with its title, description, customer and notifications", async () => {
|
|
|
- const result = await createBooking(
|
|
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
booking({
|
|
booking({
|
|
|
vehicleId: 'veh-1',
|
|
vehicleId: 'veh-1',
|
|
|
description: '<p>Bring the <strong>spare key</strong></p><script>alert(1)</script>',
|
|
description: '<p>Bring the <strong>spare key</strong></p><script>alert(1)</script>',
|
|
@@ -192,14 +209,14 @@ describe('createBooking: an appointment', () => {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('keeps no description that says nothing', async () => {
|
|
it('keeps no description that says nothing', async () => {
|
|
|
- await createBooking(booking({ description: '<p> </p>' }))
|
|
|
|
|
|
|
+ await createBookingOnce(booking({ description: '<p> </p>' }))
|
|
|
expect(appointmentData().description).toBeNull()
|
|
expect(appointmentData().description).toBeNull()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it("refuses another workshop's car and creates nothing", async () => {
|
|
it("refuses another workshop's car and creates nothing", async () => {
|
|
|
db.vehicle.findFirst.mockResolvedValue(null)
|
|
db.vehicle.findFirst.mockResolvedValue(null)
|
|
|
|
|
|
|
|
- const result = await createBooking(booking({ vehicleId: 'someone-elses-car' }))
|
|
|
|
|
|
|
+ const result = await createBookingOnce(booking({ vehicleId: 'someone-elses-car' }))
|
|
|
|
|
|
|
|
expect(result.success).toBe(false)
|
|
expect(result.success).toBe(false)
|
|
|
expect(result.error).toBe('Vehicle not found')
|
|
expect(result.error).toBe('Vehicle not found')
|
|
@@ -209,7 +226,7 @@ describe('createBooking: an appointment', () => {
|
|
|
|
|
|
|
|
describe('createBooking: a work order', () => {
|
|
describe('createBooking: a work order', () => {
|
|
|
it('needs a car or a customer, and writes nothing without one', async () => {
|
|
it('needs a car or a customer, and writes nothing without one', async () => {
|
|
|
- const result = await createBooking(booking({ kind: 'workOrder', work: 'Brakes' }))
|
|
|
|
|
|
|
+ const result = await createBookingOnce(booking({ kind: 'workOrder', work: 'Brakes' }))
|
|
|
|
|
|
|
|
expect(result.success).toBe(false)
|
|
expect(result.success).toBe(false)
|
|
|
expect(db.serviceRecord.create).not.toHaveBeenCalled()
|
|
expect(db.serviceRecord.create).not.toHaveBeenCalled()
|
|
@@ -225,7 +242,7 @@ describe('createBooking: a work order', () => {
|
|
|
closuresEnabled: false,
|
|
closuresEnabled: false,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- const result = await createBooking(
|
|
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
booking({
|
|
booking({
|
|
|
kind: 'workOrder',
|
|
kind: 'workOrder',
|
|
|
title: 'Brake job',
|
|
title: 'Brake job',
|
|
@@ -242,6 +259,7 @@ describe('createBooking: a work order', () => {
|
|
|
ref: '2026-1044',
|
|
ref: '2026-1044',
|
|
|
vehicleId: 'veh-1',
|
|
vehicleId: 'veh-1',
|
|
|
overbooked: false,
|
|
overbooked: false,
|
|
|
|
|
+ repeated: false,
|
|
|
})
|
|
})
|
|
|
const job = jobData()
|
|
const job = jobData()
|
|
|
expect(job.organizationId).toBe(ORG)
|
|
expect(job.organizationId).toBe(ORG)
|
|
@@ -271,7 +289,7 @@ describe('createBooking: a work order', () => {
|
|
|
it('makes the title the only concern when no work lines are given', async () => {
|
|
it('makes the title the only concern when no work lines are given', async () => {
|
|
|
db.vehicle.findFirst.mockResolvedValue(null)
|
|
db.vehicle.findFirst.mockResolvedValue(null)
|
|
|
|
|
|
|
|
- const result = await createBooking(
|
|
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
booking({ kind: 'workOrder', title: 'Winter tyres on', customerId: 'cust-1' })
|
|
booking({ kind: 'workOrder', title: 'Winter tyres on', customerId: 'cust-1' })
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -291,7 +309,7 @@ describe('createBooking: a work order', () => {
|
|
|
closuresEnabled: false,
|
|
closuresEnabled: false,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- const result = await createBooking(
|
|
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
booking({ kind: 'workOrder', vehicleId: 'veh-1', work: 'Service' })
|
|
booking({ kind: 'workOrder', vehicleId: 'veh-1', work: 'Service' })
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -303,9 +321,9 @@ describe('createBooking: a work order', () => {
|
|
|
|
|
|
|
|
describe('createBooking: an appointment made a work order', () => {
|
|
describe('createBooking: an appointment made a work order', () => {
|
|
|
it('books the job and takes the appointment off the calendar', async () => {
|
|
it('books the job and takes the appointment off the calendar', async () => {
|
|
|
- db.appointment.findFirst.mockResolvedValue({ id: 'appt-1' })
|
|
|
|
|
|
|
+ appointmentOnFile({ id: 'appt-1' })
|
|
|
|
|
|
|
|
- const result = await createBooking(
|
|
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
booking({
|
|
booking({
|
|
|
kind: 'workOrder',
|
|
kind: 'workOrder',
|
|
|
vehicleId: 'veh-1',
|
|
vehicleId: 'veh-1',
|
|
@@ -325,7 +343,7 @@ describe('createBooking: an appointment made a work order', () => {
|
|
|
it("refuses another workshop's appointment and creates nothing", async () => {
|
|
it("refuses another workshop's appointment and creates nothing", async () => {
|
|
|
db.appointment.findFirst.mockResolvedValue(null)
|
|
db.appointment.findFirst.mockResolvedValue(null)
|
|
|
|
|
|
|
|
- const result = await createBooking(
|
|
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
booking({
|
|
booking({
|
|
|
kind: 'workOrder',
|
|
kind: 'workOrder',
|
|
|
vehicleId: 'veh-1',
|
|
vehicleId: 'veh-1',
|
|
@@ -341,9 +359,177 @@ describe('createBooking: an appointment made a work order', () => {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+describe('the same booking sent twice', () => {
|
|
|
|
|
+ /** What a lookup by the token finds once the first send has booked. */
|
|
|
|
|
+ function alreadyBooked(found: {
|
|
|
|
|
+ job?: { id: string; vehicleId: string | null; invoiceNumber: string | null }
|
|
|
|
|
+ appointment?: { id: string; title: string; vehicleId: string | null }
|
|
|
|
|
+ }) {
|
|
|
|
|
+ db.serviceRecord.findFirst.mockImplementation(
|
|
|
|
|
+ async (args?: { where?: { bookingToken?: string } }) =>
|
|
|
|
|
+ args?.where?.bookingToken ? (found.job ?? null) : { invoiceNumber: '2026-1044' }
|
|
|
|
|
+ )
|
|
|
|
|
+ db.appointment.findFirst.mockImplementation(
|
|
|
|
|
+ async (args?: { where?: { bookingToken?: string } }) =>
|
|
|
|
|
+ args?.where?.bookingToken ? (found.appointment ?? null) : null
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ it('keeps the token on the job it books', async () => {
|
|
|
|
|
+ const result = await createBookingOnce(booking({ kind: 'workOrder', vehicleId: 'veh-1' }))
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(true)
|
|
|
|
|
+ expect(jobUpdate().data.bookingToken).toBe(TOKEN)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('keeps the token on the appointment it books', async () => {
|
|
|
|
|
+ await createBookingOnce(booking())
|
|
|
|
|
+
|
|
|
|
|
+ expect(appointmentData().bookingToken).toBe(TOKEN)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('answers with the job already booked and books no second one', async () => {
|
|
|
|
|
+ alreadyBooked({ job: { id: 'job-1', vehicleId: 'veh-1', invoiceNumber: '2026-1044' } })
|
|
|
|
|
+
|
|
|
|
|
+ const result = await createBookingOnce(booking({ kind: 'workOrder', vehicleId: 'veh-1' }))
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(true)
|
|
|
|
|
+ expect(result.data).toMatchObject({ kind: 'workOrder', id: 'job-1', ref: '2026-1044' })
|
|
|
|
|
+ expect(db.serviceRecord.findFirst).toHaveBeenCalledWith(
|
|
|
|
|
+ expect.objectContaining({ where: { organizationId: ORG, bookingToken: TOKEN } })
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(db.serviceRecord.create).not.toHaveBeenCalled()
|
|
|
|
|
+ expect(db.appointment.create).not.toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('answers with the appointment already booked and books no second one', async () => {
|
|
|
|
|
+ alreadyBooked({ appointment: { id: 'appt-1', title: 'Call Kari', vehicleId: null } })
|
|
|
|
|
+
|
|
|
|
|
+ const result = await createBookingOnce(booking())
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(true)
|
|
|
|
|
+ expect(result.data).toMatchObject({ kind: 'appointment', id: 'appt-1', ref: 'Call Kari' })
|
|
|
|
|
+ expect(db.appointment.findFirst).toHaveBeenCalledWith(
|
|
|
|
|
+ expect.objectContaining({ where: { organizationId: ORG, bookingToken: TOKEN } })
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(db.appointment.create).not.toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('does not write the booking into the audit log a second time', async () => {
|
|
|
|
|
+ alreadyBooked({ job: { id: 'job-1', vehicleId: 'veh-1', invoiceNumber: '2026-1044' } })
|
|
|
|
|
+
|
|
|
|
|
+ await createBookingOnce(booking({ kind: 'workOrder', vehicleId: 'veh-1' }))
|
|
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, 20))
|
|
|
|
|
+
|
|
|
|
|
+ expect(db.auditLog.create).not.toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('finds the job when the appointment it was made from is already gone', async () => {
|
|
|
|
|
+ // The first send made the work order and removed the appointment.
|
|
|
|
|
+ alreadyBooked({ job: { id: 'job-1', vehicleId: 'veh-1', invoiceNumber: '2026-1044' } })
|
|
|
|
|
+
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
|
|
+ booking({ kind: 'workOrder', vehicleId: 'veh-1', fromAppointmentId: 'appt-1' })
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(true)
|
|
|
|
|
+ expect(result.data?.id).toBe('job-1')
|
|
|
|
|
+ expect(db.serviceRecord.create).not.toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('waits its turn and books nothing when the first send finishes meanwhile', async () => {
|
|
|
|
|
+ // Nothing booked when this send first looks. By the time it holds the
|
|
|
|
|
+ // lock the other send has finished, as either kind.
|
|
|
|
|
+ let turn = false
|
|
|
|
|
+ db.$executeRaw.mockImplementation(async () => {
|
|
|
|
|
+ turn = true
|
|
|
|
|
+ return 1
|
|
|
|
|
+ })
|
|
|
|
|
+ db.serviceRecord.findFirst.mockImplementation(
|
|
|
|
|
+ async (args?: { where?: { bookingToken?: string } }) =>
|
|
|
|
|
+ args?.where?.bookingToken ? null : { invoiceNumber: '2026-1043' }
|
|
|
|
|
+ )
|
|
|
|
|
+ db.appointment.findFirst.mockImplementation(
|
|
|
|
|
+ async (args?: { where?: { bookingToken?: string } }) =>
|
|
|
|
|
+ args?.where?.bookingToken && turn
|
|
|
|
|
+ ? { id: 'appt-first', title: 'Call Kari', vehicleId: null }
|
|
|
|
|
+ : null
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ const result = await createBookingOnce(booking({ kind: 'workOrder', vehicleId: 'veh-1' }))
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(true)
|
|
|
|
|
+ expect(result.data).toMatchObject({ kind: 'appointment', id: 'appt-first' })
|
|
|
|
|
+ expect(db.$executeRaw).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(db.serviceRecord.create).not.toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('finds the job when the appointment goes between its two lookups', async () => {
|
|
|
|
|
+ // Not booked at the first look; the first send then commits, taking the
|
|
|
|
|
+ // appointment with it, before this one looks the appointment up.
|
|
|
|
|
+ let looks = 0
|
|
|
|
|
+ db.serviceRecord.findFirst.mockImplementation(
|
|
|
|
|
+ async (args?: { where?: { bookingToken?: string } }) => {
|
|
|
|
|
+ if (!args?.where?.bookingToken) return { invoiceNumber: '2026-1043' }
|
|
|
|
|
+ looks += 1
|
|
|
|
|
+ return looks > 1 ? { id: 'job-1', vehicleId: 'veh-1', invoiceNumber: '2026-1044' } : null
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ db.appointment.findFirst.mockResolvedValue(null)
|
|
|
|
|
+
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
|
|
+ booking({ kind: 'workOrder', vehicleId: 'veh-1', fromAppointmentId: 'appt-1' })
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(true)
|
|
|
|
|
+ expect(result.data?.id).toBe('job-1')
|
|
|
|
|
+ expect(db.serviceRecord.create).not.toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("answers with the other send's job when both arrive together", async () => {
|
|
|
|
|
+ // Nothing booked when this send looks; the other one commits first and
|
|
|
|
|
+ // the database refuses this one the token.
|
|
|
|
|
+ let committed = false
|
|
|
|
|
+ db.serviceRecord.findFirst.mockImplementation(
|
|
|
|
|
+ async (args?: { where?: { bookingToken?: string } }) =>
|
|
|
|
|
+ args?.where?.bookingToken
|
|
|
|
|
+ ? committed
|
|
|
|
|
+ ? { id: 'job-first', vehicleId: 'veh-1', invoiceNumber: '2026-1044' }
|
|
|
|
|
+ : null
|
|
|
|
|
+ : { invoiceNumber: '2026-1043' }
|
|
|
|
|
+ )
|
|
|
|
|
+ db.serviceRecord.update.mockImplementation(async () => {
|
|
|
|
|
+ committed = true
|
|
|
|
|
+ throw Object.assign(new Error('Unique constraint failed'), { code: 'P2002' })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const result = await createBookingOnce(booking({ kind: 'workOrder', vehicleId: 'veh-1' }))
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(true)
|
|
|
|
|
+ expect(result.data).toMatchObject({ kind: 'workOrder', id: 'job-first', ref: '2026-1044' })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('still fails when the database refuses it for another reason', async () => {
|
|
|
|
|
+ db.serviceRecord.update.mockRejectedValue(
|
|
|
|
|
+ Object.assign(new Error('Unique constraint failed'), { code: 'P2002' })
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ const result = await createBookingOnce(booking({ kind: 'workOrder', vehicleId: 'veh-1' }))
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(false)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('refuses a booking sent without a token', async () => {
|
|
|
|
|
+ const result = await createBookingOnce(booking({ token: undefined }))
|
|
|
|
|
+
|
|
|
|
|
+ expect(result.success).toBe(false)
|
|
|
|
|
+ expect(db.appointment.create).not.toHaveBeenCalled()
|
|
|
|
|
+ })
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
describe('notifications to the customer', () => {
|
|
describe('notifications to the customer', () => {
|
|
|
it('need somebody to go to', async () => {
|
|
it('need somebody to go to', async () => {
|
|
|
- const result = await createBooking(
|
|
|
|
|
|
|
+ const result = await createBookingOnce(
|
|
|
booking({ notifications: [{ channel: 'customer_sms', amount: 1, unit: 'days' }] })
|
|
booking({ notifications: [{ channel: 'customer_sms', amount: 1, unit: 'days' }] })
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -354,7 +540,7 @@ describe('notifications to the customer', () => {
|
|
|
it('are refused on the demo, while a notice in the app is not', async () => {
|
|
it('are refused on the demo, while a notice in the app is not', async () => {
|
|
|
vi.stubEnv('DEMO_MODE', 'true')
|
|
vi.stubEnv('DEMO_MODE', 'true')
|
|
|
vi.resetModules()
|
|
vi.resetModules()
|
|
|
- const { createBooking: demoCreateBooking } = await import(
|
|
|
|
|
|
|
+ const { createBookingOnce: demoCreateBooking } = await import(
|
|
|
'@/features/calendar/Actions/createBooking'
|
|
'@/features/calendar/Actions/createBooking'
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -679,7 +865,7 @@ describe('who may book', () => {
|
|
|
it('refuses a role that may not create jobs', async () => {
|
|
it('refuses a role that may not create jobs', async () => {
|
|
|
signInAs('member', [{ action: 'read', subject: 'services' }])
|
|
signInAs('member', [{ action: 'read', subject: 'services' }])
|
|
|
|
|
|
|
|
- const result = await createBooking(booking())
|
|
|
|
|
|
|
+ const result = await createBookingOnce(booking())
|
|
|
|
|
|
|
|
expect(result.success).toBe(false)
|
|
expect(result.success).toBe(false)
|
|
|
expect(result.forbidden).toBe(true)
|
|
expect(result.forbidden).toBe(true)
|
|
@@ -689,7 +875,7 @@ describe('who may book', () => {
|
|
|
it('lets a role that may create jobs book', async () => {
|
|
it('lets a role that may create jobs book', async () => {
|
|
|
signInAs('member', [{ action: 'create', subject: 'services' }])
|
|
signInAs('member', [{ action: 'create', subject: 'services' }])
|
|
|
|
|
|
|
|
- const result = await createBooking(booking())
|
|
|
|
|
|
|
+ const result = await createBookingOnce(booking())
|
|
|
|
|
|
|
|
expect(result.success).toBe(true)
|
|
expect(result.success).toBe(true)
|
|
|
expect(db.appointment.create).toHaveBeenCalledTimes(1)
|
|
expect(db.appointment.create).toHaveBeenCalledTimes(1)
|