Skip to content

Commit

Permalink
fix failing test for accummulate_item_timers/1 #145 #356 #410
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Aug 27, 2023
1 parent d795b1f commit e54e3d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
11 changes: 1 addition & 10 deletions lib/app/item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ defmodule App.Item do
# dbg(all_list)
# |> Enum.join(",")
seq = App.ListItems.get_list_items(all_list.cid)
|> dbg()

sql = """
SELECT i.id, i.cid, i.text, i.status, i.person_id, i.updated_at,
Expand Down Expand Up @@ -401,15 +400,7 @@ defmodule App.Item do
end)

# return the list of items in the order of seq
Enum.map(seq, fn cid ->
dbg(cid)
cid_item_map[cid]
end)
# |> dbg()
# Return the list of items without duplicates and only the last/active timer:
# Map.values(cid_item_map)
# Sort list by item.id descending (ordered by timer_id ASC above) so newest item first:
# |> Enum.sort_by(fn i -> i.id end, :desc)
Enum.map(seq, fn cid -> cid_item_map[cid] end)
end

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down
21 changes: 8 additions & 13 deletions test/app/item_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ defmodule App.ItemTest do
start: nil,
text: "This item has no timers",
timer_id: nil,
li_id: 1,
position: 1.0
cid: "3"
},
%{
stop: ~N[2022-07-17 11:18:10.000000],
Expand All @@ -128,8 +127,7 @@ defmodule App.ItemTest do
text:
"Item #2 has one active (no end) and one complete timer should total 17sec",
timer_id: 3,
li_id: 2,
position: 2.0
cid: "2"
},
%{
stop: nil,
Expand All @@ -138,8 +136,7 @@ defmodule App.ItemTest do
text:
"Item #2 has one active (no end) and one complete timer should total 17sec",
timer_id: 4,
li_id: 3,
position: 3.0
cid: "2"
},
%{
stop: ~N[2022-07-17 11:18:31.000000],
Expand All @@ -148,8 +145,7 @@ defmodule App.ItemTest do
text:
"Item with 3 complete timers that should add up to 42 seconds elapsed",
timer_id: 2,
li_id: 4,
position: 2.999999
cid: "1"
},
%{
stop: ~N[2022-07-17 11:18:24.000000],
Expand All @@ -158,8 +154,7 @@ defmodule App.ItemTest do
text:
"Item with 3 complete timers that should add up to 42 seconds elapsed",
timer_id: 1,
li_id: 5,
position: 4.0
cid: "1"
},
%{
stop: ~N[2022-07-17 11:19:42.000000],
Expand All @@ -168,14 +163,14 @@ defmodule App.ItemTest do
text:
"Item with 3 complete timers that should add up to 42 seconds elapsed",
timer_id: 5,
li_id: 42,
position: 42.0
cid: "1"
}
]

# The *interesting* timer is the *active* one (started seven_seconds_ago) ...
# The "hard" part to test in accumulating timers are the *active* ones ...
acc = Item.accumulate_item_timers(items_with_timers)
seq = ["3", "2", "1"]
acc = Item.accumulate_item_timers(items_with_timers, seq)
item_map = Map.new(acc, fn item -> {item.id, item} end)
item1 = Map.get(item_map, 1)
item2 = Map.get(item_map, 2)
Expand Down

0 comments on commit e54e3d1

Please sign in to comment.