diff --git a/src/app/Console/Commands/Wallet/GetDiscountCommand.php b/src/app/Console/Commands/Wallet/GetDiscountCommand.php index 4034a501..057f517e 100644 --- a/src/app/Console/Commands/Wallet/GetDiscountCommand.php +++ b/src/app/Console/Commands/Wallet/GetDiscountCommand.php @@ -1,59 +1,59 @@ getWallet($this->argument('wallet')); if (!$wallet) { $this->error("Wallet not found."); return 1; } if ($this->option('int')) { - $this->info($wallet->discount?->discount ?? 0); + $this->info((string) ($wallet->discount?->discount ?? 0)); return 0; } if (!$wallet->discount) { $this->info("No discount on this wallet."); return 0; } $result = $wallet->discount->discount . '%'; if ($code = $wallet->discount->code) { $result .= " [{$code}]"; } if ($description = $wallet->discount->description) { $result .= " {$description}"; } $this->info($result); } } diff --git a/src/tests/Feature/Controller/PolicyTest.php b/src/tests/Feature/Controller/PolicyTest.php index aedb81e6..6026ea46 100644 --- a/src/tests/Feature/Controller/PolicyTest.php +++ b/src/tests/Feature/Controller/PolicyTest.php @@ -1,87 +1,97 @@ clientAddress = '212.103.80.148'; - $this->net = \App\IP4Net::getNet($this->clientAddress); + $this->clientAddress = '127.0.0.100'; + + $this->net = \App\IP4Net::create([ + 'net_number' => '127.0.0.0', + 'net_broadcast' => '127.255.255.255', + 'net_mask' => 8, + 'country' => 'US', + 'rir_name' => 'test', + 'serial' => 1, + ]); + $this->testDomain = $this->getTestDomain('test.domain', [ 'type' => Domain::TYPE_EXTERNAL, 'status' => Domain::STATUS_ACTIVE | Domain::STATUS_CONFIRMED | Domain::STATUS_VERIFIED ]); + $this->testUser = $this->getTestUser('john@test.domain'); Greylist\Connect::where('sender_domain', 'sender.domain')->delete(); Greylist\Whitelist::where('sender_domain', 'sender.domain')->delete(); $this->useServicesUrl(); } public function tearDown(): void { $this->deleteTestUser($this->testUser->email); $this->deleteTestDomain($this->testDomain->namespace); + $this->net->delete(); Greylist\Connect::where('sender_domain', 'sender.domain')->delete(); Greylist\Whitelist::where('sender_domain', 'sender.domain')->delete(); parent::tearDown(); } /** * Test greylist policy webhook * - * @group data * @group greylist */ public function testGreylist() { // Note: Only basic tests here. More detailed policy handler tests are in another place // Test 403 response $post = [ 'sender' => 'someone@sender.domain', 'recipient' => $this->testUser->email, 'client_address' => $this->clientAddress, 'client_name' => 'some.mx' ]; $response = $this->post('/api/webhooks/policy/greylist', $post); $response->assertStatus(403); $json = $response->json(); $this->assertEquals('DEFER_IF_PERMIT', $json['response']); $this->assertEquals("Greylisted for 5 minutes. Try again later.", $json['reason']); // Test 200 response $connect = Greylist\Connect::where('sender_domain', 'sender.domain')->first(); $connect->created_at = \Carbon\Carbon::now()->subMinutes(6); $connect->save(); $response = $this->post('/api/webhooks/policy/greylist', $post); $response->assertStatus(200); $json = $response->json(); $this->assertEquals('DUNNO', $json['response']); $this->assertMatchesRegularExpression('/^Received-Greylist: greylisted from/', $json['prepend'][0]); } }