Skip to content

Commit

Permalink
OP-303: Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GracjanJozefczyk committed Jun 7, 2024
1 parent 396b423 commit 868e7d7
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
Sylius\Component\Core\Model\Channel:
channel_web:
code: 'WEB'
name: 'Web Channel'
hostname: 'localhost'
description: 'Lorem ipsum'
baseCurrency: '@currency_usd'
defaultLocale: '@locale_en'
locales: ['@locale_en']
color: 'black'
enabled: true
taxCalculationStrategy: 'order_items_based'

Sylius\Component\Currency\Model\Currency:
currency_usd:
code: 'USD'

Sylius\Component\Locale\Model\Locale:
locale_en:
code: 'en_US'

Sylius\Component\Core\Model\Product:
product_mug:
code: 'MUG'
channels: ['@channel_web']
currentLocale: 'en_US'
translations:
en_US: '@product_translation_mug'
product_mug2:
code: 'MUG2'
channels: ['@channel_web']
currentLocale: 'en_US'
translations:
en_US: '@product_translation_mug2'
product_mug3:
code: 'MUG3'
channels: ['@channel_web']
currentLocale: 'en_US'
translations:
en_US: '@product_translation_mug3'

Sylius\Component\Core\Model\ProductTranslation:
product_translation_mug:
slug: 'mug'
locale: 'en_US'
name: 'Mug'
description: '<paragraph(2)>'
translatable: '@product_mug'
product_translation_mug2:
slug: 'mug-2'
locale: 'en_US'
name: 'Mug 2'
description: '<paragraph(2)>'
translatable: '@product_mug2'
product_translation_mug3:
slug: 'mug-3'
locale: 'en_US'
name: 'Mug 3'
description: '<paragraph(2)>'
translatable: '@product_mug3'

Sylius\Component\Product\Model\ProductAttributeTranslation:
attributeTranslation1:
locale: en_US
name: "Product color"
translatable: "@product_attribute_color"
attributeTranslation2:
locale: en_US
name: "Product material"
translatable: "@product_attribute_material"

Sylius\Component\Product\Model\ProductAttribute:
product_attribute_color:
code: 'color'
type: 'text'
storage_type: 'text'
position: 1
translatable: 1
product_attribute_material:
code: 'material'
type: 'text'
storage_type: 'text'
position: 1
translatable: 1

Sylius\Component\Product\Model\ProductAttributeValue:
product_attribute_value_color_1:
product: '@product_mug'
attribute: '@product_attribute_color'
localeCode: 'en_US'
value: 'red'
product_attribute_value_color_2:
product: '@product_mug2'
attribute: '@product_attribute_color'
localeCode: 'en_US'
value: 'red'
product_attribute_value_material_1:
product: '@product_mug'
attribute: '@product_attribute_material'
localeCode: 'en_US'
value: 'ceramic'
product_attribute_value_material_2:
product: '@product_mug2'
attribute: '@product_attribute_material'
localeCode: 'en_US'
value: 'ceramic'

Sylius\Component\Core\Model\Taxon:
mugs:
code: "mugs"

Sylius\Component\Core\Model\ProductTaxon:
productTaxon1:
product: "@product_mug"
taxon: "@mugs"
position: 0
26 changes: 24 additions & 2 deletions tests/PHPUnit/Integration/Api/ProductListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public function test_it_finds_products_by_name(): void
$this->loadFixturesFromFiles(['test_it_finds_products_by_name.yaml']);
$this->populateElasticsearch();

$this->client->request('GET', '/api/v2/shop/products/search?query=mug');
$this->client->request(
'GET',
'/api/v2/shop/products/search?query=mug'
);

$response = $this->client->getResponse();
$this->assertResponse($response, 'test_it_finds_products_by_name', Response::HTTP_OK);
}
Expand All @@ -36,11 +40,29 @@ public function test_it_finds_products_by_name_and_facets(): void
$this->loadFixturesFromFiles(['test_it_finds_products_by_name_and_facets.yaml']);
$this->populateElasticsearch();

$this->client->request('GET', '/api/v2/shop/products/search?query=mug&facets[color][]=red');
$this->client->request(
'GET',
'/api/v2/shop/products/search?query=mug&facets[color][]=red'
);

$response = $this->client->getResponse();
$this->assertResponse($response, 'test_it_finds_products_by_name_and_facets', Response::HTTP_OK);
}

public function test_it_finds_products_by_name_and_multiple_facets(): void
{
$this->loadFixturesFromFiles(['test_it_finds_products_by_name_and_multiple_facets.yaml']);
$this->populateElasticsearch();

$this->client->request(
'GET',
'/api/v2/shop/products/search?query=mug&facets[color][]=red&facets[material][]=ceramic'
);

$response = $this->client->getResponse();
$this->assertResponse($response, 'test_it_finds_products_by_name_and_multiple_facets', Response::HTTP_OK);
}

private function populateElasticsearch(): void
{
$process = new Process(['tests/Application/bin/console', 'fos:elastica:populate']);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"items": [
{
"productTaxons": [
"/api/v2/shop/product-taxons/@string@"
],
"mainTaxon": null,
"averageRating": 0,
"images": [],
"id": "@integer@",
"code": "MUG",
"variants": [],
"options": [],
"associations": [],
"createdAt": "@string@",
"updatedAt": "@string@",
"shortDescription": null,
"reviews": [],
"name": "Mug",
"description": "@string@",
"slug": "mug"
},
{
"productTaxons": [],
"mainTaxon": null,
"averageRating": 0,
"images": [],
"id": "@integer@",
"code": "MUG2",
"variants": [],
"options": [],
"associations": [],
"createdAt": "@string@",
"updatedAt": "@string@",
"shortDescription": null,
"reviews": [],
"name": "Mug 2",
"description": "@string@",
"slug": "mug-2"
}
],
"facets": {
"material": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "ceramic",
"doc_count": 2
}
]
},
"color": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "red",
"doc_count": 2
}
]
},
"price": {
"buckets": []
},
"taxon": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "mugs",
"doc_count": 1
}
]
}
},
"pagination": {
"current_page": 1,
"has_previous_page": false,
"has_next_page": false,
"per_page": 9,
"total_items": 2,
"total_pages": 1
}
}

0 comments on commit 868e7d7

Please sign in to comment.