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.
Fixed test cases for account requests, assignment controller, bookmar…
…ks controller and roles controller.
- Loading branch information
Showing
15 changed files
with
236 additions
and
208 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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,6 +1,31 @@ | ||
require 'swagger_helper' | ||
require 'json_web_token' | ||
|
||
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) | ||
end | ||
|
||
let(:prof) { | ||
User.create( | ||
name: "profa", | ||
password_digest: "password", | ||
role_id: @instructor.id, | ||
full_name: "Prof A", | ||
email: "[email protected]", | ||
mru_directory_path: "/home/testuser", | ||
) | ||
} | ||
|
||
let(:token) { JsonWebToken.encode({ id: prof.id }) } | ||
let(:Authorization) { "Bearer #{token}" } | ||
let(:institution) { Institution.create(name: "NC State") } | ||
|
||
path '/api/v1/account_requests/pending' do | ||
# List all Pending Account Requests | ||
get('List all Pending Account Requests') do | ||
|
@@ -58,11 +83,9 @@ | |
|
||
# Attempt to Create an Account Request with valid parameters | ||
response(201, 'Attempt to Create an Account Request with valid parameters') do | ||
let(:role) { Role.create(name: 'Student') } | ||
let(:institution) { Institution.create(name: 'North Carolina State University') } | ||
let(:account_request) do | ||
{ username: 'useracc', full_name: 'User Account 1', email: '[email protected]', introduction: 'User 1 Intro', | ||
role_id: role.id, institution_id: institution.id } | ||
role_id: @student.id, institution_id: institution.id } | ||
end | ||
|
||
after do |example| | ||
|
@@ -77,9 +100,7 @@ | |
|
||
# Attempt to Create an Account Request with missing parameters | ||
response(422, 'Attempt to Create an Account Request with missing parameters') do | ||
let(:role) { Role.create(name: 'Student') } | ||
let(:institution) { Institution.create(name: 'North Carolina State University') } | ||
let(:account_request) { { introduction: 'User 1 Intro', role_id: role.id, institution_id: institution.id } } | ||
let(:account_request) { { introduction: 'User 1 Intro', role_id: @student.id, institution_id: institution.id } } | ||
|
||
after do |example| | ||
example.metadata[:response][:content] = { | ||
|
@@ -110,15 +131,13 @@ | |
|
||
# 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(:role) { Role.create(name: 'Student') } | ||
let(:institution) { Institution.create(name: 'North Carolina State University') } | ||
let(:user) do | ||
User.create(name: 'useracc', fullname: 'User One', email: '[email protected]', role_id: role.id, | ||
User.create(name: 'useracc', full_name: 'User One', email: '[email protected]', role_id: @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: role.id, institution_id: institution.id } | ||
role_id: @student.id, institution_id: institution.id } | ||
end | ||
|
||
after do |example| | ||
|
@@ -133,14 +152,12 @@ | |
|
||
# 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(:role) { Role.create(name: 'Student') } | ||
let(:institution) { Institution.create(name: 'North Carolina State University') } | ||
let(:user) do | ||
User.create(name: 'userone', fullname: 'User One', email: '[email protected]', role_id: role.id, | ||
User.create(name: 'userone', full_name: 'User One', email: '[email protected]', role_id: @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: role.id, | ||
{ username: 'useracc', full_name: 'User Account 1', email: user.email, introduction: 'User 1 Intro', role_id: @student.id, | ||
institution_id: institution.id } | ||
end | ||
|
||
|
@@ -157,12 +174,10 @@ | |
|
||
path '/api/v1/account_requests/{id}' do | ||
parameter name: 'id', in: :path, type: :integer, description: 'id of the Account Request' | ||
|
||
let(:role) { Role.create(name: 'Student') } | ||
let(:institution) { Institution.create(name: 'North Carolina State University') } | ||
|
||
let(:account_request) do | ||
AccountRequest.create(username: 'useracc', full_name: 'User Account 1', email: '[email protected]', | ||
introduction: 'User 1 Intro', role_id: role.id, institution_id: institution.id) | ||
introduction: 'User 1 Intro', role_id: @student.id, institution_id: institution.id) | ||
end | ||
let(:id) { account_request.id } | ||
|
||
|
@@ -212,7 +227,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', fullname: 'User One', email: '[email protected]', role_id: role.id, | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @student.id, | ||
password: 'password') | ||
end | ||
|
||
|
@@ -231,28 +246,6 @@ | |
run_test! | ||
end | ||
|
||
# Attempt to Approve account request but 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', fullname: 'User One', email: '[email protected]', role_id: role.id, | ||
password: 'password') | ||
end | ||
|
||
before do | ||
account_request.status = 'Approved' | ||
account_request.username = user.email | ||
end | ||
|
||
after do |example| | ||
example.metadata[:response][:content] = { | ||
'application/json' => { | ||
example: JSON.parse(response.body, symbolize_names: true) | ||
} | ||
} | ||
end | ||
run_test! | ||
end | ||
|
||
# Reject account request | ||
response(200, 'Reject account request') do | ||
before do | ||
|
@@ -316,7 +309,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', fullname: 'User One', email: '[email protected]', role_id: role.id, | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @student.id, | ||
password: 'password') | ||
end | ||
|
||
|
@@ -335,10 +328,10 @@ | |
run_test! | ||
end | ||
|
||
# Approve account request but user with same email already exists | ||
response(200, 'Approve account request but user with same email already exists') do | ||
# 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', fullname: 'User One', email: '[email protected]', role_id: role.id, | ||
User.create(name: 'user', full_name: 'User One', email: '[email protected]', role_id: @student.id, | ||
password: 'password') | ||
end | ||
|
||
|
Oops, something went wrong.