Skip to content

Commit

Permalink
add hosted streaks to my_streaks #1
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Mar 9, 2015
1 parent 76f3555 commit 1af8f74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
12 changes: 9 additions & 3 deletions applications/api.moon
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ format_user = (u) ->
format_streak = do
fields = {"id", "start_date", "end_date", "hour_offset"}
(s) ->
import Streaks from require "models"
out = {f, s[f] for f in *fields}
out.host = format_user s\get_user!
out.publish_status = Streaks.publish_statuses\to_name s.publish_status
out

class StreakApi extends lapis.Application
Expand Down Expand Up @@ -61,11 +63,15 @@ class StreakApi extends lapis.Application
active = @current_user\find_participating_streaks(state: "active", :prepare_results)\get_page!
upcoming = @current_user\find_participating_streaks(state: "upcoming", :prepare_results)\get_page!
completed = @current_user\find_participating_streaks(state: "completed", :prepare_results)\get_page!
hosted = @current_user\find_hosted_streaks(:prepare_results)\get_page!

json: {
active: [format_streak s for s in *active]
upcoming: [format_streak s for s in *upcoming]
completed: [format_streak s for s in *completed]
joined: {
active: [format_streak s for s in *active]
upcoming: [format_streak s for s in *upcoming]
completed: [format_streak s for s in *completed]
}
hosted: [format_streak s for s in *hosted]
}


Expand Down
22 changes: 15 additions & 7 deletions spec/applications/api_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ describe "api", ->
status, res = request_with_key "/api/1/my-streaks"
assert.same 200, status
assert.same {
upcoming: {}
active: {}
completed: {}
hosted: {}
joined: {
upcoming: {}
active: {}
completed: {}
}
}, res


it "should get my-streaks with streaks", ->
it "should get my-streaks with joined streaks", ->
s1 = factory.Streaks state: "before_start"
s2 = factory.Streaks state: "after_end"
s3 = factory.Streaks state: "during"
Expand All @@ -84,7 +87,12 @@ describe "api", ->
status, res = request_with_key "/api/1/my-streaks"
assert.same 200, status

assert.same {}, res.active
assert.same {s1.id}, [s.id for s in *res.upcoming]
assert.same {s2.id}, [s.id for s in *res.completed]
assert.same {}, res.joined.active
assert.same {s1.id}, [s.id for s in *res.joined.upcoming]
assert.same {s2.id}, [s.id for s in *res.joined.completed]

it "should get my-streaks with hosted streaks", ->
s = factory.Streaks state: "before_start", user_id: current_user.id
status, res = request_with_key "/api/1/my-streaks"
assert.same {s.id}, [s.id for s in *res.hosted]

0 comments on commit 1af8f74

Please sign in to comment.