Created
November 7, 2019 12:47
-
-
Save renatocron/ffd26823b7be01c8e6354335b16c51af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub test_callback { | |
my $promise = Mojo::Promise->new(); | |
my $req = Mojo::Message::Request->new; | |
my $id = Mojo::IOLoop->server( | |
{ address => '127.0.0.1' } => sub { | |
my ( $loop, $stream ) = @_; | |
$stream->on( | |
read => sub { | |
my ( $stream, $chunk ) = @_; | |
if ( $chunk =~ /webhook-url/ ) { | |
$stream->write( "HTTP/1.1 200 OK\x0d\x0a" . "Content-Length: 3\x0d\x0a\x0d\x0a" . 'Hi!' ); | |
$promise->resolve(); | |
} | |
else { | |
$stream->write( | |
"HTTP/1.1 404 Not Found\x0d\x0a" . "Content-Length: 3\x0d\x0a\x0d\x0a" . 'NO.' ); | |
$promise->reject(); | |
} | |
} | |
); | |
} | |
); | |
my $port = Mojo::IOLoop->acceptor($id)->port; | |
$ENV{CHATBOT_WEBHOOK_RELOAD_URL} = "http://127.0.0.1:$port/webhook-url"; | |
t->delete_ok( | |
'/ca/chatbots', | |
form => { | |
api_key => $ca_session, | |
page_id => '1321322', | |
} | |
)->status_is(204); | |
$promise->wait(); | |
is $promise->{status}, 'resolve', 'callback executed'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment