From c1fb530eea90fcf7c1c294b44d6d833e4dbcd809 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 24 Jun 2018 12:01:23 -0400 Subject: add scheduled transactions --- t/budget.t | 34 +++++++++++++++++++ t/lib/WWW/YNAB/MockUA.pm | 85 +++++++++++++++++++++++++++++++++++++++++++++-- t/scheduled_transaction.t | 55 ++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 t/scheduled_transaction.t (limited to 't') diff --git a/t/budget.t b/t/budget.t index 3886365..fe46d38 100644 --- a/t/budget.t +++ b/t/budget.t @@ -113,6 +113,40 @@ is($subtransactions[0]->category_id, "33333333-3333-3333-3333-444444444444"); is($subtransactions[0]->transfer_account_id, undef); ok(!$subtransactions[0]->deleted); +my @scheduled_transactions = $budget->scheduled_transactions; +is(scalar @scheduled_transactions, 1); +isa_ok($scheduled_transactions[0], 'WWW::YNAB::ScheduledTransaction'); +is($scheduled_transactions[0]->id, "66666666-6666-6666-6666-666666666666"); +is($scheduled_transactions[0]->date_first, "2018-06-05"); +is($scheduled_transactions[0]->date_next, "2018-07-05"); +is($scheduled_transactions[0]->frequency, "monthly"); +is($scheduled_transactions[0]->amount, -100000); +is($scheduled_transactions[0]->memo, "cable"); +is($scheduled_transactions[0]->flag_color, "purple"); +is($scheduled_transactions[0]->account_id, "00000000-0000-0000-0000-111111111111"); +is($scheduled_transactions[0]->payee_id, undef); +is($scheduled_transactions[0]->category_id, "33333333-3333-3333-3333-666666666666"); +is($scheduled_transactions[0]->transfer_account_id, undef); +ok(!$scheduled_transactions[0]->deleted); +is($scheduled_transactions[0]->account_name, "Checking Account"); +is($scheduled_transactions[0]->payee_name, undef); +# this is i think a bug in their api - they don't return a category object for +# "split" even though they have a category id for it, and the name shows up in +# the direct transaction/scheduled_transaction individual object request +is($scheduled_transactions[0]->category_name, undef); +is(scalar $scheduled_transactions[0]->subtransactions, 2); + +my @scheduled_subtransactions = $scheduled_transactions[0]->subtransactions; +is(scalar @scheduled_subtransactions, 2); +is($scheduled_subtransactions[0]->id, "77777777-7777-7777-7777-777777777777"); +is($scheduled_subtransactions[0]->scheduled_transaction_id, "66666666-6666-6666-6666-666666666666"); +is($scheduled_subtransactions[0]->amount, -50000); +is($scheduled_subtransactions[0]->memo, "tv"); +is($scheduled_subtransactions[0]->payee_id, undef); +is($scheduled_subtransactions[0]->category_id, "33333333-3333-3333-3333-444444444444"); +is($scheduled_subtransactions[0]->transfer_account_id, undef); +ok(!$scheduled_subtransactions[0]->deleted); + is(scalar $ua->test_requests, 1); done_testing; diff --git a/t/lib/WWW/YNAB/MockUA.pm b/t/lib/WWW/YNAB/MockUA.pm index 24519cd..1827111 100644 --- a/t/lib/WWW/YNAB/MockUA.pm +++ b/t/lib/WWW/YNAB/MockUA.pm @@ -377,8 +377,44 @@ EOF "deleted": false } ], - "scheduled_transactions": [], - "scheduled_subtransactions": [] + "scheduled_transactions": [ + { + "id": "66666666-6666-6666-6666-666666666666", + "date_first": "2018-06-05", + "date_next": "2018-07-05", + "frequency": "monthly", + "amount": -100000, + "memo": "cable", + "flag_color": "purple", + "account_id": "00000000-0000-0000-0000-111111111111", + "payee_id": null, + "category_id": "33333333-3333-3333-3333-666666666666", + "transfer_account_id": null, + "deleted": false + } + ], + "scheduled_subtransactions": [ + { + "id": "77777777-7777-7777-7777-777777777777", + "scheduled_transaction_id": "66666666-6666-6666-6666-666666666666", + "amount": -50000, + "memo": "tv", + "payee_id": null, + "category_id": "33333333-3333-3333-3333-444444444444", + "transfer_account_id": null, + "deleted": false + }, + { + "id": "77777777-7777-7777-7777-888888888888", + "scheduled_transaction_id": "66666666-6666-6666-6666-666666666666", + "amount": -50000, + "memo": "internet", + "payee_id": null, + "category_id": "33333333-3333-3333-3333-444444444444", + "transfer_account_id": null, + "deleted": false + } + ] }, "server_knowledge": 1 } @@ -533,6 +569,51 @@ EOF } } } +EOF + 'https://api.youneedabudget.com/v1/budgets/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/scheduled_transactions/66666666-6666-6666-6666-666666666666' => <<'EOF', +{ + "data": { + "scheduled_transaction": { + "id": "66666666-6666-6666-6666-666666666666", + "date_first": "2018-06-05", + "date_next": "2018-07-05", + "frequency": "monthly", + "amount": -100000, + "memo": "cable", + "flag_color": "purple", + "account_id": "00000000-0000-0000-0000-111111111111", + "account_name": "Checking Account", + "payee_id": null, + "payee_name": null, + "category_id": "33333333-3333-3333-3333-666666666666", + "category_name": "Split (Multiple Categories)...", + "transfer_account_id": null, + "deleted": false, + "subtransactions": [ + { + "id": "77777777-7777-7777-7777-777777777777", + "scheduled_transaction_id": "66666666-6666-6666-6666-666666666666", + "amount": -50000, + "memo": "tv", + "payee_id": null, + "category_id": "33333333-3333-3333-3333-444444444444", + "transfer_account_id": null, + "deleted": false + }, + { + "id": "77777777-7777-7777-7777-888888888888", + "scheduled_transaction_id": "66666666-6666-6666-6666-666666666666", + "amount": -50000, + "memo": "internet", + "payee_id": null, + "category_id": "33333333-3333-3333-3333-444444444444", + "transfer_account_id": null, + "deleted": false + } + ] + } + } +} EOF ); diff --git a/t/scheduled_transaction.t b/t/scheduled_transaction.t new file mode 100644 index 0000000..98960ea --- /dev/null +++ b/t/scheduled_transaction.t @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use lib 't/lib'; + +use WWW::YNAB; +use WWW::YNAB::MockUA; + +my $ua = WWW::YNAB::MockUA->new; +my $ynab = WWW::YNAB->new( + access_token => 'abcdef', + ua => $ua, +); + +is(scalar $ua->test_requests, 0); + +my $budget = $ynab->budget('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'); +is(scalar $ua->test_requests, 1); +isa_ok($budget, 'WWW::YNAB::Budget'); + +my $scheduled_transaction = $budget->scheduled_transaction('66666666-6666-6666-6666-666666666666'); +is(scalar $ua->test_requests, 2); +isa_ok($scheduled_transaction, 'WWW::YNAB::ScheduledTransaction'); + +is($scheduled_transaction->id, "66666666-6666-6666-6666-666666666666"); +is($scheduled_transaction->date_first, "2018-06-05"); +is($scheduled_transaction->date_next, "2018-07-05"); +is($scheduled_transaction->frequency, "monthly"); +is($scheduled_transaction->amount, -100000); +is($scheduled_transaction->memo, "cable"); +is($scheduled_transaction->flag_color, "purple"); +is($scheduled_transaction->account_id, "00000000-0000-0000-0000-111111111111"); +is($scheduled_transaction->payee_id, undef); +is($scheduled_transaction->category_id, "33333333-3333-3333-3333-666666666666"); +is($scheduled_transaction->transfer_account_id, undef); +ok(!$scheduled_transaction->deleted); +is($scheduled_transaction->account_name, "Checking Account"); +is($scheduled_transaction->payee_name, undef); +is($scheduled_transaction->category_name, "Split (Multiple Categories)..."); +is(scalar $scheduled_transaction->subtransactions, 2); + +my @scheduled_subtransactions = $scheduled_transaction->subtransactions; +is(scalar @scheduled_subtransactions, 2); +is($scheduled_subtransactions[0]->id, "77777777-7777-7777-7777-777777777777"); +is($scheduled_subtransactions[0]->scheduled_transaction_id, "66666666-6666-6666-6666-666666666666"); +is($scheduled_subtransactions[0]->amount, -50000); +is($scheduled_subtransactions[0]->memo, "tv"); +is($scheduled_subtransactions[0]->payee_id, undef); +is($scheduled_subtransactions[0]->category_id, "33333333-3333-3333-3333-444444444444"); +is($scheduled_subtransactions[0]->transfer_account_id, undef); +ok(!$scheduled_subtransactions[0]->deleted); + +done_testing; -- cgit v1.2.3-54-g00ecf