Skip to content

Commit 275437c

Browse files
committed
test: add integration tests
Fix #1
1 parent a71c063 commit 275437c

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
node_modules/
2+
3+
# RobotFramework reports
4+
tests/log.html
5+
tests/output.xml
6+
tests/report.html

docker/categories.sql

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE TABLE `categories` (
2+
`id` int(11) NOT NULL AUTO_INCREMENT,
3+
`name` varchar(50) NOT NULL,
4+
`name_ru` varchar(50) DEFAULT NULL,
5+
`slug` varchar(50) NOT NULL,
6+
`created_at` datetime NOT NULL,
7+
`created_by` int(11) NOT NULL,
8+
`updated_at` datetime NOT NULL,
9+
`updated_by` int(11) NOT NULL,
10+
PRIMARY KEY (`id`),
11+
UNIQUE KEY `name` (`name`),
12+
UNIQUE KEY `uc_categories_slug` (`slug`),
13+
UNIQUE KEY `name_ru` (`name_ru`)
14+
) ENGINE=InnoDB CHARSET=utf8;

docker/docker-compose.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Usage example:
2+
#
3+
# $ docker-compose up -d
4+
# $ docker-compose exec mysql mysql -u test -ptest test
5+
#
6+
version: '3'
7+
8+
services:
9+
mysql:
10+
image: mysql:5.7.20
11+
user: mysql:mysql
12+
environment:
13+
- MYSQL_ROOT_PASSWORD=secret
14+
- MYSQL_USER=test
15+
- MYSQL_PASSWORD=test
16+
- MYSQL_DATABASE=test
17+
ports:
18+
- '3306:3306'
19+
volumes:
20+
- ./categories.sql:/docker-entrypoint-initdb.d/categories.sql
21+

tests/crud.robot

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
*** Settings ***
2+
Documentation Basic CRUD operations
3+
Library RequestsLibrary
4+
Suite Setup Create Session alias=api url=${SERVER_URL}
5+
Suite Teardown Delete All Sessions
6+
7+
*** Variables ***
8+
${SERVER_URL} http://host.docker.internal:3000
9+
10+
** Test Cases ***
11+
GET should return a value
12+
${response}= Get Request api /v1/categories/count
13+
Status Should Be 200 ${response}
14+
Should Be Equal As Integers 0 ${response.json()}
15+
16+
POST should create an object
17+
&{payload}= Create Dictionary name=Sport slug=sport userId=1
18+
${response}= Post Request api /v1/categories json=${payload}
19+
Status Should Be 204 ${response}
20+
# checks that it was created
21+
${response}= Get Request api /v1/categories/count
22+
Status Should Be 200 ${response}
23+
Should Be Equal As Integers 1 ${response.json()}
24+
25+
PUT should update an object
26+
&{payload}= Create Dictionary name=Fauna nameRu=Фауна slug=fauna userId=1 categoryId=1
27+
${response}= Put Request api /v1/categories/1 json=${payload}
28+
Status Should Be 204 ${response}
29+
30+
DELETE should remove an object
31+
${response}= Delete Request api /v1/categories/1
32+
Status Should Be 204 ${response}
33+
# checks that it was removed
34+
${response}= Get Request api /v1/categories/count
35+
Status Should Be 200 ${response}
36+
Should Be Equal As Integers 0 ${response.json()}

0 commit comments

Comments
 (0)