user = User::factory()->create(); $this->location = Location::factory()->create(['name' => 'Test Location', 'label' => 'downtown']); $this->team = Team::factory()->create(['owner_id' => $this->user->id, 'location_id' => $this->location->id]); $this->team->customSubscription()->updateOrCreate([ 'credit' => 1000, 'additional_monthly_credit' => 100, 'rollover_credit' => 100, 'gets_member_rate' => true, ]); $this->user->teams()->attach($this->team, ['role' => 'owner']); $this->user->current_team_id = $this->team->id; $this->user->save(); $this->actingAs($this->user); Config::set('mill.send-webhook-url', 'https://example.com/webhook'); Config::set('mill.send-webhook-secret', 'test-secret'); // Capture Laravel logs to STDERR \Illuminate\Support\Facades\Log::listen(function ($msg) { fwrite(STDERR, '[Log] '.$msg->message."\n"); }); }); test('webhook is dispatched when creating reservation for rentable with webhook enabled', function () { $this->withoutExceptionHandling(); Mail::fake(); Queue::fake(); $rentable = Rentable::factory()->create([ 'send_webhook' => true, 'name' => 'Test Studio', 'google_calendar_id' => null, 'location_id' => $this->location->id, 'billing_period' => 60, // 1 hour billing period 'minimum_length' => 30, // 30 minute minimum 'member_rate' => 50.00, 'rate' => 75.00, 'open' => '09:00', 'close' => '17:00', ]); // Calculate the price based on the time difference $openHour = intval(substr($rentable->open, 0, 2)); $start = now()->addDay()->setHour($openHour)->setMinute(0)->setSecond(0); $end = $start->copy()->addHours(2); $length = $start->diffInMinutes($end); $price = $length * ($rentable->member_rate / $rentable->billing_period); $price = round($price, 2); // Create the reservation via Livewire $livewire = livewire(ReservationCreate::class) ->set('rentable', $rentable); // First set the location and rentable to trigger the component fill $livewire->fillForm([ 'location' => $this->location->id, ]); usleep(500000); $livewire->assertFormFieldIsHidden('date'); $livewire->fillForm([ 'rentable' => $rentable->id, ]); usleep(500000); // Add debug output to see what's happening fwrite(STDERR, '[Debug] Rentable data: '.json_encode($livewire->instance()->rentable)."\n"); fwrite(STDERR, '[Debug] Form data: '.json_encode($livewire->get('data'))."\n"); // Fill in the date $livewire->fillForm([ 'date' => $start->format('Y-m-d H:i:s'), ]); usleep(500000); // Then fill the rest of the form $livewire->fillForm([ 'start' => $start->format('Y-m-d H:i:s'), 'end' => $end->format('Y-m-d H:i:s'), 'credit' => min($price, $this->team->credit), ]); // Submit the form $livewire->call('submit'); $livewire->assertHasNoFormErrors(); // Assert a success notification was sent $livewire->assertNotified('You have successfully reserved '.$rentable->name); // Assert the webhook job was queued Queue::assertPushed(CallWebhookJob::class); }); test('webhook is not dispatched when creating reservation for rentable without webhook', function () { Queue::fake(); $rentable = Rentable::factory()->create([ 'send_webhook' => false, 'name' => 'Test Studio', 'google_calendar_id' => null, 'location_id' => $this->location->id, 'billing_period' => 60, // 1 hour billing period 'minimum_length' => 30, // 30 minute minimum 'member_rate' => 50.00, 'rate' => 75.00, 'open' => '09:00', 'close' => '17:00', ]); // Calculate the price based on the time difference $openHour = intval(substr($rentable->open, 0, 2)); $start = now()->addDay()->setHour($openHour)->setMinute(0)->setSecond(0); $end = $start->copy()->addHours(2); $length = $start->diffInMinutes($end); $price = $length * ($rentable->member_rate / $rentable->billing_period); $price = round($price, 2); // Create the reservation via Livewire $livewire = livewire(ReservationCreate::class) ->set('rentable', $rentable); // First set the location and rentable to trigger the component fill $livewire->fillForm([ 'location' => $this->location->id, 'rentable' => $rentable->id, ]); // File in the date $livewire->fillForm([ 'date' => $start->format('Y-m-d H:i:s'), ]); // Then fill the rest of the form $livewire->fillForm([ 'start' => $start->format('Y-m-d H:i:s'), 'end' => $end->format('Y-m-d H:i:s'), 'credit' => min($price, $this->team->credit), ]); // Submit the form $livewire->call('submit') ->assertHasNoFormErrors(); // Assert no webhook job was queued Queue::assertNotPushed(CallWebhookJob::class); });