forked from saasbook/flextensions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge from main and resolve conflict
- Loading branch information
Showing
10 changed files
with
196 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class CourseToLms < ApplicationRecord | ||
|
||
# Associations | ||
belongs_to :course | ||
belongs_to :lms | ||
|
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,7 @@ | ||
class Extension < ApplicationRecord | ||
#Relationship with Assignment | ||
belongs_to :assignment | ||
|
||
#Relationship with User | ||
has_one :user | ||
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# app/models/lms.rb | ||
class Lms < ApplicationRecord | ||
#Relationship with Course (and CourseToLms) | ||
has_many :course_to_lmss | ||
has_many :courses, :through => :course_to_lmss | ||
|
||
|
||
#Relationship with Assignment | ||
has_many :assignments | ||
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
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,10 @@ | ||
class UserToCourse < ApplicationRecord | ||
# Associations | ||
belongs_to :user | ||
belongs_to :course | ||
|
||
# Validations | ||
validates :user_id, presence: true | ||
validates :course_id, presence: true | ||
validates :role, presence: true | ||
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 |
---|---|---|
|
@@ -7,3 +7,86 @@ | |
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| | ||
# MovieGenre.find_or_create_by!(name: genre_name) | ||
# end | ||
|
||
LmsCredential.destroy_all | ||
Extension.destroy_all | ||
Assignment.destroy_all | ||
CourseToLms.destroy_all | ||
UserToCourse.destroy_all | ||
Course.destroy_all | ||
Lms.destroy_all | ||
User.destroy_all | ||
|
||
canvas = Lms.create!({ | ||
lms_name: "Canvas", | ||
use_auth_token: true | ||
}) | ||
|
||
|
||
test_assignment = Assignment.create!({ | ||
lms_id: canvas.id, | ||
name: "Test Assignment", | ||
external_assignment_id: "11111" | ||
}) | ||
|
||
|
||
test_course = Course.create!({ | ||
course_name: "Test Course", | ||
}) | ||
|
||
test_course_to_lms = CourseToLms.create!({ | ||
lms_id: canvas.id, | ||
course_id: test_course.id, | ||
external_course_id: "22222" | ||
}) | ||
|
||
test_user = User.create!({ | ||
email: "[email protected]", | ||
}) | ||
|
||
test_user_to_course = UserToCourse.create!({ | ||
user_id: test_user.id, | ||
course_id: test_course.id, | ||
role: "test" | ||
}) | ||
|
||
test_extension = Extension.create!({ | ||
assignment_id: test_assignment.id, | ||
student_email: "[email protected]", | ||
initial_due_date: DateTime.iso8601('2024-04-20'), | ||
new_due_date: DateTime.iso8601('2024-04-30'), | ||
last_processed_by_id: test_user.id, | ||
external_extension_id: "33333" | ||
}) | ||
|
||
test_lms_credential = LmsCredential.create!({ | ||
user_id: test_user.id, | ||
lms_name: "canvas", | ||
token: "test token", | ||
external_user_id: "44444" | ||
}) | ||
|
||
real_course = Course.create!({ | ||
course_name: "CS169L Flextension", | ||
}) | ||
|
||
real_course_to_lms = CourseToLms.create!({ | ||
lms_id: canvas.id, | ||
course_id: real_course.id, | ||
external_course_id: "1534405" | ||
}) | ||
|
||
real_assignment = Assignment.create!({ | ||
lms_id: canvas.id, | ||
name: "Seed Data Testing", | ||
external_assignment_id: "8741483" | ||
}) | ||
|
||
real_extension = Extension.create!({ | ||
assignment_id: real_assignment.id, | ||
student_email: "[email protected]", | ||
initial_due_date: DateTime.iso8601('2024-04-20'), | ||
new_due_date: DateTime.iso8601('2024-04-27'), | ||
last_processed_by_id: test_user.id, | ||
external_extension_id: "270163" | ||
}) |
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 |
---|---|---|
|
@@ -44,9 +44,36 @@ module V1 | |
end | ||
|
||
describe 'add_user' do | ||
it 'throws a 501 error' do | ||
put :add_user, params: { course_id: 16, user_id: 16 } | ||
expect(response.status).to eq(501) | ||
let(:test_course) { Course.create(course_name: "Test Course") } | ||
let(:test_user) { User.create(email: "[email protected]") } | ||
|
||
context "Provided parameters are valid" do | ||
it "adds an existing user to an existing course" do | ||
post :add_user, params: { course_id: test_course.id, user_id: test_user.id, role: "ta" } | ||
expect(response).to have_http_status(:created) | ||
expect(flash["success"]).to eq("User added to the course successfully.") | ||
end | ||
end | ||
|
||
context "Provided parameter are invalid" do | ||
it "returns an error if course is not existed in the courses table" do | ||
post :add_user, params: { course_id: 123456, user_id: test_user.id, role: "ta" } | ||
expect(response).to have_http_status(:not_found) | ||
expect(JSON.parse(response.body)["error"]).to eq("The course does not exist.") | ||
end | ||
|
||
it "returns an error if user is not existed in the users table" do | ||
post :add_user, params: { course_id: test_course.id, user_id: 123456, role: "ta" } | ||
expect(response).to have_http_status(:not_found) | ||
expect(JSON.parse(response.body)["error"]).to eq("The user does not exist.") | ||
end | ||
|
||
it "returns an error if the user is already associated with the course" do | ||
post :add_user, params: { course_id: test_course.id, user_id: test_user.id, role: "student" } | ||
post :add_user, params: { course_id: test_course.id, user_id: test_user.id, role: "student" } | ||
expect(response).to have_http_status(:unprocessable_entity) | ||
expect(JSON.parse(response.body)["error"]).to eq("The user is already added to the course.") | ||
end | ||
end | ||
end | ||
end | ||
|