aboutsummaryrefslogtreecommitdiffstats
path: root/t/Mock/Facebook.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2016-03-28 20:38:28 +0200
committerMarius Halden <marius.h@lden.org>2016-03-28 20:38:28 +0200
commit6c1118dbf2c4b15bcfcd77600d36f2389428c75e (patch)
treeda81756a344a89502df5479b860b6f4a24b6ed92 /t/Mock/Facebook.pm
parenta2d67ca6de255ff04badb7cb5a62f7d3df3ce293 (diff)
parent4345263c9de752454795ad57323e684e41e702a8 (diff)
Merge tag 'v1.8.1' into fiksgatami-dev
Diffstat (limited to 't/Mock/Facebook.pm')
-rw-r--r--t/Mock/Facebook.pm52
1 files changed, 52 insertions, 0 deletions
diff --git a/t/Mock/Facebook.pm b/t/Mock/Facebook.pm
new file mode 100644
index 000000000..eb882af21
--- /dev/null
+++ b/t/Mock/Facebook.pm
@@ -0,0 +1,52 @@
+package t::Mock::Facebook;
+
+use JSON::MaybeXS;
+use Web::Simple;
+use MooX::Types::MooseLike::Base qw(:all);
+
+has json => (
+ is => 'lazy',
+ default => sub {
+ JSON->new->pretty->allow_blessed->convert_blessed;
+ },
+);
+
+has returns_email => (
+ is => 'rw',
+ isa => Bool,
+ default => 1,
+);
+
+sub dispatch_request {
+ my $self = shift;
+
+ sub (GET + /v2.2/dialog/oauth + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/html' ], [ 'FB login page' ] ];
+ },
+
+ sub (GET + /v2.2/oauth/access_token + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'access_token=access_token&expires=never' ] ];
+ },
+
+ sub (GET + /me + ?fields=) {
+ my ($self, $fields) = @_;
+ my $data = {
+ id => '123456789',
+ name => 'Fiona Tester',
+ };
+ $data->{email} = 'facebook@example.org' if $self->returns_email;
+ my $json = $self->json->encode($data);
+ return [ 200, [ 'Content-Type' => 'text/html' ], [ $json ] ];
+ },
+
+ sub (GET + /search + ?q=) {
+ my ($self, $q) = @_;
+ my $response = $self->query($q);
+ my $json = $self->json->encode($response);
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
+}
+
+__PACKAGE__->run_if_script;