Compare commits
2 Commits
ea22c19d2b
...
4422e7564b
| Author | SHA1 | Date | |
|---|---|---|---|
| 4422e7564b | |||
| bcef42b58e |
19
.gitea/workflows/test.yaml
Normal file
19
.gitea/workflows/test.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name: Launch the PHPunit tests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
phpunit-tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.1'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: composer install
|
||||||
|
- name: Run PHPUnit tests
|
||||||
|
run: vendor/bin/phpunit --configuration phpunit.xml
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Browser\Jobs\HellcaseBattles;
|
namespace App\Browser\Jobs\EldoradoRobuxPriceSentry;
|
||||||
|
|
||||||
use App\Notification\NotificationBody;
|
use App\Notification\NotificationBody;
|
||||||
|
|
||||||
|
|||||||
@@ -93,11 +93,11 @@ class EldoradoRobuxPriceSentryJob extends BrowserJob implements ShouldBeUniqueUn
|
|||||||
{
|
{
|
||||||
$lowestPriceElement = $browser->driver->findElement(WebDriverBy::xpath('(//eld-offer-price)[2]/strong'));
|
$lowestPriceElement = $browser->driver->findElement(WebDriverBy::xpath('(//eld-offer-price)[2]/strong'));
|
||||||
$lowestPriceText = $lowestPriceElement->getText(); // Ex: " 0,00478 € "
|
$lowestPriceText = $lowestPriceElement->getText(); // Ex: " 0,00478 € "
|
||||||
$lowestPrice = (float)str_replace(["€", ","], ["", "."], trim($lowestPriceText));
|
$lowestPrice = $this->textToFloat($lowestPriceText);
|
||||||
$lowestPrice = $lowestPrice / 1000; // Price per Robux
|
$lowestPrice = $lowestPrice / 1000; // Price per Robux
|
||||||
// TODO : Look at the entire text to try to understand if it is per 1k or per single Robux
|
// TODO : Look at the entire text to try to understand if it is per 1k or per single Robux
|
||||||
|
|
||||||
$threshold = floatval(str_replace(",", ".", $this->jobInfos->get("eldorado_robux_price_threshold")));
|
$threshold = $this->textToFloat($this->jobInfos->get("eldorado_robux_price_threshold"));
|
||||||
dump($threshold);
|
dump($threshold);
|
||||||
|
|
||||||
Log::info("EldoradoRobuxPriceSentryJob: lowest price = $lowestPrice €, threshold = $threshold €");
|
Log::info("EldoradoRobuxPriceSentryJob: lowest price = $lowestPrice €, threshold = $threshold €");
|
||||||
@@ -131,4 +131,9 @@ class EldoradoRobuxPriceSentryJob extends BrowserJob implements ShouldBeUniqueUn
|
|||||||
Log::info("EldoradoRobuxPriceSentryJob: no alert sent");
|
Log::info("EldoradoRobuxPriceSentryJob: no alert sent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function textToFloat(string $text): float
|
||||||
|
{
|
||||||
|
return floatval(str_replace(["€", ","], ["", "."], trim($text)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@
|
|||||||
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
||||||
<env name="BCRYPT_ROUNDS" value="4"/>
|
<env name="BCRYPT_ROUNDS" value="4"/>
|
||||||
<env name="CACHE_STORE" value="array"/>
|
<env name="CACHE_STORE" value="array"/>
|
||||||
<!-- <env name="DB_CONNECTION" value="sqlite"/> -->
|
<env name="DB_CONNECTION" value="sqlite"/>
|
||||||
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
|
<env name="DB_DATABASE" value=":memory:"/>
|
||||||
<env name="MAIL_MAILER" value="array"/>
|
<env name="MAIL_MAILER" value="array"/>
|
||||||
<env name="PULSE_ENABLED" value="false"/>
|
<env name="PULSE_ENABLED" value="false"/>
|
||||||
<env name="QUEUE_CONNECTION" value="sync"/>
|
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\EldoradoRobuxPriceSentryJob;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use App\Browser\Jobs\EldoradoRobuxPriceSentry\EldoradoRobuxPriceSentryJob;
|
||||||
|
use ReflectionMethod;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class textToFLoatTest extends TestCase
|
||||||
|
{
|
||||||
|
private EldoradoRobuxPriceSentryJob $job;
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
parent::setUp();
|
||||||
|
$this->job = new EldoradoRobuxPriceSentryJob();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function assertTextToFloat($input, $expected) {
|
||||||
|
$reflection = new ReflectionMethod(EldoradoRobuxPriceSentryJob::class, 'textToFloat');
|
||||||
|
$reflection->setAccessible(true);
|
||||||
|
$result = $reflection->invoke($this->job, $input);
|
||||||
|
$this->assertEquals($expected, $result, "Failed asserting that textToFloat('$input') equals $expected. Got $result instead.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function test_simple_int(): void
|
||||||
|
{
|
||||||
|
$this->assertTextToFloat("10", 10.0);
|
||||||
|
$this->assertTextToFloat(" 42", 42.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_decimal_numbers(): void
|
||||||
|
{
|
||||||
|
$this->assertTextToFloat("3,14", 3.14);
|
||||||
|
$this->assertTextToFloat(" 0,0015 ", 0.0015);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_money_symbols_int(): void
|
||||||
|
{
|
||||||
|
$this->assertTextToFloat("5 €", 5.0);
|
||||||
|
$this->assertTextToFloat(" € 123 ", 123.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_money_symbols_decimal(): void
|
||||||
|
{
|
||||||
|
$this->assertTextToFloat("7,89 €", 7.89);
|
||||||
|
$this->assertTextToFloat(" € 0,75 ", 0.75);
|
||||||
|
$this->assertTextToFloat(" €0.00402 ", 0.00402);
|
||||||
|
$this->assertTextToFloat(" 0,00429 € ", 0.00429);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user