ソースを参照

Work on #4: Playwright::Util 100%

George S. Baugh 5 年 前
コミット
90d3114727
1 ファイル変更24 行追加0 行削除
  1. 24 0
      t/Playwright-Util.t

+ 24 - 0
t/Playwright-Util.t

@@ -0,0 +1,24 @@
+use Test2::V0 -target => 'Playwright::Base';
+use Test2::Tools::Explain;
+use Playwright::Util;
+use Test::MockModule qw{strict};
+
+my $lwpmock = Test::MockModule->new('LWP::UserAgent');
+$lwpmock->redefine('request', sub {
+    return bless({},'BogusResponse');
+});
+
+no warnings qw{redefine once};
+my $json = '{ "error":true, "message":"waa"}';
+local *BogusResponse::decoded_content = sub {
+    return $json;
+};
+use warnings;
+
+like( dies { Playwright::Util::request('tickle','chase',666, LWP::UserAgent->new(), a => 'b' ) }, qr/waa/i, "Bad response from server = BOOM");
+
+$json = '{ "error":false, "message": { "_type":"Bogus", "_guid":"abc123" } }';
+
+is(Playwright::Util::request('tickle','chase',666, LWP::UserAgent->new(), a => 'b' ), { _type => 'Bogus', _guid => 'abc123' }, "Good response from server decoded and returned");
+
+done_testing();