Skip to content

Commit

Permalink
Merge pull request #52 from sorich87/hotfix/read-was-never-working
Browse files Browse the repository at this point in the history
Read was never working
  • Loading branch information
nashby authored Jul 27, 2016
2 parents 461400d + 2b84549 commit a72a09c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/facebook/messenger/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Bot

base_uri 'https://graph.facebook.com/v2.6/me'

EVENTS = [:message, :delivery, :postback, :optin].freeze
EVENTS = [:message, :delivery, :postback, :optin, :read].freeze

class << self
# Deliver a message with the given payload.
Expand Down
51 changes: 51 additions & 0 deletions spec/facebook/messenger/incoming/read_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

describe Facebook::Messenger::Incoming::Read do
let :payload do
{
'sender' => {
'id' => '3'
},
'recipient' => {
'id' => '3'
},
'timestamp' => 145_776_419_762_7,
'read' => {
'watermark' => 145_866_885_625_3,
'seq' => 38
}
}
end

subject { Facebook::Messenger::Incoming::Read.new(payload) }

describe '.messaging' do
it 'returns the original payload' do
expect(subject.messaging).to eq(payload)
end
end

describe '.sender' do
it 'returns the sender' do
expect(subject.sender).to eq(payload['sender'])
end
end

describe '.recipient' do
it 'returns the recipient' do
expect(subject.recipient).to eq(payload['recipient'])
end
end

describe '.at' do
it 'returns when the message was read' do
expect(subject.at).to eq(Time.at(payload['read']['watermark'] / 1000))
end
end

describe '.seq' do
it 'returns the read sequence number' do
expect(subject.seq).to eq(payload['read']['seq'])
end
end
end
24 changes: 24 additions & 0 deletions spec/facebook/messenger/incoming_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,29 @@
)
end
end

context 'when the payload is a read' do
let :payload do
{
'sender' => {
'id' => '3'
},
'recipient' => {
'id' => '3'
},
'timestamp' => 145_776_419_762_7,
'read' => {
'watermark' => 145_866_885_625_3,
'seq' => 38
}
}
end

it 'returns an Incoming::Read' do
expect(subject.parse(payload)).to be_a(
Facebook::Messenger::Incoming::Read
)
end
end
end
end

0 comments on commit a72a09c

Please sign in to comment.