Skip to content

Commit

Permalink
Merge pull request #1968 from brave-intl/staging
Browse files Browse the repository at this point in the history
Release 2019-06-12
  • Loading branch information
yachtcaptain23 authored Jun 12, 2019
2 parents eb8477a + 5b81419 commit 4b1bcbf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
14 changes: 7 additions & 7 deletions app/models/channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,25 @@ def self.find_by_channel_identifier(channel_identifier)
channel_details_type_identifier = channel_id_split_on_prefix.first
return SiteChannelDetails.where(brave_publisher_id: channel_details_type_identifier).
joins(:channel).
where('channels.verified = true').first.channel
where('channels.verified = true').first&.channel
end

prefix = channel_id_split_on_prefix.first
channel_details_type_identifier = channel_id_split_on_prefix.second
case prefix
when "youtube#channel"
YoutubeChannelDetails.where(youtube_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first.channel
YoutubeChannelDetails.where(youtube_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first&.channel
when "twitter#channel"
TwitterChannelDetails.where(twitter_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first.channel
TwitterChannelDetails.where(twitter_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first&.channel
when "vimeo#channel"
VimeoChannelDetails.where(vimeo_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first.channel
VimeoChannelDetails.where(vimeo_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first&.channel
when "reddit#channel"
RedditChannelDetails.where(reddit_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first.channel
RedditChannelDetails.where(reddit_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first&.channel
when "github#channel"
GithubChannelDetails.where(github_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first.channel
GithubChannelDetails.where(github_channel_id: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first&.channel
when "twitch#channel"
when "twitch#author"
TwitchChannelDetails.where(name: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first.channel
TwitchChannelDetails.where(name: channel_details_type_identifier).joins(:channel).where('channels.verified = true').first&.channel
else
Rails.logger.info("Unable to find channel for channel identifier #{channel_identifier}")
nil
Expand Down
2 changes: 1 addition & 1 deletion app/models/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def wallet
# Sync the default_currency to eyeshade, if they are mismatched
# ToDo: This can be eliminated once eyeshade no longer maintains a default_currency
# (which should be after publishers is driving payout report generation)
if default_currency.present? && default_currency != @_wallet.default_currency
if default_currency.present? && @_wallet.address.present? && default_currency != @_wallet.default_currency
UploadDefaultCurrencyJob.perform_later(publisher_id: id)
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/publisher_statement_getter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def replace_account_identifiers_with_titles(transactions)
transaction["channel"] = "Manual"
else
channel = Channel.find_by_channel_identifier(account_identifier)
transaction["channel"] = channel.publication_title
transaction["channel"] = channel&.publication_title || account_identifier
end
transaction
}
Expand Down
14 changes: 11 additions & 3 deletions test/models/publisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,24 @@ class PublisherTest < ActiveSupport::TestCase
assert publisher.save
end

test "when wallet is gotten the default currency will be sent to eyeshade if it is mismatched" do
test "when wallet has an address, a job will set the default currency on eyeshade if it is mismatched" do
Rails.application.secrets[:api_eyeshade_offline] = false
publisher = publishers(:verified)
publisher.default_currency = "USD"

wallet = {
defaultCurrency: "CAD"
defaultCurrency: "CAD",
address: ""
}
stub_all_eyeshade_wallet_responses(publisher: publisher, wallet: { wallet: wallet })
assert_no_enqueued_jobs

stub_all_eyeshade_wallet_responses(publisher: publisher, wallet: wallet)
wallet = {
defaultCurrency: "CAD",
address: "12345-67890"
}

stub_all_eyeshade_wallet_responses(publisher: publisher, wallet: { wallet: wallet })

assert_enqueued_with(job: UploadDefaultCurrencyJob) do
publisher.wallet.default_currency
Expand Down

0 comments on commit 4b1bcbf

Please sign in to comment.