mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
Kroger grocery stores allow manual access to past purchases in json form through a browser's developer tools. This class converts the Kroger json data into something Grocy can understand while doing minor error checking. Also added appropriate unit tests. In order to get this json, open developer tools and navigate to https://www.qfc.com/mypurchases (or another Kroger grocer, aka https://www.fredmeyer.com/mypurchases) and look for a call to /mypurchases/api/v1/receipt/details. The entire response will contain all recent purchases.
46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php declare(strict_types=1);
|
|
use PHPUnit\Framework\TestCase;
|
|
use Grocy\Helpers\KrogerToGrocyConverter;
|
|
|
|
final class KrogerToGrocyConverterTest extends TestCase
|
|
{
|
|
public function testConvertUpcToBarcode(): void
|
|
{
|
|
$this->assertEquals(
|
|
"0722252601421",
|
|
KrogerToGrocyConverter::ConvertUpcToBarcode("0072225260142")
|
|
);
|
|
$this->assertEquals(
|
|
"0072220005165",
|
|
KrogerToGrocyConverter::ConvertUpcToBarcode("07222000516")
|
|
);
|
|
$this->assertEquals(
|
|
"0072220005165",
|
|
KrogerToGrocyConverter::ConvertUpcToBarcode("0000007222000516")
|
|
);
|
|
}
|
|
|
|
public function testConvertJson(): void
|
|
{
|
|
$testjson = file_get_contents(dirname(__FILE__) . "/testdata/receipts.json");
|
|
$default_quantity_units = 3;
|
|
$default_location_id = 2;
|
|
|
|
$products = KrogerToGrocyConverter::ConvertJson(json_decode($testjson, true), $default_quantity_units, $default_location_id);
|
|
|
|
$expectedjson = file_get_contents(dirname(__FILE__) . "/testdata/receipts_expected.json");
|
|
$expected = json_decode($expectedjson, true);
|
|
|
|
$this->assertEquals(count($expected), count($products));
|
|
|
|
foreach ($expected as $index => $product)
|
|
{
|
|
foreach ($product as $key => $value)
|
|
{
|
|
$this->assertEquals($value, $products[$index][$key]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|