/* test
Author: Giménez, Christian.
Copyright (C) 2019 Giménez, Christian
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
07 aug 2019
*/
:- module(telegrambot_test, [
test_pred/2
]).
/** telegrambot_test:
@author Christian Gimenez
@license GPLv3
*/
:- license(gplv3).
:- use_module('../prolog/telegrambot').
test_pred(_Message, _Params) :-
asserta(telegrambot_test:test_passed).
test_pred_b(_Message, _Params) :-
asserta(telegrambot_test:test_passed_b).
:- command_handler(start, telegrambot_test:test_pred).
:- command_handler(next, telegrambot_test:test_pred_b).
%% :- use_token('').
%% :- command_handler('start', help).
%% help(Message, Params) :-
%% member(chat=json(ChatData), Message),
%% member(id=ChatID, ChatData),
%% send_message(ChatID, 'Hello!', [], _R).
:- begin_tests(telegrambot, []).
test(use_token) :-
use_token('hello world'),
telegrambot:token('hello world').
test(is_command, []) :-
Msg = json([ update_id = 381390181,
message = json([ (message_id = 1),
(from = json([ (id = 1234567),
(is_bot = @(false)),
(first_name = 'first'),
(username = 'user'),
(language_code = en)
])),
(chat = json([ (id = 1234567),
(first_name = 'First'),
(username = 'user'),
(type = private)
])),
(date = 1565066895),
(text = '/start'),
(entities =
[json([offset=0,length=6,type=bot_command])])
])
]),
telegrambot:is_command(Msg, Cmd, Params),
Cmd = start,
Params = [].
test(process_update_message, []) :-
retractall(telegrambot_test:test_passed),
Msg = json([ update_id = 381390181,
message = json([ (message_id = 1),
(from = json([ (id = 1234567),
(is_bot = @(false)),
(first_name = 'first'),
(username = 'user'),
(language_code = en)
])),
(chat = json([ (id = 1234567),
(first_name = 'First'),
(username = 'user'),
(type = private)
])),
(date = 1565066895),
(text = '/start'),
(entities =
[json([offset=0,length=6,type=bot_command])])
])
]),
telegrambot:process_update_message(Msg),
telegrambot_test:test_passed.
test(process_update_json, []) :-
retractall(telegrambot_test:test_passed),
retractall(telegrambot_test:test_passed_b),
Msg1 = json([update_id=38298123,
message=json([message_id=1,
from=json([id=1234567,
is_bot= @(false),
first_name='first',
username='user',
language_code=en]),
chat=json([id=234567,
first_name='first',
username='user',
type=private]),
date=1570374390,
text='/start',
entities=[json([offset=0,
length=6,
type=bot_command
])]])]),
Msg2 = json([update_id=38298124,
message=json([message_id=2,
from=json([id=87654,
is_bot= @(false),
first_name='first',
username='user',
language_code=en]),
chat=json([id=234567,
first_name='first',
username='user',
type=private]),
date=1570374417,
text='/next',
entities=[json([offset=0,
length=5,
type=bot_command
])]])]),
Update = json([ok= @(true),
result=[
Msg1, Msg2
]]),
telegrambot:process_update_json(Update),
telegrambot_test:test_passed,
telegrambot_test:test_passed_b.
:- end_tests(telegrambot).