Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashika08 committed Jan 29, 2025
2 parents f997d59 + 9a88066 commit 7a49fe4
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 65 deletions.
29 changes: 12 additions & 17 deletions spec/requests/api/v1/account_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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|
Expand All @@ -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] = {
Expand Down Expand Up @@ -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|
Expand All @@ -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

Expand All @@ -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 }

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
8 changes: 2 additions & 6 deletions spec/requests/api/v1/assignment_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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') }
Expand All @@ -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",
Expand Down
8 changes: 2 additions & 6 deletions spec/requests/api/v1/bookmarks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 4 additions & 8 deletions spec/requests/api/v1/courses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 2 additions & 6 deletions spec/requests/api/v1/institution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 6 additions & 10 deletions spec/requests/api/v1/invitation_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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) }

Expand Down
8 changes: 2 additions & 6 deletions spec/requests/api/v1/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 2 additions & 6 deletions spec/requests/api/v1/student_tasks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions spec/support/roles_helper.rb
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
2 changes: 2 additions & 0 deletions spec/swagger_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

require 'rails_helper'
require 'support/roles_helper'

RSpec.configure do |config|
# Specify a root folder where Swagger JSON files are generated
# NOTE: If you're using the rswag-api to serve API descriptions, you'll need
# to ensure that it's configured to serve Swagger from the same folder
config.swagger_root = Rails.root.join('swagger').to_s
config.include RolesHelper

# Define one or more Swagger documents and provide global metadata for each one
# When you run the 'rswag:specs:swaggerize' rake task, the complete Swagger will
Expand Down

0 comments on commit 7a49fe4

Please sign in to comment.