diff --git a/.env b/.env index 679fb184e57080a3090e2bf4fa075c8db8ad41fd..bbb4151687a9d7b8904e9775e1975baa10537fe2 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 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/migrations/Version20240502094853.php b/migrations/Version20240503065723.php similarity index 97% rename from migrations/Version20240502094853.php rename to migrations/Version20240503065723.php index 1727aac28652f702d54ae004523e5a31bec461cd..bfdb5fee16029f1d16853d817f55d69f13c2ca1b 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 52bdd28bfe12389a23346e3cc8504649c7c4fdb4..a982f83781613bb5bfe85d6c80dd22135ecb0b03 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 23ade5987d82fd50c87649347211d974bc1e5640..a53f59770f4a8087ef8a99949f3d0a862fe46a9e 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 0000000000000000000000000000000000000000..4b9569a3715250b3a1a0ecf20d7dc9dfaa675a45 --- /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 c976e59bf2728d1c52634aaa9f24599fe85c90be..addf713339fee77c1cdf3d273d59b7344bc02ddd 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 0000000000000000000000000000000000000000..c8c82be409a88e44329f046895c46cae017ef4b3 --- /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 0000000000000000000000000000000000000000..5e5bd18b7c00e726513fa3deec36bb2482e292d2 --- /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 0000000000000000000000000000000000000000..c0d0369c708925429b49f3593d82595c36f6c95a --- /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 0000000000000000000000000000000000000000..b75de05b79c1da53522232305f0d4befb63eed4e --- /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 0000000000000000000000000000000000000000..e4ae7619b85e587d3142e0401a09d48e5a8ddfa9 --- /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 0000000000000000000000000000000000000000..c2743d6d1ecd7d9d3c32d163ee3ec92eb11094d4 --- /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 0000000000000000000000000000000000000000..43173e45615369004521e61f668613b0aaa2af06 --- /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 0000000000000000000000000000000000000000..b75de05b79c1da53522232305f0d4befb63eed4e --- /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