forked from expertiza/reimplementation-back-end
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
10 changed files
with
54 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,14 @@ | |
|
||
RSpec.describe 'Account Requests API', type: :request do | ||
before(:all) do | ||
# Create roles in hierarchy using the factory | ||
@super_admin = FactoryBot.create(:role, :super_administrator) | ||
@admin = FactoryBot.create(:role, :administrator, :with_parent, parent: @super_admin) | ||
@instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: @admin) | ||
@ta = FactoryBot.create(:role, :ta, :with_parent, parent: @instructor) | ||
@student = FactoryBot.create(:role, :student, :with_parent, parent: @ta) | ||
@roles = create_roles_hierarchy | ||
end | ||
|
||
let(:prof) { | ||
User.create( | ||
name: "profa", | ||
password_digest: "password", | ||
role_id: @instructor.id, | ||
role_id: @roles[:instructor].id, | ||
full_name: "Prof A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
@@ -85,7 +80,7 @@ | |
response(201, 'Attempt to Create an Account Request with valid parameters') do | ||
let(:account_request) do | ||
{ username: 'useracc', full_name: 'User Account 1', email: '[email protected]', introduction: 'User 1 Intro', | ||
role_id: @student.id, institution_id: institution.id } | ||
role_id: @roles[:student].id, institution_id: institution.id } | ||
end | ||
|
||
after do |example| | ||
|
@@ -100,7 +95,7 @@ | |
|
||
# Attempt to Create an Account Request with missing parameters | ||
response(422, 'Attempt to Create an Account Request with missing parameters') do | ||
let(:account_request) { { introduction: 'User 1 Intro', role_id: @student.id, institution_id: institution.id } } | ||
let(:account_request) { { introduction: 'User 1 Intro', role_id: @roles[:student].id, institution_id: institution.id } } | ||
|
||
after do |example| | ||
example.metadata[:response][:content] = { | ||
|
@@ -132,12 +127,12 @@ | |
# Attempt to Create an Account Request whose username already exists in Users table | ||
response(422, 'Attempt to Create an Account Request whose username already exists in Users table') do | ||
let(:user) do | ||
User.create(name: 'useracc', full_name: 'User One', email: '[email protected]', role_id: @student.id, | ||
User.create(name: 'useracc', full_name: 'User One', email: '[email protected]', role_id: @roles[:student].id, | ||
password: 'password') | ||
end | ||
let(:account_request) do | ||
{ username: user.name, full_name: 'User Account 1', email: '[email protected]', introduction: 'User 1 Intro', | ||
role_id: @student.id, institution_id: institution.id } | ||
role_id: @roles[:student].id, institution_id: institution.id } | ||
end | ||
|
||
after do |example| | ||
|
@@ -153,11 +148,11 @@ | |
# Create an Account Request whose email already exists in Users table | ||
response(201, 'Create an Account Request whose email already exists in Users table') do | ||
let(:user) do | ||
User.create(name: 'userone', full_name: 'User One', email: '[email protected]', role_id: @student.id, | ||
User.create(name: 'userone', full_name: 'User One', email: '[email protected]', role_id: @roles[:student].id, | ||
password: 'password') | ||
end | ||
let(:account_request) do | ||
{ username: 'useracc', full_name: 'User Account 1', email: user.email, introduction: 'User 1 Intro', role_id: @student.id, | ||
{ username: 'useracc', full_name: 'User Account 1', email: user.email, introduction: 'User 1 Intro', role_id: @roles[:student].id, | ||
institution_id: institution.id } | ||
end | ||
|
||
|
@@ -177,7 +172,7 @@ | |
|
||
let(:account_request) do | ||
AccountRequest.create(username: 'useracc', full_name: 'User Account 1', email: '[email protected]', | ||
introduction: 'User 1 Intro', role_id: @student.id, institution_id: institution.id) | ||
introduction: 'User 1 Intro', role_id: @roles[:student].id, institution_id: institution.id) | ||
end | ||
let(:id) { account_request.id } | ||
|
||
|
@@ -227,7 +222,7 @@ | |
# Attempt to Approve account request but user with same name already exists | ||
response(422, 'Attempt to Approve account request but user with same name already exists') do | ||
let(:user) do | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @student.id, | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @roles[:student].id, | ||
password: 'password') | ||
end | ||
|
||
|
@@ -309,7 +304,7 @@ | |
# Attempt to Approve account request but user with same username already exists | ||
response(422, 'Attempt to Approve account request but user with same username already exists') do | ||
let(:user) do | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @student.id, | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @roles[:student].id, | ||
password: 'password') | ||
end | ||
|
||
|
@@ -331,7 +326,7 @@ | |
# Reject account request if user with same email already exists | ||
response(422, 'Attempt to Approve account request but user with same email already exists') do | ||
let(:user) do | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @student.id, | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @roles[:student].id, | ||
password: 'password') | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,7 @@ | |
|
||
RSpec.describe 'Assignments API', type: :request do | ||
before do | ||
@super_admin = FactoryBot.create(:role, :super_administrator) | ||
@admin = FactoryBot.create(:role, :administrator, :with_parent, parent: @super_admin) | ||
@instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: @admin) | ||
@ta = FactoryBot.create(:role, :ta, :with_parent, parent: @instructor) | ||
@student = FactoryBot.create(:role, :student, :with_parent, parent: @ta) | ||
@roles = create_roles_hierarchy | ||
end | ||
|
||
let(:institution) { Institution.create(id: 100, name: 'NCSU') } | ||
|
@@ -24,7 +20,7 @@ | |
User.create( | ||
name: "profa", | ||
password_digest: "password", | ||
role_id: @instructor.id, | ||
role_id: @roles[:instructor].id, | ||
full_name: "Prof A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,14 @@ | |
# Rspec test for Bookmarks Controller | ||
RSpec.describe 'api/v1/bookmarks', type: :request do | ||
before(:all) do | ||
@super_admin = FactoryBot.create(:role, :super_administrator) | ||
@admin = FactoryBot.create(:role, :administrator, :with_parent, parent: @super_admin) | ||
@instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: @admin) | ||
@ta = FactoryBot.create(:role, :ta, :with_parent, parent: @instructor) | ||
@student = FactoryBot.create(:role, :student, :with_parent, parent: @ta) | ||
@roles = create_roles_hierarchy | ||
end | ||
|
||
let(:student) { | ||
User.create( | ||
name: "studenta", | ||
password_digest: "password", | ||
role_id: @student.id, | ||
role_id: @roles[:student].id, | ||
full_name: "student A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,14 @@ | |
|
||
RSpec.describe 'api/v1/courses', type: :request do | ||
before(:all) do | ||
@super_admin = FactoryBot.create(:role, :super_administrator) | ||
@admin = FactoryBot.create(:role, :administrator, :with_parent, parent: @super_admin) | ||
@instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: @admin) | ||
@ta = FactoryBot.create(:role, :ta, :with_parent, parent: @instructor) | ||
@student = FactoryBot.create(:role, :student, :with_parent, parent: @ta) | ||
@roles = create_roles_hierarchy | ||
end | ||
|
||
let(:prof) { | ||
User.create( | ||
name: "profa", | ||
password_digest: "password", | ||
role_id: @instructor.id, | ||
role_id: @roles[:instructor].id, | ||
full_name: "Prof A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
@@ -33,7 +29,7 @@ | |
User.create( | ||
name: "taa", | ||
password_digest: "password", | ||
role_id: @ta.id, | ||
role_id: @roles[:ta].id, | ||
full_name: "TA A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
@@ -113,7 +109,7 @@ | |
User.create( | ||
name: "taa", | ||
password_digest: "password", | ||
role_id: @ta.id, | ||
role_id: @roles[:ta].id, | ||
full_name: "TA A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,13 @@ | |
require 'json_web_token' | ||
RSpec.describe 'Institutions API', type: :request do | ||
before(:all) do | ||
@super_admin = FactoryBot.create(:role, :super_administrator) | ||
@admin = FactoryBot.create(:role, :administrator, :with_parent, parent: @super_admin) | ||
@instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: @admin) | ||
@ta = FactoryBot.create(:role, :ta, :with_parent, parent: @instructor) | ||
@student = FactoryBot.create(:role, :student, :with_parent, parent: @ta) | ||
@roles = create_roles_hierarchy | ||
end | ||
|
||
let(:prof) { User.create( | ||
name: "profa", | ||
password_digest: "password", | ||
role_id: @instructor.id, | ||
role_id: @roles[:instructor].id, | ||
full_name: "Prof A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,14 @@ | |
|
||
RSpec.describe 'Invitations API', type: :request do | ||
before(:all) do | ||
@super_admin = FactoryBot.create(:role, :super_administrator) | ||
@admin = FactoryBot.create(:role, :administrator, :with_parent, parent: @super_admin) | ||
@instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: @admin) | ||
@ta = FactoryBot.create(:role, :ta, :with_parent, parent: @instructor) | ||
@student = FactoryBot.create(:role, :student, :with_parent, parent: @ta) | ||
@roles = create_roles_hierarchy | ||
end | ||
|
||
let(:student) { | ||
User.create( | ||
name: "studenta", | ||
password_digest: "password", | ||
role_id: @student.id, | ||
role_id: @roles[:student].id, | ||
full_name: "student A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
@@ -26,7 +22,7 @@ | |
User.create( | ||
name: "profa", | ||
password_digest: "password", | ||
role_id: @instructor.id, | ||
role_id: @roles[:instructor].id, | ||
full_name: "Prof A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
@@ -35,9 +31,9 @@ | |
|
||
let(:token) { JsonWebToken.encode({id: student.id}) } | ||
let(:Authorization) { "Bearer #{token}" } | ||
let(:user1) { create :user, name: 'rohitgeddam' } | ||
let(:user2) { create :user, name: 'superman' } | ||
let(:invalid_user) { build :user, name: 'INVALID' } | ||
let(:user1) { create :user, name: 'rohitgeddam', role_id: @roles[:student].id } | ||
let(:user2) { create :user, name: 'superman', role_id: @roles[:student].id } | ||
let(:invalid_user) { build :user, name: 'INVALID', role_id: nil } | ||
let(:assignment) { Assignment.create!(id: 1, name: 'Test Assignment', instructor_id: prof.id) } | ||
let(:invitation) { Invitation.create!(from_user: user1, to_user: user2, assignment: assignment) } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,14 @@ | |
|
||
RSpec.describe 'Roles API', type: :request do | ||
before(:all) do | ||
@super_admin = FactoryBot.create(:role, :super_administrator) | ||
@admin = FactoryBot.create(:role, :administrator, :with_parent, parent: @super_admin) | ||
@instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: @admin) | ||
@ta = FactoryBot.create(:role, :ta, :with_parent, parent: @instructor) | ||
@student = FactoryBot.create(:role, :student, :with_parent, parent: @ta) | ||
@roles = create_roles_hierarchy | ||
end | ||
|
||
let(:adm) { | ||
User.create( | ||
name: "adma", | ||
password_digest: "password", | ||
role_id: @admin.id, | ||
role_id: @roles[:admin].id, | ||
full_name: "Admin A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,14 @@ | |
RSpec.describe 'StudentTasks API', type: :request do | ||
|
||
before(:all) do | ||
@super_admin = FactoryBot.create(:role, :super_administrator) | ||
@admin = FactoryBot.create(:role, :administrator, :with_parent, parent: @super_admin) | ||
@instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: @admin) | ||
@ta = FactoryBot.create(:role, :ta, :with_parent, parent: @instructor) | ||
@student = FactoryBot.create(:role, :student, :with_parent, parent: @ta) | ||
@roles = create_roles_hierarchy | ||
end | ||
|
||
let(:studenta) { | ||
User.create( | ||
name: "studenta", | ||
password_digest: "password", | ||
role_id: @student.id, | ||
role_id: @roles[:student].id, | ||
full_name: "Student A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# spec/support/roles_helper.rb | ||
module RolesHelper | ||
def create_roles_hierarchy | ||
# Create roles in hierarchy using the factory | ||
super_admin = FactoryBot.create(:role, :super_administrator) | ||
admin = FactoryBot.create(:role, :administrator, :with_parent, parent: super_admin) | ||
instructor = FactoryBot.create(:role, :instructor, :with_parent, parent: admin) | ||
ta = FactoryBot.create(:role, :ta, :with_parent, parent: instructor) | ||
student = FactoryBot.create(:role, :student, :with_parent, parent: ta) | ||
|
||
# Return the roles as a hash for easy access in specs | ||
{ | ||
super_admin: super_admin, | ||
admin: admin, | ||
instructor: instructor, | ||
ta: ta, | ||
student: student | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters