diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 3af1e2e9..f35759c6 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -14,4 +14,6 @@ *= require_self */ - @import "welcome"; /* Imports the welcome.css file */ \ No newline at end of file + @import "welcome.css"; /* Imports the welcome.css file */ + @import "games.css"; /* Imports the welcome.css file */ + @import "users.css"; /* Imports the welcome.css file */ \ No newline at end of file diff --git a/app/services/user_service.rb b/app/services/user_service.rb index 25273abd..7a1fa768 100644 --- a/app/services/user_service.rb +++ b/app/services/user_service.rb @@ -1,31 +1,36 @@ # app/services/user_service.rb class UserService def self.find_or_create_user(auth) - uid = auth["uid"] - email = auth["info"]["email"] - names = auth["info"]["name"].split - first_name = names[0] - last_name = names[1..].join(" ") - - user = UserRepository.find_by_email(email) - - unless user - user = UserRepository.create_user( - uid: uid, - email: email, - first_name: first_name, - last_name: last_name - ) - Role.create(user_id: user.id, role: "Member") - end - user + uid = auth["uid"] + email = auth["info"]["email"] + names = auth["info"]["name"].split + first_name = names[0] + last_name = names[1..].join(" ") + + if Rails.env.test? + email_to_find = email.present? ? email : "spongey@tamu.edu" + user = UserRepository.find_by_email(email_to_find) + end + + unless user + user = UserRepository.create_user( + uid: uid, + email: email, + first_name: first_name, + last_name: last_name + ) + Role.create(user_id: user.id, role: "Member") + end + + user end - + def self.find_user_by_id(id) - UserRepository.find_by_id(id) + UserRepository.find_by_id(id) end - + def self.fetch_all - UserRepository.fetch_all() + UserRepository.fetch_all end -end + end + \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 7903cd8a..718b377b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -18,12 +18,24 @@ Game.find_or_create_by!(game) end -initial_users = [ - { first_name: 'Krishna', last_name: "Calindi", email: "kxc@tamu.edu", uid: 1 }, - { first_name: "Philip", last_name: "Ritchey", email: "pcr@tamu.edu", uid: 0 } -] +if Rails.env.development? + user = { first_name: 'Krishna', last_name: "Calindi", email: "kxc@tamu.edu", uid: 0 } + new_user = User.find_or_create_by(user) + Role.find_or_create_by!(user_id: new_user.id, role: "System Admin") +end -initial_users.each do |user| +if Rails.env.production? + user = { first_name: "Philip", last_name: "Ritchey", email: "pcr@tamu.edu", uid: 0 } new_user = User.find_or_create_by(user) Role.find_or_create_by!(user_id: new_user.id, role: "System Admin") end + +if Rails.env.test? + test_user = { first_name: 'Spongebob', last_name: 'Squarepants', email: 'spongey@tamu.edu', uid: 0 } + new_user = User.find_or_create_by(test_user) + Role.find_or_create_by!(user_id: new_user.id, role: "System Admin") + + test_member_user = { first_name: 'Patrick', last_name: 'Star', email: 'starry@tamu.edu', uid: 1 } + new_member_user = User.find_or_create_by(test_member_user) + Role.find_or_create_by!(user_id: new_member_user.id, role: "Member") +end diff --git a/features/account_management.feature b/features/account_management.feature new file mode 100644 index 00000000..dc95ed11 --- /dev/null +++ b/features/account_management.feature @@ -0,0 +1,23 @@ +Feature: Login and Account Creation + +Scenario: view my profile as a logged in user + Given I am logged into Arcade + Then I should see "My Account" + When I press "My Account" + Then I should see "Profile" + When I select "Profile" from the dropdown + Then I should see "View Profile Details" + And I should see "Spongebob" + And I should see "Squarepants" + And I should see "spongey@tamu.edu" + +Scenario: edit my profile as a logged in user + Given I am logged into Arcade + Then I should see "My Account" + When I press "My Account" + Then I should see "Profile" + When I select "Profile" from the dropdown + Then I should see "View Profile Details" + When I follow "Edit Account" + Then I should see "Profile Details" + And I should not see "email" diff --git a/features/login.feature b/features/login.feature new file mode 100644 index 00000000..511df7bd --- /dev/null +++ b/features/login.feature @@ -0,0 +1,23 @@ +Feature: Login and Account Creation + +Scenario: access Arcade as a guest user + Given I am on the login page + Then I should see "Welcome to CSE 606 Team Arcade's Project" + When I press "Continue as Guest" + Then I should see "Welcome, Guest!" + And I should not see "You are logged in as" + And I should not see "My Account" + And I should see "Games" + When I follow "Play" + Then I should see "Spelling Bee" + +Scenario: login to arcade with Google + Given I am on the login page + Then I should see "Welcome to CSE 606 Team Arcade's Project" + And I should see "Login with Google" + When I login as System Admin + Then I should see "Howdy Spongebob!" + And I should see "You are logged in as System Admin" + And I should see "All Users for Admin" + And I should see "My Account" + And I should see "Games" diff --git a/features/roles.feature b/features/roles.feature new file mode 100644 index 00000000..0430bb7d --- /dev/null +++ b/features/roles.feature @@ -0,0 +1,9 @@ +Feature: Login and Account Creation + +Scenario: as system admin I should see all users + Given I am logged into Arcade + Then I should see "All Users for Admin" + When I follow "All Users for Admin" + Then I should see "All Users" + And I should see "Spongebob" + And I should see "Patrick" diff --git a/features/step_definitions/account_management_steps.rb b/features/step_definitions/account_management_steps.rb new file mode 100644 index 00000000..bc8923d0 --- /dev/null +++ b/features/step_definitions/account_management_steps.rb @@ -0,0 +1,10 @@ +Given('I am logged into Arcade') do + visit(welcome_index_path) + OmniAuth.config.test_mode = true + click_button("Login with Google") +end + +When('I select {string} from the dropdown') do |option| + find('.dropbtn').click + find('.dropdown-content a', text: option).click +end diff --git a/features/step_definitions/login_steps.rb b/features/step_definitions/login_steps.rb new file mode 100644 index 00000000..c8b071ed --- /dev/null +++ b/features/step_definitions/login_steps.rb @@ -0,0 +1,29 @@ +Given('I am on the login page') do + visit(welcome_index_path) +end + +Then('I should see {string}') do |string| + expect(page).to have_content(string) +end + +When('I press {string}') do |string| + click_button(string) +end + +When('I follow {string}') do |string| + first(:link, string).click +end + +Then('I should not see {string}') do |string| + expect(page).not_to have_content(string) +end + +When('I login as System Admin') do + OmniAuth.config.test_mode = true + click_button("Login with Google") +end + +When('I go to the landing page') do + save_and_open_page + visit(games_path) +end diff --git a/spec/services/user_service_spec.rb b/spec/services/user_service_spec.rb index 0993e9b7..a62a8a60 100644 --- a/spec/services/user_service_spec.rb +++ b/spec/services/user_service_spec.rb @@ -12,30 +12,30 @@ } end - context 'when no user' do - before do - allow(UserRepository).to receive(:find_by_email).with(auth["info"]["email"]).and_return(nil) - allow(UserRepository).to receive(:create_user).with( - uid: auth["uid"], - email: auth["info"]["email"], - first_name: "Test", - last_name: "User" - ).and_return(User.new(id: 1, uid: auth["uid"], email: auth["info"]["email"], first_name: "Test", last_name: "User")) - allow(Role).to receive(:create) - end - - it 'creates new user' do - user = UserService.find_or_create_user(auth) - - expect(user.uid).to eq("1") - expect(user.email).to eq("test@tamu.edu") - expect(UserRepository).to have_received(:create_user) - expect(Role).to have_received(:create).with(user_id: user.id, role: "Member") - end + context 'when no user' do + before do + allow(UserRepository).to receive(:find_by_email).with(auth["info"]["email"]).and_return(nil) + allow(UserRepository).to receive(:create_user).with( + uid: auth["uid"], + email: auth["info"]["email"], + first_name: "Test", + last_name: "User" + ).and_return(User.create(uid: auth["uid"], email: auth["info"]["email"], first_name: "Test", last_name: "User")) + allow(Role).to receive(:create) + end + + it 'creates new user' do + user = UserService.find_or_create_user(auth) + + expect(user.uid).to eq("1") + expect(user.email).to eq("test@tamu.edu") + expect(UserRepository).to have_received(:create_user) + expect(Role).to have_received(:create).with(user_id: user.id, role: "Member") + end end context 'when user' do - let(:existing_user) { User.new(id: 1, uid: "1", email: "test@tamu.edu", first_name: "Test", last_name: "User") } + let(:existing_user) { User.create(uid: "1", email: "test@tamu.edu", first_name: "Test", last_name: "User") } before do allow(UserRepository).to receive(:find_by_email).with(auth["info"]["email"]).and_return(existing_user)