From e211b36f7fd8ddc03516c572726560015867277f Mon Sep 17 00:00:00 2001 From: Jennifer Byrne Date: Fri, 10 May 2024 09:00:23 -0500 Subject: [PATCH] add tests --- Gemfile | 4 +- Gemfile.lock | 4 +- .../publicChannelPage/CryptoPaymentWidget.jsx | 4 +- config/secrets.yml | 4 +- ...test_can_display_description_and_title.yml | 51 ++++++++++++++++++ .../test_can_select_different_currencies.yml | 53 +++++++++++++++++++ test/cassettes/test_can_update_amounts.yml | 53 +++++++++++++++++++ test/features/public_page_test.rb | 51 ++++++++++++++++++ 8 files changed, 217 insertions(+), 7 deletions(-) create mode 100644 test/cassettes/test_can_display_description_and_title.yml create mode 100644 test/cassettes/test_can_select_different_currencies.yml create mode 100644 test/cassettes/test_can_update_amounts.yml create mode 100644 test/features/public_page_test.rb diff --git a/Gemfile b/Gemfile index a07aaed94c..5bc35b91bd 100644 --- a/Gemfile +++ b/Gemfile @@ -199,7 +199,7 @@ group :test do gem "database_cleaner" # API recording and playback gem "vcr" - gem "webmock", "~> 3.0" + gem "webmock", "~> 3.23" gem "rails-controller-testing" # Image information library @@ -231,7 +231,7 @@ group :development, :test do gem "minitest-rails", github: "brave-intl/minitest-rails", branch: "rails71" gem "mocha", require: false gem "simplecov", require: false, group: :test - gem "selenium-webdriver", "~> 4.12" + gem "selenium-webdriver", "~> 4.4" gem "solargraph" gem "dotenv-rails", "3.1.0" end diff --git a/Gemfile.lock b/Gemfile.lock index a5a06138d1..fa6bf0de84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -809,7 +809,7 @@ DEPENDENCIES rotp (~> 6.3.0) rqrcode (~> 2.2.0) sass-rails (>= 6) - selenium-webdriver (~> 4.12) + selenium-webdriver (~> 4.4) sendgrid-ruby (~> 6.7) shakapacker (= 7.2.2) sidekiq (~> 7.2) @@ -830,7 +830,7 @@ DEPENDENCIES vcr web-console webauthn - webmock (~> 3.0) + webmock (~> 3.23) will_paginate yt (~> 0.33) zeitwerk (~> 2.6) diff --git a/app/javascript/views/publicChannelPage/CryptoPaymentWidget.jsx b/app/javascript/views/publicChannelPage/CryptoPaymentWidget.jsx index 500913555a..b5ac01f08f 100644 --- a/app/javascript/views/publicChannelPage/CryptoPaymentWidget.jsx +++ b/app/javascript/views/publicChannelPage/CryptoPaymentWidget.jsx @@ -420,7 +420,8 @@ class CryptoPaymentWidget extends React.Component { const amount = Math.round(this.calculateCryptoPrice() * Math.pow(10, decimal)); // this is the account address that will receive bat const destinationAccountOwner = new PublicKey(this.state.addresses.SOL) - const connection = new Connection(this.state.solanaMainUrl) + console.log('https://publishers.basicattentiontoken.org/rpc') + const connection = new Connection('https://publishers.basicattentiontoken.org/rpc') // Check to see if the sender has an associated token account const senderAccount = await connection.getParsedTokenAccountsByOwner(sourceAccountOwner, { mint: new PublicKey(contractAddress), @@ -557,6 +558,7 @@ class CryptoPaymentWidget extends React.Component { ), Option: CryptoPaymentOption }} + className='crypto-currency-dropdown' value={this.state.selectValue} styles={{ control: (base) => ({ ...base, diff --git a/config/secrets.yml b/config/secrets.yml index 6bb6706575..a53c0da484 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -235,8 +235,8 @@ test: sendgrid_publishers_list_id: 3986776 slack_webhook_url: false # Ratios, also needed for VCR tests - # bat_ratios_token: <%= ENV["BAT_RATIOS_TOKEN"] %> - # bat_ratios_url: <%= ENV["BAT_RATIOS_URL"] %> + bat_ratios_token: <%= ENV["BAT_RATIOS_TOKEN"] %> + bat_ratios_url: <%= ENV["BAT_RATIOS_URL"] %> # Bitflyer env variables bitflyer_host: "https://localhost/bitflyertest" bitflyer_client_id: "client_id_abc123" diff --git a/test/cassettes/test_can_display_description_and_title.yml b/test/cassettes/test_can_display_description_and_title.yml new file mode 100644 index 0000000000..97330ec68a --- /dev/null +++ b/test/cassettes/test_can_display_description_and_title.yml @@ -0,0 +1,51 @@ +--- +http_interactions: +- request: + method: get + uri: https://ratios.rewards.bravesoftware.com/v2/relative/provider/coingecko/eth,sol,bat/usd/live + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v2.9.0 + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Content-Length: + - '200' + Connection: + - keep-alive + Date: + - Mon, 20 May 2024 06:13:29 GMT + Cache-Control: + - max-age=899 + Request-Id: + - cp5ek2cqbpn9baab4ir0 + X-Request-Id: + - C38pMaXKzRDytQNE + X-Cache: + - Miss from cloudfront + Via: + - 1.1 efe54e8b68e074d39b2ecd249f85100a.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO50-C1 + X-Amz-Cf-Id: + - Ijo233Y2LHb43XZA87gBtdv3-64CT6ANXBlvsNvVaJE1xj-wGdG4Ow== + body: + encoding: UTF-8 + string: '{"payload":{"bat":{"usd":0.2395,"usd_timeframe_change":0},"eth":{"usd":3110.28,"usd_timeframe_change":0},"sol":{"usd":177.31,"usd_timeframe_change":0}},"lastUpdated":"2024-05-20T06:13:29.552704258Z"} + + ' + recorded_at: Mon, 20 May 2024 06:13:36 GMT +recorded_with: VCR 6.2.0 diff --git a/test/cassettes/test_can_select_different_currencies.yml b/test/cassettes/test_can_select_different_currencies.yml new file mode 100644 index 0000000000..038b6cc7d7 --- /dev/null +++ b/test/cassettes/test_can_select_different_currencies.yml @@ -0,0 +1,53 @@ +--- +http_interactions: +- request: + method: get + uri: https://ratios.rewards.bravesoftware.com/v2/relative/provider/coingecko/eth,sol,bat/usd/live + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v2.9.0 + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Content-Length: + - '200' + Connection: + - keep-alive + Date: + - Mon, 20 May 2024 06:13:29 GMT + Cache-Control: + - max-age=899 + Request-Id: + - cp5ek2cqbpn9baab4ir0 + X-Request-Id: + - C38pMaXKzRDytQNE + X-Cache: + - Hit from cloudfront + Via: + - 1.1 0005a84c2971ff4f5bbb79e7ebc622a8.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO50-C1 + X-Amz-Cf-Id: + - a3sfh_N-YPwEAeyY_dddYMM4B1c8VjU5I6kJ2vgQkHgyj0qFmXqbTw== + Age: + - '113' + body: + encoding: UTF-8 + string: '{"payload":{"bat":{"usd":0.2395,"usd_timeframe_change":0},"eth":{"usd":3110.28,"usd_timeframe_change":0},"sol":{"usd":177.31,"usd_timeframe_change":0}},"lastUpdated":"2024-05-20T06:13:29.552704258Z"} + + ' + recorded_at: Mon, 20 May 2024 06:15:29 GMT +recorded_with: VCR 6.2.0 diff --git a/test/cassettes/test_can_update_amounts.yml b/test/cassettes/test_can_update_amounts.yml new file mode 100644 index 0000000000..305a63fae9 --- /dev/null +++ b/test/cassettes/test_can_update_amounts.yml @@ -0,0 +1,53 @@ +--- +http_interactions: +- request: + method: get + uri: https://ratios.rewards.bravesoftware.com/v2/relative/provider/coingecko/eth,sol,bat/usd/live + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Faraday v2.9.0 + Content-Type: + - application/json + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json + Content-Length: + - '200' + Connection: + - keep-alive + Date: + - Mon, 20 May 2024 06:13:29 GMT + Cache-Control: + - max-age=899 + Request-Id: + - cp5ek2cqbpn9baab4ir0 + X-Request-Id: + - C38pMaXKzRDytQNE + X-Cache: + - Hit from cloudfront + Via: + - 1.1 a20e81b65d2465c729ce2f6bfe539dd0.cloudfront.net (CloudFront) + X-Amz-Cf-Pop: + - HIO50-C1 + X-Amz-Cf-Id: + - Yq_rBa9Hsi5ek5D6SGcUAjZgUjfFgW3KQse-kcXk5kDkZFcIRy0Rig== + Age: + - '115' + body: + encoding: UTF-8 + string: '{"payload":{"bat":{"usd":0.2395,"usd_timeframe_change":0},"eth":{"usd":3110.28,"usd_timeframe_change":0},"sol":{"usd":177.31,"usd_timeframe_change":0}},"lastUpdated":"2024-05-20T06:13:29.552704258Z"} + + ' + recorded_at: Mon, 20 May 2024 06:15:31 GMT +recorded_with: VCR 6.2.0 diff --git a/test/features/public_page_test.rb b/test/features/public_page_test.rb new file mode 100644 index 0000000000..3f41c7fdda --- /dev/null +++ b/test/features/public_page_test.rb @@ -0,0 +1,51 @@ +# typed: false + +require "test_helper" +require "webmock/minitest" +require "vcr" + +class PublicPageTest < Capybara::Rails::TestCase + include ActionMailer::TestHelper + include Rails.application.routes.url_helpers + + def setup + ActionController::Base.allow_forgery_protection = true + end + + def teardown + ActionController::Base.allow_forgery_protection = false + end + + test "redirects to home page if channel identifier not found" do + visit public_channel_path(public_identifier: "107zsxjfg6") + assert_content page, "Earn more for content you publish to the web" + end + + test "can display description and title" do + VCR.use_cassette("test_can_display_description_and_title") do + visit public_channel_path(public_identifier: "123456dfg6") + assert_content page, "Channel Banner" + assert_content page, "Lorem Ipsum" + assert_content page, "Show your love and send a token of your gratitude" + end + end + + test "can select different currencies" do + VCR.use_cassette("test_can_select_different_currencies") do + visit public_channel_path(public_identifier: "123456dfg6") + assert_content page, "20.87683 BAT" + find(".crypto-currency-dropdown", text: "ERC-20 BAT").click + find("#react-select-2-option-1-0", text: "Solana").click + assert_content page, "0.0282 SOL" + end + end + + test "can update amounts" do + VCR.use_cassette("test_can_update_amounts") do + visit public_channel_path(public_identifier: "123456dfg6") + assert_content page, "20.87683 BAT" + find("button", text: "$10").click + assert_content page, "41.75365 BAT" + end + end +end