'https://aicommerce.test', 'storefront.domain' => 'shops.test']); $this->store = Store::factory()->for(User::factory())->create(['name' => 'Kedai Ali', 'slug' => 'kedai-ali', 'whatsapp_number' => '60123456789']); $plan = SamplePlan::for($this->store); $plan['theme']['colors']['primary'] = '#123456'; $plan['theme']['colors']['primaryForeground'] = '#FEDCBA'; $plan['theme']['fonts']['heading'] = 'fraunces'; $plan['theme']['radius'] = 'large'; $this->store->plan = $plan; $this->store->save(); $this->order = Order::factory()->for($this->store)->paid()->create(['number' => 1042, 'subtotal' => 2580, 'shipping_total' => 800, 'total' => 3380]); $this->order->items()->create(['store_id' => $this->store->id, 'name' => 'Sambal Hijau', 'unit_price' => 1290, 'quantity' => 2, 'line_total' => 2580]); } private function publish(): void { $this->store->forceFill(['status' => StoreStatus::Published, 'published_plan' => $this->store->plan])->save(); } public function test_the_paid_email_uses_the_stores_colours_fonts_and_corners() { $mail = new OrderConfirmation($this->order->fresh()); $mail->assertSeeInHtml('background-color: #123456; color: #FEDCBA', false); $mail->assertSeeInHtml(''Fraunces', Georgia', false); $mail->assertSeeInHtml('border-radius: 16px', false); $mail->assertSeeInHtml('Sambal Hijau'); $mail->assertSeeInHtml('2 × RM 12.90'); $mail->assertSeeInHtml('RM 33.80'); // Our app's name is not shown to shoppers: they bought from the store. $mail->assertDontSeeInHtml(config('app.name')); } public function test_the_paid_email_links_to_the_order_page_and_whatsapp() { $this->publish(); $mail = new OrderConfirmation($this->order->fresh()); $mail->assertSeeInHtml('https://kedai-ali.shops.test/orders/'.$this->order->public_id, false); $mail->assertSeeInHtml('https://wa.me/60123456789?text='.rawurlencode('Hi Kedai Ali, I have a question about my order #1042.'), false); $mail->assertSeeInText('View your order: https://kedai-ali.shops.test/orders/'.$this->order->public_id); $mail->assertSeeInText('Total paid: RM 33.80'); } public function test_a_store_that_is_not_live_links_to_its_preview_and_hides_whatsapp_when_there_is_no_number() { $this->store->forceFill(['whatsapp_number' => null])->save(); $mail = new OrderConfirmation($this->order->fresh()); $mail->assertSeeInHtml(route('stores.preview.order', ['kedai-ali', $this->order->public_id]), false); $mail->assertDontSeeInHtml('wa.me', false); } public function test_the_store_name_comes_from_its_header() { $plan = $this->store->plan; $plan['header']['content']['logoText'] = 'KEDAI ALI & CO'; $this->store->forceFill(['plan' => $plan])->save(); (new OrderConfirmation($this->order->fresh()))->assertSeeInHtml('KEDAI ALI & CO', false); } public function test_the_paid_email_is_in_malay_for_a_malay_store() { $this->store->update(['language' => 'ms']); $mail = new OrderConfirmation($this->order->fresh()); $mail->assertSeeInHtml('Terima kasih atas pesanan anda'); $mail->assertSeeInHtml('Lihat pesanan anda'); $mail->assertSeeInHtml('Jumlah dibayar'); $mail->assertSeeInHtml(rawurlencode('Hai Kedai Ali, saya ada soalan tentang pesanan saya #1042.'), false); } public function test_the_shipped_email_has_a_tracking_button_when_the_courier_gives_a_link() { $this->order->forceFill(['shipped_at' => now(), 'shipping_courier' => 'J&T Express', 'tracking_number' => 'JT630012345678', 'tracking_url' => 'https://track.example.com/JT630012345678'])->save(); $mail = new OrderShipped($this->order->fresh()); $mail->assertSeeInHtml('Track your parcel'); $mail->assertSeeInHtml('https://track.example.com/JT630012345678', false); $mail->assertSeeInHtml('JT630012345678'); $mail->assertSeeInHtml('background-color: #123456; color: #FEDCBA', false); $mail->assertSeeInText('Tracking number: JT630012345678'); $mail->assertSeeInText('J&T Express'); } public function test_without_a_tracking_link_the_shipped_email_explains_how_to_track() { $this->order->forceFill(['shipped_at' => now(), 'shipping_courier' => 'Pos Laju', 'tracking_number' => 'EP123MY'])->save(); $mail = new OrderShipped($this->order->fresh()); $mail->assertDontSeeInHtml('Track your parcel'); $mail->assertSeeInHtml('View your order'); $mail->assertSeeInHtml("Use the tracking number on the courier's website"); } public function test_a_store_without_a_design_still_gets_a_tidy_email() { $this->store->forceFill(['plan' => null])->save(); (new OrderConfirmation($this->order->fresh())) ->assertSeeInHtml('Kedai Ali') ->assertSeeInHtml('background-color: #1F1F1F', false); } public function test_emails_come_under_the_stores_name_and_replies_go_to_its_contact_email() { config(['mail.from.address' => 'orders@aicommerce.test']); $this->store->forceFill(['contact_email' => 'hello@kedaiali.my'])->save(); foreach ([new OrderConfirmation($this->order->fresh()), new OrderShipped($this->order->fresh())] as $mail) { $mail->assertFrom('orders@aicommerce.test', 'Kedai Ali'); $mail->assertHasReplyTo('hello@kedaiali.my', 'Kedai Ali'); $mail->assertSeeInHtml('mailto:hello@kedaiali.my', false); $mail->assertSeeInText('Questions? Reply to this email or write to hello@kedaiali.my'); } } public function test_without_a_contact_email_there_is_no_reply_address() { $mail = new OrderConfirmation($this->order->fresh()); $this->assertSame([], $mail->envelope()->replyTo); $mail->assertDontSeeInHtml('mailto:', false); } public function test_the_merchant_sets_the_contact_email_in_settings() { $this->actingAs($this->store->user); $save = fn (array $data) => $this->put(route('stores.settings.update', $this->store->slug), [ 'shipping_west' => '8.00', 'shipping_east' => '15.00', ...$data, ]); $this->get(route('stores.settings', $this->store->slug)) ->assertInertia(fn ($page) => $page ->where('settings.contact_email', null) ->where('accountEmail', $this->store->user->email)); $save(['contact_email' => 'not-an-email'])->assertSessionHasErrors('contact_email'); $save(['contact_email' => ' Hello@KedaiAli.my '])->assertSessionHasNoErrors(); $this->assertSame('hello@kedaiali.my', $this->store->fresh()->contact_email); // Saving a form without the field keeps it; clearing it removes it. $save([])->assertSessionHasNoErrors(); $this->assertSame('hello@kedaiali.my', $this->store->fresh()->contact_email); $save(['contact_email' => ''])->assertSessionHasNoErrors(); $this->assertNull($this->store->fresh()->contact_email); } }