Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
f78fdd94
Commit
f78fdd94
authored
Sep 12, 2014
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add group_id to payload from notifications.
TNL-299
parent
2d2a05a1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
33 deletions
+77
-33
lib/helpers.rb
+5
-2
spec/api/notifications_spec.rb
+72
-31
No files found.
lib/helpers.rb
View file @
f78fdd94
...
...
@@ -255,14 +255,14 @@ helpers do
end
end
def
notifications_by_date_range_and_user_ids
start_date_time
,
end_date_time
,
user_ids
def
notifications_by_date_range_and_user_ids
(
start_date_time
,
end_date_time
,
user_ids
)
#given a date range and a user, find all of the notifiable content
#key by thread id, and return notification messages for each user
#first, find the subscriptions for the users
subscriptions
=
Subscription
.
where
(
:subscriber_id
.
in
=>
user_ids
)
#get the th
h
read ids
#get the thread ids
thread_ids
=
subscriptions
.
collect
{
|
t
|
t
.
source_id
}.
uniq
#find all the comments
...
...
@@ -308,6 +308,9 @@ helpers do
t
[
"content"
]
=
[]
t
[
"title"
]
=
current_thread
.
title
t
[
"commentable_id"
]
=
current_thread
.
commentable_id
unless
current_thread
.
group_id
.
nil?
t
[
"group_id"
]
=
current_thread
.
group_id
end
else
t
=
notification_map
[
u
][
c
.
course_id
][
c
.
comment_thread_id
.
to_s
]
end
...
...
spec/api/notifications_spec.rb
View file @
f78fdd94
...
...
@@ -8,35 +8,81 @@ describe "app" do
set_api_key_header
end
describe
"POST /api/v1/notifications"
do
it
"returns notifications by class and user"
do
start_time
=
Time
.
now
user
=
User
.
create
(
:external_id
=>
1
,
:username
=>
"example"
)
commentable
=
Commentable
.
new
(
"question_1"
)
random_string
=
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
thread
=
CommentThread
.
new
(
title:
"Test title"
,
body:
"elephant otter"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
,
comments_text_dummy:
random_string
)
thread
.
thread_type
=
:discussion
thread
.
author
=
user
thread
.
save!
def
create_thread
(
user
,
options
=
{})
# Create a CommentThread with the given user.
# Can optionally specify a cohort group_id via options.
# Returns the created CommentThread.
commentable
=
Commentable
.
new
(
"question_1"
)
random_string
=
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
thread
=
CommentThread
.
new
(
title:
"Test title"
,
body:
"elephant otter"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
,
comments_text_dummy:
random_string
)
thread
.
thread_type
=
:discussion
thread
.
author
=
user
if
options
[
:group_id
]
thread
.
group_id
=
options
[
:group_id
]
end
thread
.
save!
subscription
=
Subscription
.
create
({
:subscriber_id
=>
user
.
_id
.
to_s
,
:source_id
=>
thread
.
_id
.
to_s
})
return
thread
end
dummy
=
random_string
=
(
0
..
5
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
comment
=
Comment
.
new
comment
.
comment_thread_id
=
thread
.
id
comment
.
body
=
dummy
comment
.
author_id
=
user
.
id
comment
.
course_id
=
'test course'
comment
.
save!
def
get_thread_notification
(
comment_body
,
options
=
{})
# Creates a thread and comment with the specified comment_body.
# Can optionally specify a cohort group_id via options.
# Calls the notifications API to retrieve the notification for the thread
# and returns the response hash for the single comment thread within the course.
# Keys for the returned hash: content, title, commentable_id, group_id (only present if cohorted).
start_time
=
Time
.
now
user
=
User
.
create
(
:external_id
=>
1
,
:username
=>
"example"
)
thread
=
create_thread
(
user
,
options
)
subscription
=
Subscription
.
create
(
:subscriber_id
=>
user
.
_id
.
to_s
,
:source_id
=>
thread
.
_id
.
to_s
)
comment
=
Comment
.
new
comment
.
comment_thread_id
=
thread
.
id
comment
.
body
=
comment_body
comment
.
author_id
=
user
.
id
comment
.
course_id
=
'test course'
comment
.
save!
sleep
1
end_time
=
Time
.
now
post
(
"/api/v1/notifications"
,
{
from:
CGI
::
escape
(
start_time
.
to_s
),
to:
CGI
::
escape
(
end_time
.
to_s
),
user_ids:
subscription
.
subscriber_id
}
)
last_response
.
should
be_ok
response_hash
=
JSON
.
parse
(
last_response
.
body
)
return
response_hash
[
user
.
id
][
comment
.
course_id
][
thread
.
id
.
to_s
]
end
sleep
1
describe
"POST /api/v1/notifications"
do
it
"returns notifications by class and user"
do
expected_comment_body
=
random_string
=
(
0
..
5
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
thread_notification
=
get_thread_notification
(
expected_comment_body
)
actual_comment_body
=
thread_notification
[
"content"
][
0
][
"body"
]
actual_comment_body
.
should
eq
(
expected_comment_body
)
end
end_time
=
Time
.
now
it
"contains cohort group_id if defined"
do
thread_notification
=
get_thread_notification
(
"dummy comment content"
,
:group_id
=>
1974
)
thread_notification
[
"group_id"
].
should
be
(
1974
)
end
post
"/api/v1/notifications"
,
from:
CGI
::
escape
(
start_time
.
to_s
),
to:
CGI
::
escape
(
end_time
.
to_s
),
user_ids:
subscription
.
subscriber_id
last_response
.
should
be_ok
last_response
.
body
.
to_s
.
include?
(
dummy
).
should
==
true
it
"does not contain cohort group_id if not defined"
do
thread_notification
=
get_thread_notification
(
"dummy comment content"
)
thread_notification
.
has_key?
(
"group_id"
).
should
be_false
end
it
"returns only threads subscribed to by user"
do
...
...
@@ -44,16 +90,11 @@ describe "app" do
# first make a dummy thread and comment and a subscription
commentable
=
Commentable
.
new
(
"question_1"
)
user
=
User
.
create
(
:external_id
=>
1
,
:username
=>
"example"
)
random_string
=
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
thread
=
CommentThread
.
new
(
title:
"Test title"
,
body:
"elephant otter"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
,
comments_text_dummy:
random_string
)
thread
.
thread_type
=
:discussion
thread
.
author
=
user
thread
.
save!
thread
=
create_thread
(
user
)
subscription
=
Subscription
.
create
({
:subscriber_id
=>
user
.
_id
.
to_s
,
:source_id
=>
thread
.
_id
.
to_s
})
comment
=
Comment
.
new
(
body:
random_string
,
course_id:
"1"
,
commentable_id:
commentable
.
id
)
comment
=
Comment
.
new
(
body:
"dummy body text"
,
course_id:
"1"
,
commentable_id:
commentable
.
id
)
comment
.
author
=
user
comment
.
comment_thread
=
thread
comment
.
save!
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment