diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..b6aa89d --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,33 @@ +version: '3' + +services: + mockserver: + image: mockserver/mockserver:latest + ports: + - "1080:1080" + volumes: + - ./tests/mocks:/config + environment: + MOCKSERVER_INITIALIZATION_JSON_PATH: /config/telegram_expectations.json + networks: + - test-network + + sysblokbot: + container_name: sysblokbot-test + build: + context: . + dockerfile: Dockerfile.dev + depends_on: + - mockserver + environment: + - ENVIRONMENT=local + - TELEGRAM_BASE_URL=http://mockserver:1080 + volumes: + - ./config_override.json:/app/config_override.json + networks: + - test-network + +networks: + test-network: + driver: bridge + diff --git a/tests/mocks/telegram_expectations.json b/tests/mocks/telegram_expectations.json new file mode 100644 index 0000000..2dcc5a4 --- /dev/null +++ b/tests/mocks/telegram_expectations.json @@ -0,0 +1,162 @@ +[ + { + "httpRequest": { + "method": "POST", + "path": "/bot.*/getMe" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "Content-Type": ["application/json"] + }, + "body": { + "ok": true, + "result": { + "id": 123456789, + "is_bot": true, + "first_name": "TestBot", + "username": "test_bot", + "can_join_groups": true, + "can_read_all_group_messages": false, + "supports_inline_queries": false + } + } + } + }, + { + "httpRequest": { + "method": "POST", + "path": "/bot.*/getUpdates" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "Content-Type": ["application/json"] + }, + "body": { + "ok": true, + "result": [] + } + } + }, + { + "httpRequest": { + "method": "POST", + "path": "/bot.*/sendMessage" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "Content-Type": ["application/json"] + }, + "body": { + "ok": true, + "result": { + "message_id": 1, + "from": { + "id": 123456789, + "is_bot": true, + "first_name": "TestBot", + "username": "test_bot" + }, + "chat": { + "id": 1, + "first_name": "Test", + "type": "private" + }, + "date": 1234567890, + "text": "Message sent" + } + } + } + }, + { + "httpRequest": { + "method": "GET", + "path": "/bot.*/sendMessage" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "Content-Type": ["application/json"] + }, + "body": { + "ok": true, + "result": { + "message_id": 1, + "from": { + "id": 123456789, + "is_bot": true, + "first_name": "TestBot", + "username": "test_bot" + }, + "chat": { + "id": 1, + "first_name": "Test", + "type": "private" + }, + "date": 1234567890, + "text": "Message sent" + } + } + } + }, + { + "httpRequest": { + "method": "GET", + "path": "/bot.*/sendPoll" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "Content-Type": ["application/json"] + }, + "body": { + "ok": true, + "result": { + "message_id": 2, + "from": { + "id": 123456789, + "is_bot": true, + "first_name": "TestBot", + "username": "test_bot" + }, + "chat": { + "id": 1, + "first_name": "Test", + "type": "private" + }, + "date": 1234567890, + "poll": { + "id": "poll123", + "question": "Test poll", + "options": [], + "total_voter_count": 0, + "is_closed": false, + "is_anonymous": true, + "type": "regular", + "allows_multiple_answers": false + } + } + } + } + }, + { + "httpRequest": { + "method": "POST", + "path": "/bot.*/deleteWebhook" + }, + "httpResponse": { + "statusCode": 200, + "headers": { + "Content-Type": ["application/json"] + }, + "body": { + "ok": true, + "result": true, + "description": "Webhook was deleted" + } + } + } +] +