aboutsummaryrefslogtreecommitdiffstats
path: root/t/Mock/Twilio.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2017-12-20 01:06:27 +0100
committerMarius Halden <marius.h@lden.org>2017-12-20 01:06:27 +0100
commit8b10c8b8d787e680bb085e2a7543dac50fd39742 (patch)
tree391efde6de4944e350cc0dafbd4e1efb0613e9c3 /t/Mock/Twilio.pm
parenteef35397ccf8242cdc65dc666db2958b1ee35440 (diff)
parent7e15bd3db202363db4bab8fa7c9f462eabe28fce (diff)
Merge tag 'v2.3' into fiksgatami-dev
Diffstat (limited to 't/Mock/Twilio.pm')
-rw-r--r--t/Mock/Twilio.pm32
1 files changed, 32 insertions, 0 deletions
diff --git a/t/Mock/Twilio.pm b/t/Mock/Twilio.pm
new file mode 100644
index 000000000..125daa55f
--- /dev/null
+++ b/t/Mock/Twilio.pm
@@ -0,0 +1,32 @@
+package t::Mock::Twilio;
+
+use Web::Simple;
+
+has texts => (
+ is => 'ro',
+ default => sub { [] },
+);
+
+sub get_text_code {
+ my $self = shift;
+ my $text = shift @{$self->texts};
+ return unless $text;
+ my ($code) = $text->{Body} =~ /(\d+)/;
+ return $code;
+}
+
+sub dispatch_request {
+ my $self = shift;
+
+ sub (POST + /2010-04-01/Accounts/*/Messages.json + %*) {
+ my ($self, $sid, $data) = @_;
+ if ($data->{To} eq '+18165550101') {
+ return [ 400, [ 'Content-Type' => 'application/json' ],
+ [ '{"code":"21408", "message": "Unable to send"}' ] ];
+ }
+ push @{$self->texts}, $data;
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ '{}' ] ];
+ },
+}
+
+__PACKAGE__->run_if_script;