@@ -156,184 +156,10 @@ defmodule CadetWeb.UserControllerTest do
156156 assert expected == resp
157157 end
158158
159- # # This also tests for the case where assessment has no submission
160- # @tag authenticate: :student
161- # test "success, student story ordering", %{conn: conn} do
162- # early_assessments = build_assessments_starting_at(Timex.shift(Timex.now(), days: -3))
163- # late_assessments = build_assessments_starting_at(Timex.shift(Timex.now(), days: -1))
164-
165- # for assessment <- early_assessments ++ late_assessments do
166- # resp_story =
167- # conn
168- # |> get("/v2/user")
169- # |> json_response(200)
170- # |> Map.get("latestViewedCourse").story
171-
172- # expected_story = %{
173- # "story" => assessment.story,
174- # "playStory" => true
175- # }
176-
177- # assert resp_story == expected_story
178-
179- # {:ok, _} = Repo.delete(assessment)
180- # end
181- # end
182-
183- # @tag authenticate: :student
184- # test "success, student story skips assessment without story", %{conn: conn} do
185- # assessments = build_assessments_starting_at(Timex.shift(Timex.now(), days: -1))
186-
187- # assessments
188- # |> List.first()
189- # |> Assessment.changeset(%{story: nil})
190- # |> Repo.update()
191-
192- # resp_story =
193- # conn
194- # |> get("/v2/user")
195- # |> json_response(200)
196- # |> Map.get("story")
197-
198- # expected_story = %{
199- # "story" => Enum.fetch!(assessments, 1).story,
200- # "playStory" => true
201- # }
202-
203- # assert resp_story == expected_story
204- # end
205-
206- # @tag authenticate: :student
207- # test "success, student story skips unopen assessments", %{conn: conn} do
208- # build_assessments_starting_at(Timex.shift(Timex.now(), days: 1))
209- # build_assessments_starting_at(Timex.shift(Timex.now(), months: -1))
210-
211- # valid_assessments = build_assessments_starting_at(Timex.shift(Timex.now(), days: -1))
212-
213- # for assessment <- valid_assessments do
214- # assessment
215- # |> Assessment.changeset(%{is_published: false})
216- # |> Repo.update!()
217- # end
218-
219- # resp_story =
220- # conn
221- # |> get("/v2/user")
222- # |> json_response(200)
223- # |> Map.get("story")
224-
225- # expected_story = %{
226- # "story" => nil,
227- # "playStory" => false
228- # }
229-
230- # assert resp_story == expected_story
231- # end
232-
233- # @tag authenticate: :student
234- # test "success, student story skips attempting/attempted/submitted", %{conn: conn} do
235- # user = conn.assigns.current_user
236-
237- # early_assessments = build_assessments_starting_at(Timex.shift(Timex.now(), days: -3))
238- # late_assessments = build_assessments_starting_at(Timex.shift(Timex.now(), days: -1))
239-
240- # # Submit for i-th assessment, expect (i+1)th story to be returned
241- # for status <- [:attempting, :attempted, :submitted] do
242- # for [tester, checker] <-
243- # Enum.chunk_every(early_assessments ++ late_assessments, 2, 1, :discard) do
244- # insert(:submission, %{student: user, assessment: tester, status: status})
245-
246- # resp_story =
247- # conn
248- # |> get("/v2/user")
249- # |> json_response(200)
250- # |> Map.get("story")
251-
252- # expected_story = %{
253- # "story" => checker.story,
254- # "playStory" => true
255- # }
256-
257- # assert resp_story == expected_story
258- # end
259-
260- # Repo.delete_all(Submission)
261- # end
262- # end
263-
264- # @tag authenticate: :student
265- # test "success, return most recent assessment when all are attempted", %{conn: conn} do
266- # user = conn.assigns.current_user
267-
268- # early_assessments = build_assessments_starting_at(Timex.shift(Timex.now(), days: -3))
269- # late_assessments = build_assessments_starting_at(Timex.shift(Timex.now(), days: -1))
270-
271- # for assessment <- early_assessments ++ late_assessments do
272- # insert(:submission, %{student: user, assessment: assessment, status: :attempted})
273- # end
274-
275- # resp_story =
276- # conn
277- # |> get("/v2/user")
278- # |> json_response(200)
279- # |> Map.get("story")
280-
281- # expected_story = %{
282- # "story" => late_assessments |> List.first() |> Map.get(:story),
283- # "playStory" => false
284- # }
285-
286- # assert resp_story == expected_story
287- # end
288-
289- # @tag authenticate: :staff
290- # test "success, staff", %{conn: conn} do
291- # user = conn.assigns.current_user
292-
293- # resp =
294- # conn
295- # |> get("/v2/user")
296- # |> json_response(200)
297- # |> Map.delete("story")
298-
299- # expected = %{
300- # "name" => user.name,
301- # "role" => "#{user.role}",
302- # "group" => nil,
303- # "grade" => 0,
304- # "maxGrade" => 0,
305- # "xp" => 0,
306- # "gameStates" => %{},
307- # "userId" => user.id
308- # }
309-
310- # assert expected == resp
311- # end
312-
313159 test "unauthorized" , % { conn: conn } do
314160 conn = get ( conn , "/v2/user" , nil )
315161 assert response ( conn , 401 ) =~ "Unauthorised"
316162 end
317-
318- # defp build_assessments_starting_at(time) do
319- # type_order_map =
320- # Assessment.assessment_types()
321- # |> Enum.with_index()
322- # |> Enum.reduce(%{}, fn {type, idx}, acc -> Map.put(acc, type, idx) end)
323-
324- # Assessment.assessment_types()
325- # |> Enum.map(
326- # &build(:assessment, %{
327- # type: &1,
328- # is_published: true,
329- # open_at: time,
330- # close_at: Timex.shift(time, days: 10)
331- # })
332- # )
333- # |> Enum.shuffle()
334- # |> Enum.map(&insert(&1))
335- # |> Enum.sort(&(type_order_map[&1.type] < type_order_map[&2.type]))
336- # end
337163 end
338164
339165 describe "GET /v2/user/latest_viewed_course" do
0 commit comments