|
| 1 | +/* Copyright (c) 2020 The Brave Authors. All rights reserved. |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | + |
| 6 | +#include <utility> |
| 7 | + |
| 8 | +#include "base/test/task_environment.h" |
| 9 | +#include "bat/ledger/internal/ledger_client_mock.h" |
| 10 | +#include "bat/ledger/internal/ledger_impl_mock.h" |
| 11 | +#include "bat/ledger/internal/uphold/uphold.h" |
| 12 | +#include "bat/ledger/ledger.h" |
| 13 | +#include "bat/ledger/global_constants.h" |
| 14 | +#include "testing/gtest/include/gtest/gtest.h" |
| 15 | + |
| 16 | +// npm run test -- brave_unit_tests --filter=UpholdTest.* |
| 17 | + |
| 18 | +using ::testing::_; |
| 19 | +using std::placeholders::_1; |
| 20 | +using std::placeholders::_2; |
| 21 | + |
| 22 | +namespace braveledger_uphold { |
| 23 | + |
| 24 | +class UpholdTest : public testing::Test { |
| 25 | + private: |
| 26 | + base::test::TaskEnvironment scoped_task_environment_; |
| 27 | + |
| 28 | + protected: |
| 29 | + std::unique_ptr<ledger::MockLedgerClient> mock_ledger_client_; |
| 30 | + std::unique_ptr<bat_ledger::MockLedgerImpl> mock_ledger_impl_; |
| 31 | + std::unique_ptr<Uphold> uphold_; |
| 32 | + |
| 33 | + UpholdTest() { |
| 34 | + mock_ledger_client_ = std::make_unique<ledger::MockLedgerClient>(); |
| 35 | + mock_ledger_impl_ = |
| 36 | + std::make_unique<bat_ledger::MockLedgerImpl>(mock_ledger_client_.get()); |
| 37 | + uphold_ = std::make_unique<Uphold>(mock_ledger_impl_.get()); |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +TEST_F(UpholdTest, FetchBalanceConnectedWallet) { |
| 42 | + EXPECT_CALL(*mock_ledger_impl_, LoadURL(_, _, _, _, _, _)).Times(0); |
| 43 | + |
| 44 | + std::map<std::string, ledger::ExternalWalletPtr> wallets; |
| 45 | + |
| 46 | + auto wallet = ledger::ExternalWallet::New(); |
| 47 | + wallet->status = ledger::WalletStatus::CONNECTED; |
| 48 | + wallet->token = "token"; |
| 49 | + wallet->address = "address"; |
| 50 | + |
| 51 | + wallets.insert(std::make_pair(ledger::kWalletUphold, std::move(wallet))); |
| 52 | + |
| 53 | + FetchBalanceCallback callback = |
| 54 | + std::bind( |
| 55 | + [&](ledger::Result result, double balance) { |
| 56 | + ASSERT_EQ(result, ledger::Result::LEDGER_OK); |
| 57 | + ASSERT_EQ(balance, 0.0); |
| 58 | + }, |
| 59 | + _1, |
| 60 | + _2); |
| 61 | + |
| 62 | + uphold_->FetchBalance(std::move(wallets), callback); |
| 63 | +} |
| 64 | + |
| 65 | +} // namespace braveledger_uphold |
0 commit comments