Skip to content

Commit

Permalink
added transport and payment to frontend API (#1726)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLudvik authored Mar 17, 2020
2 parents 0be9251 + d2ee9a6 commit 74e48fe
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 11 deletions.
4 changes: 4 additions & 0 deletions config/graphql/types/Payment.types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Payment:
type: object
inherits:
- 'PaymentDecorator'
4 changes: 4 additions & 0 deletions config/graphql/types/Transport.types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Transport:
type: object
inherits:
- 'TransportDecorator'
2 changes: 2 additions & 0 deletions easy-coding-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ parameters:
- '*/tests/App/Functional/Model/Product/ProductOnCurrentDomainFacadeCountDataTest.php'
- '*/tests/App/Functional/Model/Cart/CartMigrationFacadeTest.php'
- '*/tests/FrontendApiBundle/Functional/Image/ProductImagesTest.php'
- '*/tests/FrontendApiBundle/Functional/Payment/PaymentsTest.php'
- '*/tests/FrontendApiBundle/Functional/Transport/TransportsTest.php'

ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff:
- '*/tests/App/Functional/Model/Product/ProductVisibilityRepositoryTest.php'
Expand Down
9 changes: 0 additions & 9 deletions tests/FrontendApiBundle/Functional/Category/CategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\FrontendApiBundle\Functional\Category;

use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Model\Category\CategoryFacade;
use Tests\FrontendApiBundle\Test\GraphQlTestCase;

Expand Down Expand Up @@ -127,12 +126,4 @@ public function testCategoryProductsByUuid(): void

$this->assertQueryWithExpectedArray($query, $arrayExpected);
}

/**
* @return string
*/
private function getLocaleForFirstDomain(): string
{
return $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale();
}
}
49 changes: 49 additions & 0 deletions tests/FrontendApiBundle/Functional/Payment/PaymentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Tests\FrontendApiBundle\Functional\Payment;

use Tests\FrontendApiBundle\Test\GraphQlTestCase;

class PaymentTest extends GraphQlTestCase
{
/**
* @var \Shopsys\FrameworkBundle\Model\Payment\PaymentFacade
* @inject
*/
protected $paymentFacade;

/**
* @var \Shopsys\FrameworkBundle\Model\Payment\Payment
*/
protected $payment;

protected function setUp(): void
{
$this->payment = $this->paymentFacade->getById(2);

parent::setUp();
}

public function testPaymentNameByUuid(): void
{
$query = '
query {
payment(uuid: "' . $this->payment->getUuid() . '") {
name
}
}
';

$arrayExpected = [
'data' => [
'payment' => [
'name' => t('Cash on delivery', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
],
],
];

$this->assertQueryWithExpectedArray($query, $arrayExpected);
}
}
99 changes: 99 additions & 0 deletions tests/FrontendApiBundle/Functional/Payment/PaymentsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

declare(strict_types=1);

namespace Tests\FrontendApiBundle\Functional\Payment;

use Tests\FrontendApiBundle\Test\GraphQlTestCase;

class PaymentsTest extends GraphQlTestCase
{
public function testPayments(): void
{
$query = '
query {
payments {
name,
description,
instruction,
position,
price {
priceWithVat
priceWithoutVat
vatAmount
},
images {
url
},
transports {
name
}
}
}
';

$arrayExpected = [
'data' => [
'payments' => [
[
'name' => t('Credit card', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
'description' => t('Quick, cheap and reliable!', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
'instruction' => null,
'position' => 0,
'price' => [
'priceWithVat' => '100',
'priceWithoutVat' => '100.00',
'vatAmount' => '0.00',
],
'images' => [
['url' => 'http://webserver:8080/content-test/images/payment/default/53.jpg'],
['url' => 'http://webserver:8080/content-test/images/payment/original/53.jpg'],
],
'transports' => [
['name' => t('PPL', [], 'dataFixtures', $this->getLocaleForFirstDomain())],
['name' => t('Personal collection', [], 'dataFixtures', $this->getLocaleForFirstDomain())],
],
],
[
'name' => t('Cash on delivery', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
'description' => null,
'instruction' => null,
'position' => 1,
'price' => [
'priceWithVat' => '50',
'priceWithoutVat' => '50.00',
'vatAmount' => '0.00',
],
'images' => [
['url' => 'http://webserver:8080/content-test/images/payment/default/55.jpg'],
['url' => 'http://webserver:8080/content-test/images/payment/original/55.jpg'],
],
'transports' => [
['name' => t('Czech post', [], 'dataFixtures', $this->getLocaleForFirstDomain())],
],
],
[
'name' => t('Cash', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
'description' => null,
'instruction' => null,
'position' => 2,
'price' => [
'priceWithVat' => '0',
'priceWithoutVat' => '0',
'vatAmount' => '0',
],
'images' => [
['url' => 'http://webserver:8080/content-test/images/payment/default/54.jpg'],
['url' => 'http://webserver:8080/content-test/images/payment/original/54.jpg'],
],
'transports' => [
['name' => t('Personal collection', [], 'dataFixtures', $this->getLocaleForFirstDomain())],
],
],
],
],
];

$this->assertQueryWithExpectedArray($query, $arrayExpected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public function testProductMainVariantResultData(): void
'shortDescription' => t('Television monitor IPS, 16: 9, 5M: 1, 200cd/m2, 5ms GTG, FullHD 1920x1080, DVB-S2/T2/C, 2x HDMI, USB, SCART, 2 x 5W speakers, energ. Class A', [], 'dataFixtures', $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale()),
'variants' => [
[
'name' => t('Hyundai 22HD44D', [], 'dataFixtures', $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale()),
'name' => t('51,5” Hyundai 22HD44D', [], 'dataFixtures', $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale()),
],
[
'name' => t('60” Hyundai 22HD44D', [], 'dataFixtures', $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale()),
],
[
'name' => t('51,5” Hyundai 22HD44D', [], 'dataFixtures', $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale()),
'name' => t('Hyundai 22HD44D', [], 'dataFixtures', $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale()),
],
],
],
Expand Down
49 changes: 49 additions & 0 deletions tests/FrontendApiBundle/Functional/Transport/TransportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Tests\FrontendApiBundle\Functional\Transport;

use Tests\FrontendApiBundle\Test\GraphQlTestCase;

class TransportTest extends GraphQlTestCase
{
/**
* @var \Shopsys\FrameworkBundle\Model\Transport\TransportFacade
* @inject
*/
protected $transportFacade;

/**
* @var \Shopsys\FrameworkBundle\Model\Transport\Transport
*/
protected $transport;

protected function setUp(): void
{
$this->transport = $this->transportFacade->getById(2);

parent::setUp();
}

public function testTransportNameByUuid(): void
{
$query = '
query {
transport(uuid: "' . $this->transport->getUuid() . '") {
name
}
}
';

$arrayExpected = [
'data' => [
'transport' => [
'name' => t('PPL', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
],
],
];

$this->assertQueryWithExpectedArray($query, $arrayExpected);
}
}
99 changes: 99 additions & 0 deletions tests/FrontendApiBundle/Functional/Transport/TransportsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

declare(strict_types=1);

namespace Tests\FrontendApiBundle\Functional\Transport;

use Tests\FrontendApiBundle\Test\GraphQlTestCase;

class TransportsTest extends GraphQlTestCase
{
public function testPayments(): void
{
$query = '
query {
transports {
name,
description,
instruction,
position,
price {
priceWithVat
priceWithoutVat
vatAmount
},
images {
url
},
payments {
name
}
}
}
';

$arrayExpected = [
'data' => [
'transports' => [
[
'name' => t('Czech post', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
'description' => null,
'instruction' => null,
'position' => 0,
'price' => [
'priceWithVat' => '121',
'priceWithoutVat' => '100.00',
'vatAmount' => '21.00',
],
'images' => [
['url' => 'http://webserver:8080/content-test/images/transport/default/56.jpg'],
['url' => 'http://webserver:8080/content-test/images/transport/original/56.jpg'],
],
'payments' => [
['name' => t('Cash on delivery', [], 'dataFixtures', $this->getLocaleForFirstDomain())],
],
],
[
'name' => t('PPL', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
'description' => null,
'instruction' => null,
'position' => 1,
'price' => [
'priceWithVat' => '242',
'priceWithoutVat' => '200.00',
'vatAmount' => '42.00',
],
'images' => [
['url' => 'http://webserver:8080/content-test/images/transport/default/57.jpg'],
['url' => 'http://webserver:8080/content-test/images/transport/original/57.jpg'],
],
'payments' => [
['name' => t('Credit card', [], 'dataFixtures', $this->getLocaleForFirstDomain())],
],
],
[
'name' => t('Personal collection', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
'description' => t('You will be welcomed by friendly staff!', [], 'dataFixtures', $this->getLocaleForFirstDomain()),
'instruction' => null,
'position' => 2,
'price' => [
'priceWithVat' => '0',
'priceWithoutVat' => '0',
'vatAmount' => '0',
],
'images' => [
['url' => 'http://webserver:8080/content-test/images/transport/default/58.jpg'],
['url' => 'http://webserver:8080/content-test/images/transport/original/58.jpg'],
],
'payments' => [
['name' => t('Credit card', [], 'dataFixtures', $this->getLocaleForFirstDomain())],
['name' => t('Cash', [], 'dataFixtures', $this->getLocaleForFirstDomain())],
],
],
],
],
];

$this->assertQueryWithExpectedArray($query, $arrayExpected);
}
}
9 changes: 9 additions & 0 deletions tests/FrontendApiBundle/Test/GraphQlTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\FrontendApiBundle\Test;

use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Symfony\Component\HttpFoundation\Response;
use Tests\App\Test\FunctionalTestCase;

Expand Down Expand Up @@ -87,4 +88,12 @@ private function getResponseForQuery(string $query, array $variables): ?Response

return $this->client->getResponse();
}

/**
* @return string
*/
protected function getLocaleForFirstDomain(): string
{
return $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID)->getLocale();
}
}

0 comments on commit 74e48fe

Please sign in to comment.