Skip to content

Commit

Permalink
merge 002_end_to_end and 004_end_to_end_LIVE
Browse files Browse the repository at this point in the history
so we can run the same test against both emulator and live API
  • Loading branch information
leejo committed Aug 21, 2016
1 parent 5eae2ff commit c0f3188
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 187 deletions.
1 change: 0 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mondo_emulator.pl
t/001_compiles_pod.t
t/002_end_to_end.t
t/003_changes.t
t/004_end_to_end_LIVE.t
t/business/mondo.t
t/business/mondo/account.t
t/business/mondo/address.t
Expand Down
20 changes: 15 additions & 5 deletions end_to_end_emulated.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#!/bin/bash

set -x -e

port=$1

if [ "$port" == "" ]; then
port=3000
fi

set -u

# start emulator
morbo mondo_emulator.pl -l 'https://*:3000' &
morbo mondo_emulator.pl -l "https://*:$port" &
sleep 2;

# get an access token (requires httpie here)
ACCESS_TOKEN=$(http --verify no --form POST "https://127.0.0.1:3000/oauth2/token" \
# get an access token
ACCESS_TOKEN=$(http --verify no --form POST "https://127.0.0.1:$port/oauth2/token" \
"grant_type=password" \
"client_id=test_client" \
"client_secret=test_client_secret" \
Expand All @@ -18,9 +28,9 @@ ACCESS_TOKEN=$(http --verify no --form POST "https://127.0.0.1:3000/oauth2/token
MONDO_DEBUG=1 \
MONDO_ENDTOEND=1 \
MONDO_TOKEN=$ACCESS_TOKEN \
MONDO_URL='https://127.0.0.1:3000' \
MONDO_URL="https://127.0.0.1:$port" \
SKIP_CERT_CHECK=1 \
prove -v -Ilib t/002_end_to_end.t

# stop emulator
pkill -f 'morbo mondo_emulator';
pkill -lf 'mondo_emulator';
3 changes: 3 additions & 0 deletions lib/Business/Mondo/Client.pm
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ sub _api_request {
}

if ( $tx->success ) {
carp( "RES: " . Dumper $tx->res->json )
if $ENV{MONDO_DEBUG};

return $tx->res->json;
}
else {
Expand Down
2 changes: 2 additions & 0 deletions lib/Business/Mondo/Currency.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ has [ qw/ currency local_currency / ] => (
coerce => sub {
my ( $args ) = @_;

return undef if ! $args;

if ( ! ref( $args ) ) {
$args = Data::Currency->new({
code => $args,
Expand Down
2 changes: 1 addition & 1 deletion mondo_emulator.pl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
"user_id" => "user_00009238aMBIIrS5Rdncq9",
"external_id" => $external_id,
"file_url" => $file_url,
"file_type" => "image/png",
"file_type" => $file_type,
"created" => "2015-11-12T18:37:02Z"
}
} );
Expand Down
90 changes: 51 additions & 39 deletions t/002_end_to_end.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,64 @@ $ENV{MONDO_DEBUG} = 1;
note( "Mondo" );
my $Mondo = Business::Mondo->new(
token => $token,
api_url => $url
( $url ? ( api_url => $url ) : () ),
);

isa_ok( $Mondo,'Business::Mondo' );

note( "Transaction" );
note( "Account" );
my @accounts = $Mondo->accounts;

isa_ok(
my $Transaction = $Mondo->transaction( id => 1, expand => 'merchant' ),
'Business::Mondo::Transaction'
my $Account = $accounts[0],
'Business::Mondo::Account'
);

my @transactions = $Mondo->transactions( account_id => $Account->id );

isa_ok(
$Transaction->get,
my $Transaction = $transactions[0],
'Business::Mondo::Transaction',
);

note( "Transaction" );
isa_ok(
$Transaction->attachments->[1],
'Business::Mondo::Attachment',
$Transaction = $Mondo->transaction(
id => $Transaction->id,
expand => 'merchant'
),
'Business::Mondo::Transaction'
);

isa_ok(
$Transaction->annotate( foo => 'bar' ),
$Transaction->get,
'Business::Mondo::Transaction',
);

cmp_deeply(
$Transaction->annotations,
{
stuff => 'yes',
more_stuff => 'yep',
},
'->annotations',
);
my $time = time;

isa_ok(
( $Mondo->transactions( account_id => 1 ) )[1],
$Transaction = $Transaction->annotate(
testing_at => $time,
),
'Business::Mondo::Transaction',
);

note( "Account" );
isa_ok(
my $Account = ( $Mondo->accounts )[0],
'Business::Mondo::Account',
cmp_deeply(
my $annotations = $Transaction->annotations,
{
testing_at => $time,
},
'->annotations',
);

ok( $Account->add_feed_item(
params => {
title => 'foo',
image_url => 'bar',
}
url => 'https://metacpan.org/release/Business-Mondo',
params => {
title => 'Hello from the perl API client',
image_url => 'http://pix.iemoji.com/images/emoji/apple/ios-9/256/dromedary-camel.png',
body => '🐪',
}
),'->add_feed_item' );

note( "Webhook" );
Expand All @@ -90,16 +97,19 @@ isa_ok( my $Webhook = $Account->register_webhook(
),'Business::Mondo::Webhook' );

ok( my @webhooks = $Account->webhooks,'->webhooks' );
ok( $Webhook->delete,'->delete' );

foreach $Webhook ( @webhooks ) {
ok( $Webhook->delete,'->delete' );
}

note( "Balance" );
isa_ok(
my $Balance = $Mondo->balance( account_id => 1 ),
my $Balance = $Mondo->balance( account_id => $Account->id ),
'Business::Mondo::Balance'
);

is( $Balance->account_id,'1','->account_id' );
is( $Balance->balance,5000,'->balance' );
like( $Balance->account_id,qr/acc_0000/,'->account_id' );
ok( $Balance->balance,'->balance' );
isa_ok( $Balance->currency,'Data::Currency','->currency' );
is( $Balance->spend_today,0,'->spend_today' );

Expand All @@ -111,21 +121,23 @@ isa_ok( my $Attachment = $Mondo->upload_attachment(

is( $Attachment->file_name,'foo.png','->file_name' );
is( $Attachment->file_type,'image/png','->file_type' );
is( $Attachment->file_url,'https://127.0.0.1:3000/file/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png','->file_url' );
is( $Attachment->upload_url,'https://127.0.0.1:3000/upload/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png?AWSAccessKeyId=AKIAIR3IFH6UCTCXB5PQ0026Expires=14473534310026Signature=k2QeDCCQQHaZeynzYKckejqXRGU%!D(MISSING)','->upload_url' );
like( $Attachment->file_url,qr/^http/,'->file_url' );
like( $Attachment->upload_url,qr/^http/,'->upload_url' );

isa_ok( $Attachment = $Attachment->register(
external_id => 'my_id'
external_id => $Transaction->id,
file_url => 'http://www.nyan.cat/cats/original.gif',
file_type => 'image/gif',
),'Business::Mondo::Attachment' );

is( $Attachment->user_id,'user_00009238aMBIIrS5Rdncq9','->user_id' );
like( $Attachment->user_id,qr/user_/,'->user_id' );
isa_ok( $Attachment->created,'DateTime' );
is( $Attachment->external_id,'my_id','->id' );
is( $Attachment->id,'attach_00009238aOAIvVqfb9LrZh','->id' );
is( $Attachment->file_name,'foo.png','->file_name' );
is( $Attachment->file_type,'image/png','->file_type' );
is( $Attachment->file_url,'https://127.0.0.1:3000/file/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png','->file_url' );
is( $Attachment->upload_url,'https://127.0.0.1:3000/upload/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png?AWSAccessKeyId=AKIAIR3IFH6UCTCXB5PQ0026Expires=14473534310026Signature=k2QeDCCQQHaZeynzYKckejqXRGU%!D(MISSING)','->upload_url' );
is( $Attachment->external_id,$Transaction->id,'->id' );
like( $Attachment->id,qr/attach_/,'->id' );
ok( $Attachment->file_name,'->file_name' );
is( $Attachment->file_type,'image/gif','->file_type' );
like( $Attachment->file_url,qr/^http/,'->file_url' );
like( $Attachment->upload_url,qr/^http/,'->upload_url' );

ok( $Attachment->deregister,'->deregister' );

Expand Down
141 changes: 0 additions & 141 deletions t/004_end_to_end_LIVE.t

This file was deleted.

0 comments on commit c0f3188

Please sign in to comment.