Skip to content

Commit

Permalink
WIP additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Dec 20, 2018
1 parent a0150c8 commit d4ef111
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 125 deletions.
49 changes: 10 additions & 39 deletions components/brave_rewards/browser/publisher_info_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,48 +80,18 @@ class PublisherInfoDatabase {

std::string GetDiagnosticInfo(int extended_error, sql::Statement* statement);

private:
// private
FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
Init);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
CreateContributionInfoTable);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
CreateContributionInfoIndex);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
CreatePublisherInfoTable);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
CreateActivityInfoTable);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
CreateActivityInfoIndex);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
CreateMediaPublisherInfoTable);
bool Init();

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
CreateRecurringDonationTable);
sql::Database& GetDB();

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
CreateRecurringDonationIndex);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
GetDB);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
MigrateV1toV2);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
MigrateV2toV3);
private:
// FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
// Init);
//
// FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
// GetDB);

FRIEND_TEST_ALL_PREFIXES(PublisherInfoDatabaseTest,
EnsureCurrentVersion);

bool Init();

bool CreateContributionInfoTable();

Expand All @@ -142,7 +112,8 @@ class PublisherInfoDatabase {
void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);

sql::Database& GetDB();



sql::MetaTable& GetMetaTable();

Expand Down
108 changes: 29 additions & 79 deletions components/brave_rewards/browser/publisher_info_database_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "sql/database.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

// npm run test -- brave_unit_tests --PublisherInfoDatabaseTest.*
// npm run test -- brave_unit_tests --filter=PublisherInfoDatabaseTest.*

namespace brave_rewards {

Expand Down Expand Up @@ -46,9 +47,7 @@ class PublisherInfoDatabaseTest : public ::testing::Test {

publisher_info_database_ = std::make_unique<PublisherInfoDatabase>(db_file);
ASSERT_TRUE(publisher_info_database_);

db_ = publisher_info_database_->GetDB();
ASSERT_TRUE(db_);
ASSERT_TRUE(GetDB());
}

void TearDown() override {
Expand All @@ -63,133 +62,84 @@ class PublisherInfoDatabaseTest : public ::testing::Test {
return path.value();
}

std::unique_ptr<PublisherInfoDatabase> publisher_info_database_;
sql::Database& GetDB() {
return publisher_info_database_->GetDB();
}

sql::Database db_;
std::unique_ptr<PublisherInfoDatabase> publisher_info_database_;
};

TEST_F(PublisherInfoDatabaseTest, InsertContributionInfoTest) {
TEST_F(PublisherInfoDatabaseTest, InsertContributionInfo) {
ContributionInfo info;
info.probi = "12345678901234567890123456789012345678901234";
info.month = ledger::ACTIVITY_MONTH::JANUARY;
info.year = 1970;
info.category = ledger::REWARDS_CATEGORY::AUTO_CONTRIBUTE;
info.date = base::Time::UnixEpoch();
info.date = base::Time::Now().ToJsTime();
info.publisher_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

bool success = publisher_info_database_->InsertContributionInfo(info);
EXPECT_TRUE(success);

sql::Statement info_sql(db_.GetUniqueStatement(
"SELECT publisher_id FROM publisher_info WHERE publisher_id=?"));
std::string query = "SELECT * FROM contribution_info WHERE publisher_id=?";
sql::Statement info_sql(GetDB().GetUniqueStatement(query.c_str()));

info_sql.BindString(0, info.publisher_key);

EXPECT_TRUE(info_sql.Step());
// EXPECT_EQ(info_sql.ColumnString(0), info.publisher_key);
// EXPECT_EQ(info_sql.ColumnString(1), info.probi);
// EXPECT_EQ(info_sql.ColumnInt64(2), info.date);
// EXPECT_EQ(info_sql.ColumnInt(3), info.category);
// EXPECT_EQ(info_sql.ColumnInt(4), info.month);
// EXPECT_EQ(info_sql.ColumnInt(5), info.year);
}

TEST_F(PublisherInfoDatabaseTest, GetTipsTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, InsertOrUpdatePublisherInfoTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, GetPublisherInfoTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, GetPanelPublisherTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, RestorePublishersTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfoTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, GetActivityListTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateMediaPublisherInfoTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, GetMediaPublisherInfoTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateRecurringDonationTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, GetRecurringDonationsTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, RemoveRecurringTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, GetCurrentVersionTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, VacuumTest) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, GetDiagnosticInfoTest) {
TEST_F(PublisherInfoDatabaseTest, GetTips) {
EXPECT_TRUE(false);
}

// private
TEST_F(PublisherInfoDatabaseTest, CreateContributionInfoTableTest) {
TEST_F(PublisherInfoDatabaseTest, InsertOrUpdatePublisherInfo) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, CreateContributionInfoIndexTest) {
TEST_F(PublisherInfoDatabaseTest, GetPublisherInfo) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, CreatePublisherInfoTableTest) {
TEST_F(PublisherInfoDatabaseTest, GetPanelPublisher) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, CreateActivityInfoTableTest) {
TEST_F(PublisherInfoDatabaseTest, RestorePublishers) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, CreateActivityInfoIndexTest) {
TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateActivityInfo) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, CreateMediaPublisherInfoTableTest) {
TEST_F(PublisherInfoDatabaseTest, GetActivityList) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, CreateRecurringDonationTableTest) {
TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateMediaPublisherInfo) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, CreateRecurringDonationIndexTest) {
TEST_F(PublisherInfoDatabaseTest, GetMediaPublisherInfo) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, MigrateV1toV2Test) {
TEST_F(PublisherInfoDatabaseTest, InsertOrUpdateRecurringDonation) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, MigrateV2toV3Test) {
TEST_F(PublisherInfoDatabaseTest, GetRecurringDonations) {
EXPECT_TRUE(false);
}

TEST_F(PublisherInfoDatabaseTest, EnsureCurrentVersion) {
TEST_F(PublisherInfoDatabaseTest, RemoveRecurring) {
EXPECT_TRUE(false);
}

Expand Down
14 changes: 7 additions & 7 deletions components/brave_rewards/browser/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MockLedgerClient : public ledger::Ledger {
void(std::unique_ptr<ledger::PublisherInfo> publisher_info,
ledger::PublisherInfoCallback callback));

MOCK_METHOD2(GetPublisherInfo, void(const ledger::PublisherInfoFilter& filter,
MOCK_METHOD2(GetPublisherInfo, void(const ledger::ActivityInfoFilter& filter,
ledger::PublisherInfoCallback callback));

MOCK_METHOD2(SetMediaPublisherInfo, void(const std::string& media_key,
Expand All @@ -96,7 +96,7 @@ class MockLedgerClient : public ledger::Ledger {
MOCK_METHOD4(GetPublisherInfoList, void(
uint32_t start,
uint32_t limit,
const ledger::PublisherInfoFilter& filter,
const ledger::ActivityInfoFilter& filter,
ledger::PublisherInfoListCallback callback));

MOCK_METHOD1(SetRewardsMainEnabled, void(bool enabled));
Expand All @@ -116,7 +116,7 @@ class MockLedgerClient : public ledger::Ledger {
MOCK_METHOD1(SetAutoContribute, void(bool enabled));

MOCK_METHOD3(SetBalanceReport, void(
ledger::PUBLISHER_MONTH month,
ledger::ACTIVITY_MONTH month,
int year,
const ledger::BalanceReportInfo& report_info));

Expand Down Expand Up @@ -158,7 +158,7 @@ class MockLedgerClient : public ledger::Ledger {
MOCK_CONST_METHOD0(GetWalletPassphrase, std::string());

MOCK_CONST_METHOD3(GetBalanceReport, bool(
ledger::PUBLISHER_MONTH month,
ledger::ACTIVITY_MONTH month,
int year,
ledger::BalanceReportInfo* report_info));

Expand Down Expand Up @@ -189,7 +189,7 @@ class MockLedgerClient : public ledger::Ledger {
uint64_t windowId,
const ledger::VisitData& visit_data));

MOCK_METHOD4(SetBalanceReportItem, void(ledger::PUBLISHER_MONTH month,
MOCK_METHOD4(SetBalanceReportItem, void(ledger::ACTIVITY_MONTH month,
int year,
ledger::ReportType type,
const std::string& probi));
Expand All @@ -202,9 +202,9 @@ class MockLedgerClient : public ledger::Ledger {

MOCK_METHOD6(OnReconcileCompleteSuccess, void(
const std::string& viewing_id,
const ledger::PUBLISHER_CATEGORY category,
const ledger::REWARDS_CATEGORY category,
const std::string& probi,
const ledger::PUBLISHER_MONTH month,
const ledger::ACTIVITY_MONTH month,
const int year,
const uint32_t date));

Expand Down

0 comments on commit d4ef111

Please sign in to comment.