Skip to content

Commit

Permalink
[BUG FIX] [MER-3701] Error managing gating student exceptions (#5187)
Browse files Browse the repository at this point in the history
* [MER-3701] Adds User to select_merge

* [MER-3701] Adds test
  • Loading branch information
simonchoxx authored Oct 14, 2024
1 parent ff4d7d8 commit 04c64dd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/oli/delivery/gating.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule Oli.Delivery.Gating do
select: gc,
select_merge: %{
total_count: fragment("count(*) OVER()"),
revision: rev
revision: rev,
user: u
}
)

Expand Down
76 changes: 76 additions & 0 deletions test/oli_web/live/sections/gating_and_scheduling_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,82 @@ defmodule OliWeb.Sections.GatingAndSchedulingTest do
timezone
) == input_end_date
end

test "create student exceptions for more than one student works correctly", %{
conn: conn,
section_1: section,
gating_condition: gating_condition,
revision: revision
} do
user = user_fixture(%{family_name: "Curry", given_name: "Stephen"})
user_2 = user_fixture(%{family_name: "Durant", given_name: "Kevin"})

# create a student exception for the user
gating_condition_fixture(%{
section_id: section.id,
resource_id: revision.resource_id,
parent_id: gating_condition.id,
user_id: user.id
})

# create a student exception for the user_2
gating_condition_fixture(%{
section_id: section.id,
resource_id: revision.resource_id,
parent_id: gating_condition.id,
user_id: user_2.id
})

{:ok, view, _html} =
live(
conn,
gating_condition_edit_route(section.slug, gating_condition.id)
)

# get the count of exceptions for the gating condition
count_exceptions = Gating.count_exceptions(gating_condition.id)

# assert that the count of exceptions is 2
assert count_exceptions == 2

# assert that the view displays the correct message
assert view |> element("div.alert.alert-primary > div") |> render() =~
"This gate has #{count_exceptions} student-specific exceptions."

# click on the "Manage Student Exceptions" button
view
|> element(
"~s(a[href='/sections/#{section.slug}/gating_and_scheduling/exceptions/#{gating_condition.id}'])",
"Manage Student Exceptions"
)
|> render_click()

# assert that we are redirected to the exceptions page
assert_redirected(
view,
~p"/sections/#{section.slug}/gating_and_scheduling/exceptions/#{gating_condition.id}"
)

{:ok, view, _html} =
live(
conn,
~p"/sections/#{section.slug}/gating_and_scheduling/exceptions/#{gating_condition.id}"
)

# assert that we have the correct exceptions in the view
assert view
|> element("tbody > tr:first-child > td:first-child a")
|> render() =~
"#{user.family_name}, #{user.given_name}"

assert view
|> element("tbody > tr:nth-child(2) > td:first-child a")
|> render() =~
"#{user_2.family_name}, #{user_2.given_name}"

# assert that we have the button to create a new exception
assert has_element?(view, "a", "New Student Exception")
end
end

describe "gating and scheduling new live test" do
Expand Down

0 comments on commit 04c64dd

Please sign in to comment.