Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test ci #38

Merged
merged 11 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,40 @@ jobs:

- name: erb-lint Check
run: bundle exec erblint --lint-all
test:
runs-on: ubuntu-latest
env:
RAILS_ENV: test
steps:
- uses: actions/checkout@v3

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler: default
bundler-cache: true

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18"
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build assets
run: bin/vite build --clear --mode=test

- name: Prepare database
run: |
bin/rails db:create
bin/rails db:schema:load

- name: Run tests
run: |
bin/rails test
bin/rails test:system

# - name: Smoke test database seeds
# run: sudo bin/rails db:reset
15 changes: 8 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/rails/rails.git
revision: 48e17e5ce75a02a331e6b48769d9c75243269696
revision: a5fc471b3f4bbd02e6be38dae023526a49e7d049
branch: main
specs:
actioncable (7.1.0.alpha)
Expand Down Expand Up @@ -172,7 +172,7 @@ GEM
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.6.0)
irb (1.7.0)
irb (1.7.1)
reline (>= 0.3.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
Expand Down Expand Up @@ -212,11 +212,11 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.2-aarch64-linux)
nokogiri (1.15.3-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.2-arm64-darwin)
nokogiri (1.15.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.2-x86_64-linux)
nokogiri (1.15.3-x86_64-linux)
racc (~> 1.4)
oj (3.15.0)
pagy (6.0.4)
Expand Down Expand Up @@ -244,8 +244,9 @@ GEM
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
rails-dom-testing (2.1.1)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
Expand Down
12 changes: 7 additions & 5 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class EventsController < ApplicationController
skip_before_action :authenticate_user!, only: %i[index show]
skip_before_action :authenticate_user!, only: %i[index show update]
before_action :set_event, only: %i[show edit update]

# GET /events
Expand All @@ -17,8 +17,10 @@ def edit

# PATCH/PUT /events/1
def update
if @event.update(event_params)
redirect_to @event, notice: "Event was successfully updated."
suggestion = @event.create_suggestion_from(params: event_params, user: Current.user)

if suggestion.persisted?
redirect_to event_path(@event), notice: suggestion.notice
else
render :edit, status: :unprocessable_entity
end
Expand All @@ -28,11 +30,11 @@ def update

# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find_by(slug: params[:slug])
@event = Event.find_by!(slug: params[:slug])
end

# Only allow a list of trusted parameters through.
def event_params
params.require(:event).permit(:name, :description, :website, :kind, :frequency)
params.require(:event).permit(:name, :city, :country_code)
end
end
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
# rubocop:enable Layout/LineLength
class Event < ApplicationRecord
include Suggestable
include Sluggable
slug_from :name

Expand Down
22 changes: 22 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
require "test_helper"
require "webdrivers"

Capybara.register_driver :headless_chrome do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument("--headless") unless ActiveModel::Type::Boolean.new.cast(ENV["HEADFUL"])
options.add_argument("--window-size=1920,1080")

client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 240

Capybara::Selenium::Driver.new(app, browser: :chrome, capabilities: [options], http_client: client)
end

Capybara.javascript_driver = :headless_chrome

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
Expand All @@ -12,4 +26,12 @@ def sign_in_as(user)
assert_current_path root_url
user
end

def wait_for_turbo(timeout = 2)
if has_css?(".turbo-progress-bar", visible: true, wait: 0.25.seconds)
has_no_css?(".turbo-progress-bar", wait: timeout)
end
end
end

Capybara.default_max_wait_time = 5 # Set the wait time in seconds
4 changes: 2 additions & 2 deletions test/clients/youtube/channels_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ class Youtube::ChannelsTest < ActiveSupport::TestCase
end

test "should retreive the channel id from the user name" do
VCR.use_cassette("youtube/channels") do
VCR.use_cassette("youtube/channels", match_requests_on: [:method]) do
channel_id = Youtube::Channels.new.id_by_name(channel_name: "confreaks")
assert_equal "UCWnPjmqvljcafA0z2U1fwKQ", channel_id
end
end

test "should retreive the channel id from the user name with dash" do
VCR.use_cassette("youtube/channels-scrapping") do
VCR.use_cassette("youtube/channels-scrapping", match_requests_on: [:method]) do
channel_id = Youtube::Channels.new.id_by_name(channel_name: "paris-rb")
assert_equal "UCFKE6QHGPAkISMj1SQdqnnw", channel_id
end
Expand Down
2 changes: 1 addition & 1 deletion test/clients/youtube/playlist_items_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"
class Youtube::PlaylistItemsTest < ActiveSupport::TestCase
test "should retreive the playlist of a channel" do
VCR.use_cassette("youtube/playlist_items/all") do
VCR.use_cassette("youtube/playlist_items/all", match_requests_on: [:method]) do
items = Youtube::PlaylistItems.new.all(playlist_id: "PLE7tQUdRKcyZYz0O3d9ZDdo0-BkOWhrSk")
assert items.is_a?(Array)
assert items.length > 50
Expand Down
2 changes: 1 addition & 1 deletion test/clients/youtube/playlists_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"
class Youtube::PlaylistsTest < ActiveSupport::TestCase
test "should retreive the playlist of a channel" do
VCR.use_cassette("youtube/playlists/all") do
VCR.use_cassette("youtube/playlists/all", match_requests_on: [:method]) do
playlists = Youtube::Playlists.new.all(channel_id: "UCWnPjmqvljcafA0z2U1fwKQ")
assert playlists.is_a?(Array)
assert playlists.length > 50
Expand Down
4 changes: 2 additions & 2 deletions test/clients/youtube/video_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def setup
test "should return statistics for a valid video" do
video_id = "9LfmrkyP81M"

VCR.use_cassette("youtube_statistics") do
VCR.use_cassette("youtube_statistics", match_requests_on: [:method]) do
stats = @client.get_statistics(video_id)
assert_not_nil stats
assert stats.has_key?(:view_count)
Expand All @@ -20,7 +20,7 @@ def setup
test "should return nil for an invalid video" do
video_id = "invalid_video_id"

VCR.use_cassette("youtube_statistics_invalid") do
VCR.use_cassette("youtube_statistics_invalid", match_requests_on: [:method]) do
stats = @client.get_statistics(video_id)
assert_nil stats
end
Expand Down
11 changes: 4 additions & 7 deletions test/controllers/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ class EventsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end

# Currently fails because 'description', 'frequency', 'kind' and 'website' are attributes of the event's organisation, not the event itself.
# The #update method and the corresponding form would need to be amended
# test "should update event" do
# sign_in_as @user
# patch event_url(@event), params: {event: {description: @event.description, frequency: @event.frequency, kind: @event.kind, name: @event.name, website: @event.website}}
# assert_redirected_to event_url(@event)
# end
test "should update event" do
patch event_url(@event), params: {event: {city: "Paris", country_code: "FR"}}
assert_redirected_to event_url(@event)
end
end
2 changes: 1 addition & 1 deletion test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to sign_in_url(email_hint: @user.email)
assert_equal "That email or password is incorrect", flash[:alert]

get edit_event_url(events(:one))
get admin_suggestions_url
assert_redirected_to sign_in_url
end

Expand Down
39 changes: 20 additions & 19 deletions test/system/identity/emails_test.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
require "application_system_test_case"
# the UI don't have those links yet so let's comment them
# require "application_system_test_case"

class Identity::EmailsTest < ApplicationSystemTestCase
setup do
@user = sign_in_as(users(:lazaro_nixon))
end
# class Identity::EmailsTest < ApplicationSystemTestCase
# setup do
# @user = sign_in_as(users(:lazaro_nixon))
# end

test "updating the email" do
click_on "Change email address"
# test "updating the email" do
# click_on "Change email address"

fill_in "New email", with: "[email protected]"
fill_in "Current password", with: "Secret1*3*5*"
click_on "Save changes"
# fill_in "New email", with: "[email protected]"
# fill_in "Current password", with: "Secret1*3*5*"
# click_on "Save changes"

assert_text "Your email has been changed"
end
# assert_text "Your email has been changed"
# end

test "sending a verification email" do
@user.update! verified: false
# test "sending a verification email" do
# @user.update! verified: false

click_on "Change email address"
click_on "Re-send verification email"
# click_on "Change email address"
# click_on "Re-send verification email"

assert_text "We sent a verification email to your email address"
end
end
# assert_text "We sent a verification email to your email address"
# end
# end
3 changes: 2 additions & 1 deletion test/system/identity/password_resets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class Identity::PasswordResetsTest < ApplicationSystemTestCase
test "sending a password reset email" do
visit sign_in_url
click_on "Forgot your password?"
wait_for_turbo

fill_in "Email", with: @user.email
fill_in :email, with: @user.email
click_on "Send password reset email"

assert_text "Check your email for reset instructions"
Expand Down
29 changes: 15 additions & 14 deletions test/system/passwords_test.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
require "application_system_test_case"
# the UI don't have those links yet so let's comment them
## require "application_system_test_case"

class PasswordsTest < ApplicationSystemTestCase
setup do
@user = sign_in_as(users(:lazaro_nixon))
end
# class PasswordsTest < ApplicationSystemTestCase
# setup do
# @user = sign_in_as(users(:lazaro_nixon))
# end

test "updating the password" do
click_on "Change password"
# test "updating the password" do
# click_on "Change password"

fill_in "Current password", with: "Secret1*3*5*"
fill_in "New password", with: "Secret6*4*2*"
fill_in "Confirm new password", with: "Secret6*4*2*"
click_on "Save changes"
# fill_in "Current password", with: "Secret1*3*5*"
# fill_in "New password", with: "Secret6*4*2*"
# fill_in "Confirm new password", with: "Secret6*4*2*"
# click_on "Save changes"

assert_text "Your password has been changed"
end
end
# assert_text "Your password has been changed"
# end
# end
12 changes: 6 additions & 6 deletions test/system/sessions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class SessionsTest < ApplicationSystemTestCase

test "visiting the index" do
sign_in_as @user
visit sessions_path

click_on "Devices & Sessions"
assert_selector "h1", text: "Sessions"
end

Expand All @@ -21,10 +21,10 @@ class SessionsTest < ApplicationSystemTestCase
assert_text "Signed in successfully"
end

test "signing out" do
sign_in_as @user
# test "signing out" do
# sign_in_as @user

click_on "Log out"
assert_text "That session has been logged out"
end
# click_on "Log out"
# assert_text "That session has been logged out"
# end
end