From 18094943397af832fa50dfd0caaa8176bf786c4c Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Fri, 3 May 2024 14:55:33 +0500 Subject: [PATCH] =?UTF-8?q?STA-968=20|=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- migrations/Version20240426064235.php | 0 ...02094853.php => Version20240503065723.php} | 6 +- src/Service/NewsService.php | 4 +- src/Service/RestaurantService.php | 4 +- tests/NewsControllerTest.php | 148 ++++++++++++++++ tests/RestaurantControllerTest.php | 163 ++++++++++++------ tests/responses/mainNews.json | 15 ++ tests/responses/news.json | 33 ++++ tests/responses/newsNotFound.json | 4 + tests/responses/newsOne.json | 18 ++ tests/responses/restaurant.json | 59 +++++++ tests/responses/restaurantNotFound.json | 4 + tests/responses/restaurants.json | 44 +++++ tests/responses/searchNews.json | 18 ++ 15 files changed, 461 insertions(+), 61 deletions(-) delete mode 100644 migrations/Version20240426064235.php rename migrations/{Version20240502094853.php => Version20240503065723.php} (97%) create mode 100644 tests/NewsControllerTest.php create mode 100644 tests/responses/mainNews.json create mode 100644 tests/responses/news.json create mode 100644 tests/responses/newsNotFound.json create mode 100644 tests/responses/newsOne.json create mode 100644 tests/responses/restaurant.json create mode 100644 tests/responses/restaurantNotFound.json create mode 100644 tests/responses/restaurants.json create mode 100644 tests/responses/searchNews.json diff --git a/.env b/.env index 679fb18..bbb4151 100644 --- a/.env +++ b/.env @@ -26,7 +26,7 @@ APP_SECRET=ea3ebbf899855d483050e0d1aad6a759 # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4" -DATABASE_URL="postgresql://postgres:12345@postgres/postgres?serverVersion=16&charset=utf8" +DATABASE_URL="postgresql://postgres:12345@postgres/postgres_test?serverVersion=16&charset=utf8" ###< doctrine/doctrine-bundle ### ###> symfony/messenger ### diff --git a/migrations/Version20240426064235.php b/migrations/Version20240426064235.php deleted file mode 100644 index e69de29..0000000 diff --git a/migrations/Version20240502094853.php b/migrations/Version20240503065723.php similarity index 97% rename from migrations/Version20240502094853.php rename to migrations/Version20240503065723.php index 1727aac..bfdb5fe 100644 --- a/migrations/Version20240502094853.php +++ b/migrations/Version20240503065723.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20240502094853 extends AbstractMigration +final class Version20240503065723 extends AbstractMigration { public function getDescription(): string { @@ -20,8 +20,6 @@ final class Version20240502094853 extends AbstractMigration public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->addSql('DROP SEQUENCE gallery_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE seo_id_seq CASCADE'); $this->addSql('CREATE TABLE file (id UUID NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, size INT NOT NULL, type VARCHAR(255) NOT NULL, url VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); $this->addSql('COMMENT ON COLUMN file.id IS \'(DC2Type:uuid)\''); $this->addSql('CREATE TABLE gallery (id UUID NOT NULL, restaurant_id UUID NOT NULL, file_id UUID NOT NULL, PRIMARY KEY(id))'); @@ -129,8 +127,6 @@ final class Version20240502094853 extends AbstractMigration { // this down() migration is auto-generated, please modify it to your needs $this->addSql('CREATE SCHEMA public'); - $this->addSql('CREATE SEQUENCE gallery_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE seo_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); $this->addSql('ALTER TABLE gallery DROP CONSTRAINT FK_472B783AB1E7706E'); $this->addSql('ALTER TABLE gallery DROP CONSTRAINT FK_472B783A93CB796C'); $this->addSql('ALTER TABLE kitchen DROP CONSTRAINT FK_EAA3CE34B1E7706E'); diff --git a/src/Service/NewsService.php b/src/Service/NewsService.php index 52bdd28..a982f83 100644 --- a/src/Service/NewsService.php +++ b/src/Service/NewsService.php @@ -27,8 +27,8 @@ class NewsService public function getNewsByRequest(NewsListRequest $request): NewsList { - $page = $request->getRequest()->query->get('page')?? self::DEFAULT_PAGE; - $limit = $request->getRequest()->query->get('limit')?? self::DEFAULT_LIMIT; + $page = $request->getRequest()->query->get('page') ?? self::DEFAULT_PAGE; + $limit = $request->getRequest()->query->get('limit') ?? self::DEFAULT_LIMIT; $newsCategory = $request->getRequest()->query->get('news_category'); return $this->getNews($page, $limit, $newsCategory); diff --git a/src/Service/RestaurantService.php b/src/Service/RestaurantService.php index 23ade59..a53f597 100644 --- a/src/Service/RestaurantService.php +++ b/src/Service/RestaurantService.php @@ -33,8 +33,8 @@ class RestaurantService public function getRestaurantsByRequest( RestaurantListRequest $request ): RestaurantList { - $page = $request->getRequest()->query->get('page')?? self::DEFAULT_PAGE; - $limit = $request->getRequest()->query->get('limit')?? self::DEFAULT_LIMIT; + $page = $request->getRequest()->query->get('page') ?? self::DEFAULT_PAGE; + $limit = $request->getRequest()->query->get('limit') ?? self::DEFAULT_LIMIT; $restaurantTypeId = $request->getRequest()->query->get('restaurant_type_id'); $kitchenId = $request->getRequest()->query->get('kitchen_id'); diff --git a/tests/NewsControllerTest.php b/tests/NewsControllerTest.php new file mode 100644 index 0000000..4b9569a --- /dev/null +++ b/tests/NewsControllerTest.php @@ -0,0 +1,148 @@ +request( + 'GET', + '/api/v1/news?page=1&limit=12' + ); + + $this->assertResponseIsSuccessful(); + } + + public function testNewsJsonDataPartly(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news' + ); + $data = $client->getResponse()->getContent(); + + $this->assertStringContainsString('url' , $data); + } + + public function testNewsJsonData(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news?page=1&limit=12' + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/news.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } + + public function testNewsWithNewsCategory(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news?page=1&limit=12&news_category_id=' . self::NEWS_CATEGORY_ID + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/news.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } + + public function testMainNewsJsonDataPartly(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news/mainNews' + ); + $data = $client->getResponse()->getContent(); + + $this->assertStringContainsString('name' , $data); + } + + public function testMainNews(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news/mainNews' + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/mainNews.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } + + public function testSearchNewsJsonDataPartly(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news/search' + ); + $data = $client->getResponse()->getContent(); + + $this->assertStringContainsString('seoTitle' , $data); + } + + public function testSearchNews(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news/search' + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/searchNews.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } + + public function testNewsOne(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news/' . self::NEWS_ID + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/searchNews.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } + + public function testNewsOneJsonDataPartly(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news/' . self::NEWS_ID + ); + $data = $client->getResponse()->getContent(); + + $this->assertStringContainsString('createAt' , $data); + } + + public function testNewsOneNotFound(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/news/test' + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/newsNotFound.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } +} \ No newline at end of file diff --git a/tests/RestaurantControllerTest.php b/tests/RestaurantControllerTest.php index c976e59..addf713 100644 --- a/tests/RestaurantControllerTest.php +++ b/tests/RestaurantControllerTest.php @@ -8,56 +8,117 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class RestaurantControllerTest extends WebTestCase { - public function testRestaurants(): void - { - $client = static::createClient(); - $content = $client->request('GET', '/api/v1/restaurants?page=1&limit=12'); - $actual = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR); - $expect = '{ - "pagination": { - "currentPage": 1, - "pages": 1, - "pageSize": 12 - }, - "list": [ - { - "id": 1, - "name": "Ресторан «Арктика»", - "code": "restoran-arktika", - "type": { - "id": 1, - "name": "Ресторан", - "code": "restoran" - }, - "check": "bla bla", - "image": { - "id": 1, - "name": "name", - "description": "description", - "size": 10, - "type": "jpg", - "url": "/upload/preview.png" - }, - "detailLink": "https://visityamal.ru/" - } - ], - "filterVariants": { - "type": [ - { - "id": 1, - "name": "Ресторан", - "code": "restoran" - } - ], - "kitchen": [ - { - "id": 1, - "name": "Азиатская" - } - ] - } -}'; - self::assertResponseIsSuccessful(); - self::assertJsonStringEqualsJsonString($expect, $actual); + private const RESTAURANT_ID = '018f3d5b-6688-7a34-b4ee-415cc851d5fa'; + private const RESTAURANT_TYPE_ID = '018f3d5b-6688-7a34-b4ee-415cc59ae55a'; + + public function testRestaurantsSuccessResponse(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants?page=1&limit=12' + ); + + $this->assertResponseIsSuccessful(); + } + + public function testRestaurantsSuccessResponseWithoutQuery(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants' + ); + + $this->assertResponseIsSuccessful(); + } + + public function testRestaurantsJsonDataPartly(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants' + ); + $data = $client->getResponse()->getContent(); + + $this->assertStringContainsString('image' , $data); + } + + public function testRestaurantsJsonData(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants?page=1&limit=12' + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/restaurants.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } + + public function testRestaurantsWithTypeId(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants?page=1&limit=12&restaurant_type_id=' + . self::RESTAURANT_TYPE_ID + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/restaurants.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } + + public function testRestaurantSuccessResponse(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants/' . self::RESTAURANT_ID + ); + + $this->assertResponseIsSuccessful(); + } + + public function testRestaurantJsonDataPartly(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants/' . self::RESTAURANT_ID + ); + $data = $client->getResponse()->getContent(); + + $this->assertStringContainsString('tags' , $data); + } + + public function testRestaurantJsonData(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants/' . self::RESTAURANT_ID + ); + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/restaurant.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); + } + + public function testRestaurantNotFound(): void + { + $client = static::createClient(); + $crawler = $client->request( + 'GET', + '/api/v1/restaurants/test' + ); + + $data = $client->getResponse()->getContent(); + $expected = file_get_contents(__DIR__ . '/responses/restaurantNotFound.json'); + + $this->assertJsonStringEqualsJsonString($expected, $data); } } diff --git a/tests/responses/mainNews.json b/tests/responses/mainNews.json new file mode 100644 index 0000000..c8c82be --- /dev/null +++ b/tests/responses/mainNews.json @@ -0,0 +1,15 @@ +{ + "id": "018f3d5b-65c7-7998-a6d5-2270db52f830", + "name": "Два часа на знакомство с тысячелетней историей Ямала.", + "description": "Это самый большой музей на Ямале. Здесь вы найдете всё о жизни региона, традициях и обычаях народов севера и посетите виртуальную выставку, организованную по последнему слову современных технологий.", + "image": { + "id": "018f3d5b-65c7-7998-a6d5-2270da0797c7", + "name": "asd", + "description": "Краткое описание", + "size": 1024, + "type": "png", + "url": "/upload/asd.png" + }, + "createAt": "23.04.2024", + "detailLink": "/yamal-museum/code/" +} \ No newline at end of file diff --git a/tests/responses/news.json b/tests/responses/news.json new file mode 100644 index 0000000..5e5bd18 --- /dev/null +++ b/tests/responses/news.json @@ -0,0 +1,33 @@ +{ + "pagination": { + "currentPage": 1, + "pages": 1, + "pageSize": 12 + }, + "list": [ + { + "id": "018f3d5b-65c7-7998-a6d5-2270db52f830", + "name": "Два часа на знакомство с тысячелетней историей Ямала.", + "description": "Это самый большой музей на Ямале. Здесь вы найдете всё о жизни региона, традициях и обычаях народов севера и посетите виртуальную выставку, организованную по последнему слову современных технологий.", + "image": { + "id": "018f3d5b-65c7-7998-a6d5-2270da0797c7", + "name": "asd", + "description": "Краткое описание", + "size": 1024, + "type": "png", + "url": "/upload/asd.png" + }, + "createAt": "23.04.2024", + "detailLink": "/yamal-museum/code/" + } + ], + "filterVariants": { + "category": [ + { + "id": "018f3d5b-65c7-7998-a6d5-2270da54ce3c", + "name": "Культура", + "code": "kultura" + } + ] + } +} \ No newline at end of file diff --git a/tests/responses/newsNotFound.json b/tests/responses/newsNotFound.json new file mode 100644 index 0000000..c0d0369 --- /dev/null +++ b/tests/responses/newsNotFound.json @@ -0,0 +1,4 @@ +{ + "success": false, + "message": "News not found" +} \ No newline at end of file diff --git a/tests/responses/newsOne.json b/tests/responses/newsOne.json new file mode 100644 index 0000000..b75de05 --- /dev/null +++ b/tests/responses/newsOne.json @@ -0,0 +1,18 @@ +{ + "id": "018f3d5b-65c7-7998-a6d5-2270db52f830", + "name": "Два часа на знакомство с тысячелетней историей Ямала.", + "description": "Это самый большой музей на Ямале. Здесь вы найдете всё о жизни региона, традициях и обычаях народов севера и посетите виртуальную выставку, организованную по последнему слову современных технологий.", + "text": "Это самый большой музей на Ямале. Здесь вы найдете всё о жизни региона, традициях и обычаях народов севера и посетите виртуальную выставку, организованную по последнему слову современных технологий.", + "image": { + "id": "018f3d5b-65c7-7998-a6d5-2270da0797c7", + "name": "asd", + "description": "Краткое описание", + "size": 1024, + "type": "png", + "url": "/upload/asd.png" + }, + "createAt": "23.04.2024", + "seoTitle": "Отель Арктика", + "seoDescription": "otel-arktika", + "seoKeywords": "otel-arktika" +} \ No newline at end of file diff --git a/tests/responses/restaurant.json b/tests/responses/restaurant.json new file mode 100644 index 0000000..e4ae761 --- /dev/null +++ b/tests/responses/restaurant.json @@ -0,0 +1,59 @@ +{ + "id": "018f3d5b-6688-7a34-b4ee-415cc851d5fa", + "name": "Ресторан «Арктика»", + "code": "restoran-arktika", + "coordinates": "123,321", + "type": { + "id": "018f3d5b-6688-7a34-b4ee-415cc59ae55a", + "name": "Ресторан", + "code": "restoran" + }, + "check": "от 1 до 2 || от 1 || до 1000", + "checkInfo": "bla bla", + "kitchen": [ + { + "id": "018f3d5b-6688-7a34-b4ee-415cc8d2e42f", + "name": "Азиатская" + } + ], + "phone": [ + "7999999999" + ], + "email": [ + "test@mail.ru" + ], + "address": [ + "ул.Пушкина дом Колотушкина" + ], + "tags": [ + { + "name": "группа тегов 1", + "list": [ + "тег1", + "тег2" + ] + } + ], + "site": "https://visityamal.ru/", + "image": { + "id": "018f3d5b-6688-7a34-b4ee-415cc695d635", + "name": "asd", + "description": "Краткое описание", + "size": 1024, + "type": "png", + "url": "/upload/asd.png" + }, + "gallery": [ + { + "id": "018f3d5b-6688-7a34-b4ee-415cc695d635", + "name": "asd", + "description": "Краткое описание", + "size": 1024, + "type": "png", + "url": "/upload/asd.png" + } + ], + "seoTitle": "Отель Арктика", + "seoDescription": "otel-arktika", + "seoKeywords": "otel-arktika" +} \ No newline at end of file diff --git a/tests/responses/restaurantNotFound.json b/tests/responses/restaurantNotFound.json new file mode 100644 index 0000000..c2743d6 --- /dev/null +++ b/tests/responses/restaurantNotFound.json @@ -0,0 +1,4 @@ +{ + "success": false, + "message": "Restaurant not found" +} \ No newline at end of file diff --git a/tests/responses/restaurants.json b/tests/responses/restaurants.json new file mode 100644 index 0000000..43173e4 --- /dev/null +++ b/tests/responses/restaurants.json @@ -0,0 +1,44 @@ +{ + "pagination": { + "currentPage": 1, + "pages": 1, + "pageSize": 12 + }, + "list": [ + { + "id": "018f3d5b-6688-7a34-b4ee-415cc851d5fa", + "name": "Ресторан «Арктика»", + "code": "restoran-arktika", + "type": { + "id": "018f3d5b-6688-7a34-b4ee-415cc59ae55a", + "name": "Ресторан", + "code": "restoran" + }, + "check": "bla bla", + "image": { + "id": "018f3d5b-6688-7a34-b4ee-415cc695d635", + "name": "asd", + "description": "Краткое описание", + "size": 1024, + "type": "png", + "url": "/upload/asd.png" + }, + "detailLink": "https://visityamal.ru/" + } + ], + "filterVariants": { + "type": [ + { + "id": "018f3d5b-6688-7a34-b4ee-415cc59ae55a", + "name": "Ресторан", + "code": "restoran" + } + ], + "kitchen": [ + { + "id": "018f3d5b-6688-7a34-b4ee-415cc8d2e42f", + "name": "Азиатская" + } + ] + } +} \ No newline at end of file diff --git a/tests/responses/searchNews.json b/tests/responses/searchNews.json new file mode 100644 index 0000000..b75de05 --- /dev/null +++ b/tests/responses/searchNews.json @@ -0,0 +1,18 @@ +{ + "id": "018f3d5b-65c7-7998-a6d5-2270db52f830", + "name": "Два часа на знакомство с тысячелетней историей Ямала.", + "description": "Это самый большой музей на Ямале. Здесь вы найдете всё о жизни региона, традициях и обычаях народов севера и посетите виртуальную выставку, организованную по последнему слову современных технологий.", + "text": "Это самый большой музей на Ямале. Здесь вы найдете всё о жизни региона, традициях и обычаях народов севера и посетите виртуальную выставку, организованную по последнему слову современных технологий.", + "image": { + "id": "018f3d5b-65c7-7998-a6d5-2270da0797c7", + "name": "asd", + "description": "Краткое описание", + "size": 1024, + "type": "png", + "url": "/upload/asd.png" + }, + "createAt": "23.04.2024", + "seoTitle": "Отель Арктика", + "seoDescription": "otel-arktika", + "seoKeywords": "otel-arktika" +} \ No newline at end of file -- GitLab