forked from nverinaud/ruby-mpns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP to add nested tags in raw notifications.
- Loading branch information
1 parent
803b37d
commit 5f289ce
Showing
4 changed files
with
100 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source "http://rubygems.org" | ||
|
||
gem 'htmlentities' | ||
gem 'builder' | ||
|
||
group :development do | ||
gem "shoulda", ">= 0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,63 @@ class TestRubyMpns < Test::Unit::TestCase | |
mpns = Object.new.extend MicrosoftPushNotificationService | ||
_, cls = mpns.send(:build_notification, :tile) | ||
assert_equal cls, '1' | ||
_, cls = mpns.send(:build_notification, :toast, {title: 'title', content: 'content', params: {}}) | ||
_, cls = mpns.send(:build_notification, :toast) | ||
assert_equal cls, '2' | ||
_, cls = mpns.send(:build_notification, :raw) | ||
assert_equal cls, '3' | ||
end | ||
|
||
should 'format params like a boss' do | ||
mpns = Object.new.extend MicrosoftPushNotificationService | ||
q = mpns.send(:format_params, { a: 1, b: 2 }) | ||
assert_equal q, '?a=1&b=2' | ||
q = mpns.send(:format_params, { phone: '+0987 654321', email: '[email protected]' }) | ||
assert_equal q, '?phone=+0987 654321&[email protected]' | ||
end | ||
|
||
should 'make tile XML' do | ||
mpns = Object.new.extend MicrosoftPushNotificationService | ||
xml, _ = mpns.send(:tile_notification_with_options, | ||
{ title: 'title', count: 1337, | ||
background_image: 'bg', back_title: 'bktitle', | ||
back_background_image: 'bkbg', | ||
back_content: 'bkcontent', | ||
navigation_uri: 'uri' }) | ||
assert_equal xml, '<?xml version="1.0" encoding="UTF-8"?>' + | ||
'<wp:Notification xmlns:wp="WPNotification">' + | ||
'<wp:Tile Id="uri">' + | ||
'<wp:BackgroundImage>bg</wp:BackgroundImage>' + | ||
'<wp:Count>1337</wp:Count>' + | ||
'<wp:Title>title</wp:Title>' + | ||
'<wp:BackBackgroundImage>bkbg</wp:BackBackgroundImage>' + | ||
'<wp:BackTitle>bktitle</wp:BackTitle>' + | ||
'<wp:BackContent>bkcontent</wp:BackContent>' + | ||
'</wp:Tile>' + | ||
'</wp:Notification>' | ||
end | ||
|
||
should 'make toast XML' do | ||
mpns = Object.new.extend MicrosoftPushNotificationService | ||
xml, _ = mpns.send(:toast_notification_with_options, | ||
{ title: 'title', content: 'content', params: {} }) | ||
assert_equal xml, '<?xml version="1.0" encoding="UTF-8"?>' + | ||
'<wp:Notification xmlns:wp="WPNotification">' + | ||
'<wp:Toast>' + | ||
'<wp:Text1>title</wp:Text1>' + | ||
'<wp:Text2>content</wp:Text2>' + | ||
'<wp:Param>?</wp:Param>' + | ||
'</wp:Toast>' + | ||
'</wp:Notification>' | ||
end | ||
|
||
should 'make raw XML' do | ||
mpns = Object.new.extend MicrosoftPushNotificationService | ||
xml, _ = mpns.send(:raw_notification_with_options, | ||
{ key1: 'val1', key2: 'val2' }) | ||
assert_equal xml, '<?xml version="1.0" encoding="UTF-8"?>' + | ||
'<root>' + | ||
'<key1>val1</key1>' + | ||
'<key2>val2</key2>' + | ||
'</root>' | ||
end | ||
end |