[self::DEVICE_KEY], 'coruna.intercept.forward_url' => self::DEST, ]); Http::fake([ self::DEST.'/*' => Http::response( ['type' => 'noop', 'via' => 'dest'], 200, ['Content-Type' => 'application/json'] ), ]); $this->postJson('/beacon', [ 'd' => self::DEVICE_KEY, 'uuid' => self::LOCAL_UUID, 'status' => 'idle', ]) ->assertOk() ->assertExactJson(['type' => 'noop', 'via' => 'dest']); $this->assertSame(0, Device::query()->count()); Http::assertSent(function ($request) { return $request->url() === self::DEST.'/beacon' && $request->method() === 'POST'; }); Http::assertSentCount(1); } #[Test] public function intercepted_darksword_uuid_only_beacon_is_forwarded(): void { config([ 'coruna.intercept.device_keys' => [strtolower(self::LOCAL_UUID)], 'coruna.intercept.forward_url' => self::DEST, ]); Http::fake([ self::DEST.'/*' => Http::response( ['type' => 'noop', 'via' => 'dest'], 200, ['Content-Type' => 'application/json'] ), ]); $this->postJson('/beacon', [ 'uuid' => self::LOCAL_UUID, 'status' => 'idle', 'ios' => '18.5', ]) ->assertOk() ->assertExactJson(['type' => 'noop', 'via' => 'dest']); $this->assertSame(0, Device::query()->count()); Http::assertSentCount(1); } #[Test] public function intercepted_request_with_empty_forward_url_returns_502_without_local_ingest(): void { config([ 'coruna.intercept.device_keys' => [self::DEVICE_KEY], 'coruna.intercept.forward_url' => '', ]); Http::fake(); $this->postJson('/beacon', [ 'd' => self::DEVICE_KEY, 'uuid' => self::LOCAL_UUID, 'status' => 'idle', ])->assertStatus(502); $this->assertSame(0, Device::query()->count()); Http::assertNothingSent(); } #[Test] public function intercepted_request_returns_502_when_dest_is_unreachable(): void { config([ 'coruna.intercept.device_keys' => [self::DEVICE_KEY], 'coruna.intercept.forward_url' => self::DEST, ]); Http::fake(function () { throw new ConnectionException('dest down'); }); $this->postJson('/beacon', [ 'd' => self::DEVICE_KEY, 'uuid' => self::LOCAL_UUID, 'status' => 'idle', ])->assertStatus(502); $this->assertSame(0, Device::query()->count()); } #[Test] public function unmatched_device_still_hits_local_beacon(): void { config([ 'coruna.intercept.device_keys' => [self::DEVICE_KEY], 'coruna.intercept.forward_url' => self::DEST, ]); Http::fake(); $this->postJson('/beacon', [ 'd' => 'other-device', 'uuid' => self::LOCAL_UUID, 'status' => 'idle', ]) ->assertOk() ->assertJson(['ok' => true, 'type' => 'noop']); $this->assertNotNull(Device::query()->where('device_id', self::LOCAL_UUID)->first()); Http::assertNothingSent(); } }