Skip to content

Commit 6532f2e

Browse files
authored
Merge pull request #20 from tamu-edu-students/cucumber_tests
write uat tests
2 parents 8c3d5b9 + dbac555 commit 6532f2e

File tree

9 files changed

+163
-50
lines changed

9 files changed

+163
-50
lines changed

app/assets/stylesheets/application.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
*= require_self
1515
*/
1616

17-
@import "welcome"; /* Imports the welcome.css file */
17+
@import "welcome.css"; /* Imports the welcome.css file */
18+
@import "games.css"; /* Imports the welcome.css file */
19+
@import "users.css"; /* Imports the welcome.css file */

app/services/user_service.rb

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
# app/services/user_service.rb
22
class UserService
33
def self.find_or_create_user(auth)
4-
uid = auth["uid"]
5-
email = auth["info"]["email"]
6-
names = auth["info"]["name"].split
7-
first_name = names[0]
8-
last_name = names[1..].join(" ")
9-
10-
user = UserRepository.find_by_email(email)
11-
12-
unless user
13-
user = UserRepository.create_user(
14-
uid: uid,
15-
email: email,
16-
first_name: first_name,
17-
last_name: last_name
18-
)
19-
Role.create(user_id: user.id, role: "Member")
20-
end
21-
user
4+
uid = auth["uid"]
5+
email = auth["info"]["email"]
6+
names = auth["info"]["name"].split
7+
first_name = names[0]
8+
last_name = names[1..].join(" ")
9+
10+
if Rails.env.test?
11+
email_to_find = email.present? ? email : "spongey@tamu.edu"
12+
user = UserRepository.find_by_email(email_to_find)
13+
end
14+
15+
unless user
16+
user = UserRepository.create_user(
17+
uid: uid,
18+
email: email,
19+
first_name: first_name,
20+
last_name: last_name
21+
)
22+
Role.create(user_id: user.id, role: "Member")
23+
end
24+
25+
user
2226
end
23-
27+
2428
def self.find_user_by_id(id)
25-
UserRepository.find_by_id(id)
29+
UserRepository.find_by_id(id)
2630
end
27-
31+
2832
def self.fetch_all
29-
UserRepository.fetch_all()
33+
UserRepository.fetch_all
3034
end
31-
end
35+
end
36+

db/seeds.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@
1818
Game.find_or_create_by!(game)
1919
end
2020

21-
initial_users = [
22-
{ first_name: 'Krishna', last_name: "Calindi", email: "kxc@tamu.edu", uid: 1 },
23-
{ first_name: "Philip", last_name: "Ritchey", email: "pcr@tamu.edu", uid: 0 }
24-
]
21+
if Rails.env.development?
22+
user = { first_name: 'Krishna', last_name: "Calindi", email: "kxc@tamu.edu", uid: 0 }
23+
new_user = User.find_or_create_by(user)
24+
Role.find_or_create_by!(user_id: new_user.id, role: "System Admin")
25+
end
2526

26-
initial_users.each do |user|
27+
if Rails.env.production?
28+
user = { first_name: "Philip", last_name: "Ritchey", email: "pcr@tamu.edu", uid: 0 }
2729
new_user = User.find_or_create_by(user)
2830
Role.find_or_create_by!(user_id: new_user.id, role: "System Admin")
2931
end
32+
33+
if Rails.env.test?
34+
test_user = { first_name: 'Spongebob', last_name: 'Squarepants', email: 'spongey@tamu.edu', uid: 0 }
35+
new_user = User.find_or_create_by(test_user)
36+
Role.find_or_create_by!(user_id: new_user.id, role: "System Admin")
37+
38+
test_member_user = { first_name: 'Patrick', last_name: 'Star', email: 'starry@tamu.edu', uid: 1 }
39+
new_member_user = User.find_or_create_by(test_member_user)
40+
Role.find_or_create_by!(user_id: new_member_user.id, role: "Member")
41+
end

features/account_management.feature

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Feature: Login and Account Creation
2+
3+
Scenario: view my profile as a logged in user
4+
Given I am logged into Arcade
5+
Then I should see "My Account"
6+
When I press "My Account"
7+
Then I should see "Profile"
8+
When I select "Profile" from the dropdown
9+
Then I should see "View Profile Details"
10+
And I should see "Spongebob"
11+
And I should see "Squarepants"
12+
And I should see "spongey@tamu.edu"
13+
14+
Scenario: edit my profile as a logged in user
15+
Given I am logged into Arcade
16+
Then I should see "My Account"
17+
When I press "My Account"
18+
Then I should see "Profile"
19+
When I select "Profile" from the dropdown
20+
Then I should see "View Profile Details"
21+
When I follow "Edit Account"
22+
Then I should see "Profile Details"
23+
And I should not see "email"

features/login.feature

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Feature: Login and Account Creation
2+
3+
Scenario: access Arcade as a guest user
4+
Given I am on the login page
5+
Then I should see "Welcome to CSE 606 Team Arcade's Project"
6+
When I press "Continue as Guest"
7+
Then I should see "Welcome, Guest!"
8+
And I should not see "You are logged in as"
9+
And I should not see "My Account"
10+
And I should see "Games"
11+
When I follow "Play"
12+
Then I should see "Spelling Bee"
13+
14+
Scenario: login to arcade with Google
15+
Given I am on the login page
16+
Then I should see "Welcome to CSE 606 Team Arcade's Project"
17+
And I should see "Login with Google"
18+
When I login as System Admin
19+
Then I should see "Howdy Spongebob!"
20+
And I should see "You are logged in as System Admin"
21+
And I should see "All Users for Admin"
22+
And I should see "My Account"
23+
And I should see "Games"

features/roles.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Feature: Login and Account Creation
2+
3+
Scenario: as system admin I should see all users
4+
Given I am logged into Arcade
5+
Then I should see "All Users for Admin"
6+
When I follow "All Users for Admin"
7+
Then I should see "All Users"
8+
And I should see "Spongebob"
9+
And I should see "Patrick"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Given('I am logged into Arcade') do
2+
visit(welcome_index_path)
3+
OmniAuth.config.test_mode = true
4+
click_button("Login with Google")
5+
end
6+
7+
When('I select {string} from the dropdown') do |option|
8+
find('.dropbtn').click
9+
find('.dropdown-content a', text: option).click
10+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Given('I am on the login page') do
2+
visit(welcome_index_path)
3+
end
4+
5+
Then('I should see {string}') do |string|
6+
expect(page).to have_content(string)
7+
end
8+
9+
When('I press {string}') do |string|
10+
click_button(string)
11+
end
12+
13+
When('I follow {string}') do |string|
14+
first(:link, string).click
15+
end
16+
17+
Then('I should not see {string}') do |string|
18+
expect(page).not_to have_content(string)
19+
end
20+
21+
When('I login as System Admin') do
22+
OmniAuth.config.test_mode = true
23+
click_button("Login with Google")
24+
end
25+
26+
When('I go to the landing page') do
27+
save_and_open_page
28+
visit(games_path)
29+
end

spec/services/user_service_spec.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@
1212
}
1313
end
1414

15-
context 'when no user' do
16-
before do
17-
allow(UserRepository).to receive(:find_by_email).with(auth["info"]["email"]).and_return(nil)
18-
allow(UserRepository).to receive(:create_user).with(
19-
uid: auth["uid"],
20-
email: auth["info"]["email"],
21-
first_name: "Test",
22-
last_name: "User"
23-
).and_return(User.new(id: 1, uid: auth["uid"], email: auth["info"]["email"], first_name: "Test", last_name: "User"))
24-
allow(Role).to receive(:create)
25-
end
26-
27-
it 'creates new user' do
28-
user = UserService.find_or_create_user(auth)
29-
30-
expect(user.uid).to eq("1")
31-
expect(user.email).to eq("test@tamu.edu")
32-
expect(UserRepository).to have_received(:create_user)
33-
expect(Role).to have_received(:create).with(user_id: user.id, role: "Member")
34-
end
15+
context 'when no user' do
16+
before do
17+
allow(UserRepository).to receive(:find_by_email).with(auth["info"]["email"]).and_return(nil)
18+
allow(UserRepository).to receive(:create_user).with(
19+
uid: auth["uid"],
20+
email: auth["info"]["email"],
21+
first_name: "Test",
22+
last_name: "User"
23+
).and_return(User.create(uid: auth["uid"], email: auth["info"]["email"], first_name: "Test", last_name: "User"))
24+
allow(Role).to receive(:create)
25+
end
26+
27+
it 'creates new user' do
28+
user = UserService.find_or_create_user(auth)
29+
30+
expect(user.uid).to eq("1")
31+
expect(user.email).to eq("test@tamu.edu")
32+
expect(UserRepository).to have_received(:create_user)
33+
expect(Role).to have_received(:create).with(user_id: user.id, role: "Member")
34+
end
3535
end
3636

3737
context 'when user' do
38-
let(:existing_user) { User.new(id: 1, uid: "1", email: "test@tamu.edu", first_name: "Test", last_name: "User") }
38+
let(:existing_user) { User.create(uid: "1", email: "test@tamu.edu", first_name: "Test", last_name: "User") }
3939

4040
before do
4141
allow(UserRepository).to receive(:find_by_email).with(auth["info"]["email"]).and_return(existing_user)

0 commit comments

Comments
 (0)