Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payload em pt-br para estimar preço #48

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Services/Price/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ private function buildBody(array $serviceCodes, array $products, array $fields):
private function setOptionalParams(Product $product, array $productParam): array
{
if ($product->getWidth() > 0) {
$productParam['width'] = $product->getWidth();
$productParam['largura'] = $product->getWidth();
}

if ($product->getHeight() > 0) {
$productParam['height'] = $product->getHeight();
$productParam['altura'] = $product->getHeight();
}

if ($product->getLength() > 0) {
$productParam['length'] = $product->getLength();
$productParam['comprimento'] = $product->getLength();
}

if ($product->getDiameter() > 0) {
$productParam['diameter'] = $product->getDiameter();
$productParam['diametro'] = $product->getDiameter();
}

if ($product->getCubicWeight() > 0) {
$productParam['cubicWeight'] = $product->getCubicWeight();
$productParam['psCubico'] = $product->getCubicWeight();
}

if ($product->getObjectType() > 1 && $product->getObjectType() <= 3) {
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/Services/Price/PriceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@

})->with('authentication', 'serviceCode', 'originCep', 'destinyCep');

test('It should be possible to use the get() method with optional dimensions without generate any Exception or empty array', function(Authentication $authentication, string $serviceCode, string $originCep, string $destinyCep) {
$price = new Price($authentication, time());
expect(
fn() => $price->get(
[$serviceCode],
[[
'weight' => fake()->randomFloat(1,1, 1000),
'width' => fake()->randomFloat(1,10, 20),
'height' => fake()->randomFloat(1,10, 20),
'length' => fake()->randomFloat(1,10, 20),
]],
$originCep,
$destinyCep
)
)
->not->toBeEmpty()
->not->toThrow(Exception::class);

})->with('authentication', 'serviceCode', 'originCep', 'destinyCep');

test('The get() method should generate an InvalidCepException when we use an invalid CEP', function(Authentication $authentication, string $serviceCode, string $destinyCep) {
$price = new Price($authentication, time());
expect(
Expand Down
Loading