withHeaders(['x-access-token' => $this->buildClientAccessToken()]); } public function test_customer_can_only_read_their_own_login_history(): void { $customer = Customer::factory()->create(['status' => 1]); $other = Customer::factory()->create(['status' => 1]); ActivityLog::create([ 'log_name' => 'auth', 'event' => 'login', 'description' => 'customer login', 'causer_type' => 'customer', 'causer_id' => $customer->id, 'causer_name' => $customer->email, 'ip_address' => '203.0.113.10', 'user_agent' => 'Mozilla/5.0 Chrome/130.0', ]); ActivityLog::create([ 'log_name' => 'auth', 'event' => 'login', 'description' => 'other customer login', 'causer_type' => 'customer', 'causer_id' => $other->id, 'causer_name' => $other->email, 'ip_address' => '198.51.100.20', ]); $response = $this->actingAs($customer, 'client') ->api() ->getJson('/v1/client/login-history?per_page=10') ->assertOk() ->assertJsonPath('meta.total', 1) ->assertJsonPath('data.0.ip_address', '203.0.113.10'); $this->assertCount(1, $response->json('data')); } public function test_customer_can_update_account_preferences(): void { $customer = Customer::factory()->create([ 'status' => 1, 'email_marketing' => 1, 'receive_deposit' => 1, ]); $this->actingAs($customer, 'client') ->api() ->putJson('/v1/client/preferences', [ 'email_marketing' => false, 'receive_deposit' => true, ]) ->assertOk() ->assertJsonPath('data.client.customer.email_marketing', false) ->assertJsonPath('data.client.customer.receive_deposit', true); $customer->refresh(); $this->assertSame(0, (int) $customer->email_marketing); $this->assertSame(1, (int) $customer->receive_deposit); } public function test_preferences_require_both_boolean_values(): void { $customer = Customer::factory()->create(['status' => 1]); $this->actingAs($customer, 'client') ->api() ->putJson('/v1/client/preferences', ['email_marketing' => 'yes']) ->assertStatus(422) ->assertJsonValidationErrors(['email_marketing', 'receive_deposit']); } }