create(['username' => 'promouser', 'email_verified_at' => now()]); } public function test_apply_success_passes_message() { Http::fake([ $this->base() . '/promos/apply' => Http::response([ 'success' => true, 'message' => 'Applied', ], 200), ]); $res = $this->actingAs($this->actingUser(), 'web') ->postJson('/api/promos/apply', ['code' => 'WELCOME']); $res->assertStatus(200) ->assertJson([ 'success' => true, 'message' => 'Applied', ]); } public function test_apply_client_error_maps_to_client_error() { Http::fake([ $this->base() . '/promos/apply' => Http::response(['message' => 'Invalid code'], 400), ]); $res = $this->actingAs($this->actingUser(), 'web') ->postJson('/api/promos/apply', ['code' => 'bad!']); $res->assertStatus(400) ->assertJson(['error' => 'client_error']); } }