Skip to content

Commit eb6780d

Browse files
authored
Add spec for capability for unknown message type in webhook parsing (#430)
Add a spec to make sure that parsing does not fail if there is a `type` undefined in the SDK inside the webhook when the SDK is not up-to-date. The webhook type itself is already tested, and this PR further tests it with an internally nested message type.
1 parent 3fc5017 commit eb6780d

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

spec/line/bot/v2/webhook_parser_spec.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,63 @@
4545
end
4646
end
4747

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+
48105
context 'with a text MessageEvent' do
49106
let(:webhook) do
50107
<<~JSON

0 commit comments

Comments
 (0)