|
45 | 45 | end |
46 | 46 | end |
47 | 47 |
|
| 48 | + context 'with an unknown message type' do |
| 49 | + let(:webhook) do |
| 50 | + <<~JSON |
| 51 | + { |
| 52 | + "destination": "xxxxxxxxxx", |
| 53 | + "events": [ |
| 54 | + { |
| 55 | + "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA", |
| 56 | + "type": "message", |
| 57 | + "mode": "active", |
| 58 | + "timestamp": 1462629479859, |
| 59 | + "source": { |
| 60 | + "type": "group", |
| 61 | + "groupId": "Ca56f94637c...", |
| 62 | + "userId": "U4af4980629..." |
| 63 | + }, |
| 64 | + "webhookEventId": "01FZ74A0TDDPYRVKNK77XKC3ZR", |
| 65 | + "deliveryContext": { |
| 66 | + "isRedelivery": false |
| 67 | + }, |
| 68 | + "message": { |
| 69 | + "id": "444573844083572737", |
| 70 | + "type": "hoge", |
| 71 | + "quoteToken": "q3Plxr4AgKd...", |
| 72 | + "text": "Test Message" |
| 73 | + } |
| 74 | + } |
| 75 | + ] |
| 76 | + } |
| 77 | + JSON |
| 78 | + end |
| 79 | + |
| 80 | + it 'parses the webhook as a text MessageEvent' do |
| 81 | + events = parser.parse(webhook, signature) |
| 82 | + expect(events).not_to be_empty |
| 83 | + |
| 84 | + event = events.first |
| 85 | + expect(event).to be_a(Line::Bot::V2::Webhook::MessageEvent) |
| 86 | + expect(event.reply_token).to eq('nHuyWiB7yP5Zw52FIkcQobQuGDXCTA') |
| 87 | + expect(event.type).to eq('message') |
| 88 | + expect(event.mode).to eq('active') |
| 89 | + expect(event.timestamp).to eq(1462629479859) |
| 90 | + expect(event.source).to be_a(Line::Bot::V2::Webhook::GroupSource) |
| 91 | + expect(event.source.type).to eq('group') |
| 92 | + expect(event.source.group_id).to eq('Ca56f94637c...') |
| 93 | + expect(event.source.user_id).to eq('U4af4980629...') |
| 94 | + expect(event.webhook_event_id).to eq('01FZ74A0TDDPYRVKNK77XKC3ZR') |
| 95 | + expect(event.delivery_context).to be_a(Line::Bot::V2::Webhook::DeliveryContext) |
| 96 | + expect(event.delivery_context.is_redelivery).to be false |
| 97 | + expect(event.message).to be_a(OpenStruct) |
| 98 | + expect(event.message.id).to eq('444573844083572737') |
| 99 | + expect(event.message.type).to eq('hoge') |
| 100 | + expect(event.message.quote_token).to eq('q3Plxr4AgKd...') |
| 101 | + expect(event.message.text).to eq('Test Message') |
| 102 | + end |
| 103 | + end |
| 104 | + |
48 | 105 | context 'with a text MessageEvent' do |
49 | 106 | let(:webhook) do |
50 | 107 | <<~JSON |
|
0 commit comments