require 'spec_helper'
describe Notifiable::Mpns::Nverinaud::SingleNotifier do
let(:m) { Notifiable::Mpns::Nverinaud::SingleNotifier.new }
let(:d) { Notifiable::DeviceToken.create(:token => "http://db3.notify.live.net/throttledthirdparty/01.00/123456789123456798", :provider => :mpns) }
let(:u) { User.new(d) }
it "sends a notification with a title" do
n = Notifiable::Notification.create(title: "A title")
stub_request(:post, d.token)
m.send_notification(n, d)
m.close
Notifiable::NotificationDeviceToken.count.should == 1
a_request(:post, d.token)
.with(:body => "A title")
.should have_been_made.once
end
it "sends a single mpns notification with content" do
n = Notifiable::Notification.create(message: "A message")
stub_request(:post, d.token)
m.send_notification(n, d)
m.close
Notifiable::NotificationDeviceToken.count.should == 1
a_request(:post, d.token)
.with(:body => "A message")
.should have_been_made.once
end
it "sends custom attributes" do
n = Notifiable::Notification.create(:params => {:an_object_id => 123456})
stub_request(:post, d.token)
m.send_notification(n, d)
m.close
Notifiable::NotificationDeviceToken.count.should == 1
a_request(:post, d.token)
.with(:body => "?an_object_id=123456")
.should have_been_made.once
end
it "de-registers a device on receiving a 404 status from MPNS" do
n = Notifiable::Notification.create(:message => "A message")
stub_request(:post, d.token).to_return(:status => 404)
m.send_notification(n, d)
m.close
Notifiable::NotificationDeviceToken.count.should == 0
Notifiable::DeviceToken.first.is_valid.should == false
end
end