<commit_before><?php

namespace Amelia\Test\Monzo;

use Amelia\Monzo\{Client, Monzo};
use Amelia\Monzo\Models\{Account, Transaction};
use Carbon\Carbon;
use Illuminate\Support\Collection;
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client as Guzzle;
use VCR\VCR;

class AccountsTest extends TestCase
{
    protected static $user;
    protected static $token;
    protected static $account;
    protected static $integrationUser;
    protected static $integrationToken;
    protected static $integrationAccount;

    public function testAccountsEndpoint()
    {
        VCR::insertCassette('accounts');

        $monzo = new Monzo(new Client(new Guzzle));

        $accounts = $monzo->as(static::$token)->accounts();

        $this->assertInstanceOf(Collection::class, $accounts);
        $this->assertCount(1, $accounts);
        $this->assertContainsOnly(Account::class, $accounts);

        $account = $accounts->first();

        $this->assertEquals(static::$account, $account->id);
        $this->assertInstanceOf(Carbon::class, $account->created);
        $this->assertNotNull($account->description);
    }

    public function testTransactionsEndpoint()
    {
        VCR::insertCassette('transactions');

        $monzo = new Monzo(new Client(new Guzzle));

        $transactions = $monzo->as(static::$token)
            ->since('2016-01-01T00:00:00Z')
            ->take(25)
            ->transactions(static::$account);

        $this->assertInstanceOf(Collection::class, $transactions);

        $this->assertContainsOnly(Transaction::class, $transactions);
    }

    public function testDefaultTransactionsEndpoint()
    {
        VCR::insertCassette('transactions');

        $monzo = new Monzo(new Client(new Guzzle));

        $transactions = $monzo->as(static::$token)
            ->since('2016-01-01T00:00:00Z')
            ->take(25)
            ->transactions();

        dd($transactions);

        $this->assertInstanceOf(Collection::class, $transactions);

        $this->assertContainsOnly(Transaction::class, $transactions);
    }

    public function testTransactionsEndpointLimiting()
    {
        VCR::insertCassette('transactions');

        $monzo = new Monzo(new Client(new Guzzle));

        $transactions = $monzo->as(static::$token)
            ->take(20)
            ->since('2016-01-01T00:00:00Z')
            ->transactions(static::$account);

        $this->assertInstanceOf(Collection::class, $transactions);

        $this->assertCount(20, $transactions);

        $this->assertContainsOnly(Transaction::class, $transactions);
    }

    public function testTransactionsEndpointLimitingWithoutAccount()
    {
        VCR::insertCassette('transactions');

        $monzo = new Monzo(new Client(new Guzzle));

        $transactions = $monzo->as(static::$token)
            ->take(20)
            ->since('2016-01-01T00:00:00Z')
            ->transactions();

        $this->assertInstanceOf(Collection::class, $transactions);

        $this->assertCount(20, $transactions);

        $this->assertContainsOnly(Transaction::class, $transactions);
    }

    public function testSingleTransaction()
    {
        VCR::insertCassette('single_transaction');

        $monzo = new Monzo(new Client(new Guzzle));

        // grab a single transaction
        $transaction = $monzo->as(static::$token)
            ->take(1)
            ->since('2016-01-01T00:00:00Z')
            ->transactions(static::$account)
            ->first();

        // grab the ID

        $result = $monzo->as(static::$token)->transaction($transaction->id);

        $this->assertEquals($transaction->id, $result->id);
    }

    /**
     * @expectedException \Amelia\Monzo\Exceptions\AccessTokenExpired
     */
    public function testInvalidAccessTokens()
    {
        VCR::insertCassette('invalid_access_token');

        $monzo = new Monzo(new Client(new Guzzle));

        $monzo->as('bad-access-token')->accounts();
    }

    public function testFetchingBalance()
    {
        VCR::insertCassette('balance');

        $monzo = new Monzo(new Client(new Guzzle));

        $balance = $monzo->as(static::$token)->balance();

        $this->assertEquals(6394, $balance->balance);
        $this->assertEquals('GBP', $balance->currency);
    }

    public function testFetchingBalanceWithAccount()
    {
        VCR::insertCassette('balance');

        $monzo = new Monzo(new Client(new Guzzle));

        $balance = $monzo->as(static::$token)->balance(static::$account);

        $this->assertEquals(6394, $balance->balance);
        $this->assertEquals('GBP', $balance->currency);
    }

    public static function setUpBeforeClass()
    {
        // set these when adding new tests to get a real response
        static::$integrationToken = getenv('MONZO_TEST_ACCESS_TOKEN');
        static::$integrationAccount = getenv('MONZO_TEST_ACCOUNT');
        static::$integrationUser = getenv('MONZO_TEST_USER');

        static::$token = 'valid-access-token';
        static::$account = 'acc_test';
        static::$user = 'user_test';
    }
}
<commit_msg>Remove a stray dd() call<commit_after><?php

namespace Amelia\Test\Monzo;

use Amelia\Monzo\{Client, Monzo};
use Amelia\Monzo\Models\{Account, Transaction};
use Carbon\Carbon;
use Illuminate\Support\Collection;
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client as Guzzle;
use VCR\VCR;

class AccountsTest extends TestCase
{
    protected static $user;
    protected static $token;
    protected static $account;
    protected static $integrationUser;
    protected static $integrationToken;
    protected static $integrationAccount;

    public function testAccountsEndpoint()
    {
        VCR::insertCassette('accounts');

        $monzo = new Monzo(new Client(new Guzzle));

        $accounts = $monzo->as(static::$token)->accounts();

        $this->assertInstanceOf(Collection::class, $accounts);
        $this->assertCount(1, $accounts);
        $this->assertContainsOnly(Account::class, $accounts);

        $account = $accounts->first();

        $this->assertEquals(static::$account, $account->id);
        $this->assertInstanceOf(Carbon::class, $account->created);
        $this->assertNotNull($account->description);
    }

    public function testTransactionsEndpoint()
    {
        VCR::insertCassette('transactions');

        $monzo = new Monzo(new Client(new Guzzle));

        $transactions = $monzo->as(static::$token)
            ->since('2016-01-01T00:00:00Z')
            ->take(25)
            ->transactions(static::$account);

        $this->assertInstanceOf(Collection::class, $transactions);

        $this->assertContainsOnly(Transaction::class, $transactions);
    }

    public function testDefaultTransactionsEndpoint()
    {
        VCR::insertCassette('transactions');

        $monzo = new Monzo(new Client(new Guzzle));

        $transactions = $monzo->as(static::$token)
            ->since('2016-01-01T00:00:00Z')
            ->take(25)
            ->transactions();

        $this->assertInstanceOf(Collection::class, $transactions);

        $this->assertContainsOnly(Transaction::class, $transactions);
    }

    public function testTransactionsEndpointLimiting()
    {
        VCR::insertCassette('transactions');

        $monzo = new Monzo(new Client(new Guzzle));

        $transactions = $monzo->as(static::$token)
            ->take(20)
            ->since('2016-01-01T00:00:00Z')
            ->transactions(static::$account);

        $this->assertInstanceOf(Collection::class, $transactions);

        $this->assertCount(20, $transactions);

        $this->assertContainsOnly(Transaction::class, $transactions);
    }

    public function testTransactionsEndpointLimitingWithoutAccount()
    {
        VCR::insertCassette('transactions');

        $monzo = new Monzo(new Client(new Guzzle));

        $transactions = $monzo->as(static::$token)
            ->take(20)
            ->since('2016-01-01T00:00:00Z')
            ->transactions();

        $this->assertInstanceOf(Collection::class, $transactions);

        $this->assertCount(20, $transactions);

        $this->assertContainsOnly(Transaction::class, $transactions);
    }

    public function testSingleTransaction()
    {
        VCR::insertCassette('single_transaction');

        $monzo = new Monzo(new Client(new Guzzle));

        // grab a single transaction
        $transaction = $monzo->as(static::$token)
            ->take(1)
            ->since('2016-01-01T00:00:00Z')
            ->transactions(static::$account)
            ->first();

        // grab the ID

        $result = $monzo->as(static::$token)->transaction($transaction->id);

        $this->assertEquals($transaction->id, $result->id);
    }

    /**
     * @expectedException \Amelia\Monzo\Exceptions\AccessTokenExpired
     */
    public function testInvalidAccessTokens()
    {
        VCR::insertCassette('invalid_access_token');

        $monzo = new Monzo(new Client(new Guzzle));

        $monzo->as('bad-access-token')->accounts();
    }

    public function testFetchingBalance()
    {
        VCR::insertCassette('balance');

        $monzo = new Monzo(new Client(new Guzzle));

        $balance = $monzo->as(static::$token)->balance();

        $this->assertEquals(6394, $balance->balance);
        $this->assertEquals('GBP', $balance->currency);
    }

    public function testFetchingBalanceWithAccount()
    {
        VCR::insertCassette('balance');

        $monzo = new Monzo(new Client(new Guzzle));

        $balance = $monzo->as(static::$token)->balance(static::$account);

        $this->assertEquals(6394, $balance->balance);
        $this->assertEquals('GBP', $balance->currency);
    }

    public static function setUpBeforeClass()
    {
        // set these when adding new tests to get a real response
        static::$integrationToken = getenv('MONZO_TEST_ACCESS_TOKEN');
        static::$integrationAccount = getenv('MONZO_TEST_ACCOUNT');
        static::$integrationUser = getenv('MONZO_TEST_USER');

        static::$token = 'valid-access-token';
        static::$account = 'acc_test';
        static::$user = 'user_test';
    }
}

{'fraction_non_alphanumeric': 0.14702104535124988, 'fraction_numerical': 0.01818002173698251, 'mean_word_length': 2.974087161366313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3089666', 'n_tokens_mistral': 3079, 'n_tokens_neox': 2882, 'n_words': 481}