Skip to content

Commit 1af8f74

Browse files
committed
add hosted streaks to my_streaks #1
1 parent 76f3555 commit 1af8f74

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

applications/api.moon

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ format_user = (u) ->
2424
format_streak = do
2525
fields = {"id", "start_date", "end_date", "hour_offset"}
2626
(s) ->
27+
import Streaks from require "models"
2728
out = {f, s[f] for f in *fields}
2829
out.host = format_user s\get_user!
30+
out.publish_status = Streaks.publish_statuses\to_name s.publish_status
2931
out
3032

3133
class StreakApi extends lapis.Application
@@ -61,11 +63,15 @@ class StreakApi extends lapis.Application
6163
active = @current_user\find_participating_streaks(state: "active", :prepare_results)\get_page!
6264
upcoming = @current_user\find_participating_streaks(state: "upcoming", :prepare_results)\get_page!
6365
completed = @current_user\find_participating_streaks(state: "completed", :prepare_results)\get_page!
66+
hosted = @current_user\find_hosted_streaks(:prepare_results)\get_page!
6467

6568
json: {
66-
active: [format_streak s for s in *active]
67-
upcoming: [format_streak s for s in *upcoming]
68-
completed: [format_streak s for s in *completed]
69+
joined: {
70+
active: [format_streak s for s in *active]
71+
upcoming: [format_streak s for s in *upcoming]
72+
completed: [format_streak s for s in *completed]
73+
}
74+
hosted: [format_streak s for s in *hosted]
6975
}
7076

7177

spec/applications/api_spec.moon

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ describe "api", ->
6767
status, res = request_with_key "/api/1/my-streaks"
6868
assert.same 200, status
6969
assert.same {
70-
upcoming: {}
71-
active: {}
72-
completed: {}
70+
hosted: {}
71+
joined: {
72+
upcoming: {}
73+
active: {}
74+
completed: {}
75+
}
7376
}, res
7477

7578

76-
it "should get my-streaks with streaks", ->
79+
it "should get my-streaks with joined streaks", ->
7780
s1 = factory.Streaks state: "before_start"
7881
s2 = factory.Streaks state: "after_end"
7982
s3 = factory.Streaks state: "during"
@@ -84,7 +87,12 @@ describe "api", ->
8487
status, res = request_with_key "/api/1/my-streaks"
8588
assert.same 200, status
8689

87-
assert.same {}, res.active
88-
assert.same {s1.id}, [s.id for s in *res.upcoming]
89-
assert.same {s2.id}, [s.id for s in *res.completed]
90+
assert.same {}, res.joined.active
91+
assert.same {s1.id}, [s.id for s in *res.joined.upcoming]
92+
assert.same {s2.id}, [s.id for s in *res.joined.completed]
93+
94+
it "should get my-streaks with hosted streaks", ->
95+
s = factory.Streaks state: "before_start", user_id: current_user.id
96+
status, res = request_with_key "/api/1/my-streaks"
97+
assert.same {s.id}, [s.id for s in *res.hosted]
9098

0 commit comments

Comments
 (0)