Skip to content

Commit

Permalink
[ads] Unit test code health
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Oct 30, 2024
1 parent 4d4272b commit e6e34fb
Show file tree
Hide file tree
Showing 30 changed files with 219 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h"

#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_info.h"
#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ads_database_util.h"
#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h"
#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h"

namespace brave_ads::test {

Expand All @@ -18,4 +20,12 @@ InlineContentAdInfo BuildInlineContentAd(
return BuildInlineContentAd(creative_ad);
}

InlineContentAdInfo BuildAndSaveInlineContentAd(
const bool should_generate_random_uuids) {
const CreativeInlineContentAdInfo creative_ad =
BuildCreativeInlineContentAd(should_generate_random_uuids);
database::SaveCreativeInlineContentAds({creative_ad});
return BuildInlineContentAd(creative_ad);
}

} // namespace brave_ads::test
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_
#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_

namespace brave_ads {

Expand All @@ -14,8 +14,11 @@ namespace test {

InlineContentAdInfo BuildInlineContentAd(bool should_generate_random_uuids);

InlineContentAdInfo BuildAndSaveInlineContentAd(
bool should_generate_random_uuids);

} // namespace test

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_
#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_INLINE_CONTENT_AD_INLINE_CONTENT_AD_TEST_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h"

#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_info.h"
#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ads_database_util.h"
#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h"

namespace brave_ads::test {

Expand All @@ -17,4 +19,12 @@ NewTabPageAdInfo BuildNewTabPageAd(const bool should_generate_random_uuids) {
return BuildNewTabPageAd(creative_ad);
}

NewTabPageAdInfo BuildAndSaveNewTabPageAd(
const bool should_generate_random_uuids) {
const CreativeNewTabPageAdInfo creative_ad =
BuildCreativeNewTabPageAd(should_generate_random_uuids);
database::SaveCreativeNewTabPageAds({creative_ad});
return BuildNewTabPageAd(creative_ad);
}

} // namespace brave_ads::test
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_
#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_

namespace brave_ads {

Expand All @@ -14,8 +14,10 @@ namespace test {

NewTabPageAdInfo BuildNewTabPageAd(bool should_generate_random_uuids);

NewTabPageAdInfo BuildAndSaveNewTabPageAd(bool should_generate_random_uuids);

} // namespace test

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_
#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NEW_TAB_PAGE_AD_NEW_TAB_PAGE_AD_TEST_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h"

#include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_info.h"
#include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ads_database_util.h"
#include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_builder.h"
#include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_manager.h"
#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h"

namespace brave_ads::test {

Expand All @@ -18,4 +21,14 @@ NotificationAdInfo BuildNotificationAd(
return BuildNotificationAd(creative_ad);
}

NotificationAdInfo BuildAndSaveNotificationAd(
const bool should_generate_random_uuids) {
const CreativeNotificationAdInfo creative_ad =
BuildCreativeNotificationAd(should_generate_random_uuids);
database::SaveCreativeNotificationAds({creative_ad});
const NotificationAdInfo ad = BuildNotificationAd(creative_ad);
NotificationAdManager::GetInstance().Add(ad);
return ad;
}

} // namespace brave_ads::test
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_
#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_

namespace brave_ads {

Expand All @@ -14,8 +14,11 @@ namespace test {

NotificationAdInfo BuildNotificationAd(bool should_generate_random_uuids);

NotificationAdInfo BuildAndSaveNotificationAd(
bool should_generate_random_uuids);

} // namespace test

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_
#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_NOTIFICATION_AD_NOTIFICATION_AD_TEST_UTIL_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_test_util.h"

#include "brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_info.h"
#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_info.h"
#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ads_database_util.h"
#include "brave/components/brave_ads/core/internal/creatives/promoted_content_ads/promoted_content_ad_builder.h"

namespace brave_ads::test {

PromotedContentAdInfo BuildPromotedContentAd(
const bool should_generate_random_uuids) {
const CreativePromotedContentAdInfo creative_ad =
BuildCreativePromotedContentAd(should_generate_random_uuids);
return BuildPromotedContentAd(creative_ad);
}

PromotedContentAdInfo BuildAndSavePromotedContentAd(
const bool should_generate_random_uuids) {
const CreativePromotedContentAdInfo creative_ad =
BuildCreativePromotedContentAd(should_generate_random_uuids);
database::SaveCreativePromotedContentAds({creative_ad});
return BuildPromotedContentAd(creative_ad);
}

} // namespace brave_ads::test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_PROMOTED_CONTENT_AD_PROMOTED_CONTENT_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_PROMOTED_CONTENT_AD_PROMOTED_CONTENT_AD_TEST_UTIL_H_

namespace brave_ads {

struct PromotedContentAdInfo;

namespace test {

PromotedContentAdInfo BuildPromotedContentAd(bool should_generate_random_uuids);

PromotedContentAdInfo BuildAndSavePromotedContentAd(
bool should_generate_random_uuids);

} // namespace test

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_PROMOTED_CONTENT_AD_PROMOTED_CONTENT_AD_TEST_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h"

#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_builder.h"
#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_info.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_
#ifndef BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_
#define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_

namespace brave_ads {

Expand All @@ -18,4 +18,4 @@ SearchResultAdInfo BuildSearchResultAd(bool should_generate_random_uuids);

} // namespace brave_ads

#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_PUBLIC_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_
#endif // BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_AD_UNITS_SEARCH_RESULT_AD_SEARCH_RESULT_AD_TEST_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "brave/components/brave_ads/core/internal/ad_units/promoted_content_ad/promoted_content_ad_info.h"
#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_builder.h"
#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_info.h"
#include "brave/components/brave_ads/core/internal/ad_units/search_result_ad/search_result_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/common/test/test_base.h"
#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h"
Expand All @@ -24,7 +25,6 @@
#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/search_result_ad/search_result_ad_test_util.h"
#include "brave/components/brave_ads/core/public/history/ad_history_item_info.h"

// npm run test -- brave_unit_tests --filter=BraveAds*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

#include "brave/components/brave_ads/core/internal/serving/eligible_ads/allocation/seen_ads_util.h"

#include "brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/common/test/time_test_util.h"
#include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_builder.h"
#include "brave/components/brave_ads/core/mojom/brave_ads.mojom.h"
#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

// npm run test -- brave_unit_tests --filter=BraveAds*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "brave/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_day_permission_rule.h"

#include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_feature.h"
#include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/common/test/test_base.h"
#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h"
#include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h"
#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h"

// npm run test -- brave_unit_tests --filter=BraveAds*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "brave/components/brave_ads/core/internal/serving/permission_rules/inline_content_ads/inline_content_ads_per_hour_permission_rule.h"

#include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_feature.h"
#include "brave/components/brave_ads/core/internal/ad_units/inline_content_ad/inline_content_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/common/test/test_base.h"
#include "brave/components/brave_ads/core/internal/creatives/inline_content_ads/inline_content_ad_builder.h"
#include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h"
#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/inline_content_ad/inline_content_ad_test_util.h"

// npm run test -- brave_unit_tests --filter=BraveAds*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "brave/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_minimum_wait_time_permission_rule.h"

#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h"
#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/common/test/test_base.h"
#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h"
#include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h"

// npm run test -- brave_unit_tests --filter=BraveAds*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "brave/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_day_permission_rule.h"

#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h"
#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/common/test/test_base.h"
#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h"
#include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h"

// npm run test -- brave_unit_tests --filter=BraveAds*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "brave/components/brave_ads/core/internal/serving/permission_rules/new_tab_page_ads/new_tab_page_ads_per_hour_permission_rule.h"

#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_feature.h"
#include "brave/components/brave_ads/core/internal/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/common/test/test_base.h"
#include "brave/components/brave_ads/core/internal/creatives/new_tab_page_ads/new_tab_page_ad_builder.h"
#include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/new_tab_page_ad/new_tab_page_ad_test_util.h"

// npm run test -- brave_unit_tests --filter=BraveAds*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

#include "brave/components/brave_ads/core/internal/serving/permission_rules/notification_ads/notification_ads_per_day_permission_rule.h"

#include "brave/components/brave_ads/core/internal/ad_units/notification_ad/notification_ad_test_util.h"
#include "brave/components/brave_ads/core/internal/common/test/test_base.h"
#include "brave/components/brave_ads/core/internal/creatives/notification_ads/notification_ad_builder.h"
#include "brave/components/brave_ads/core/internal/user_engagement/ad_events/ad_event_test_util.h"
#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_feature.h"
#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_info.h"
#include "brave/components/brave_ads/core/public/ad_units/notification_ad/notification_ad_test_util.h"

// npm run test -- brave_unit_tests --filter=BraveAds*

Expand Down
Loading

0 comments on commit e6e34fb

Please sign in to comment.