-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
161 additions
and
26 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 |
---|---|---|
|
@@ -20,7 +20,7 @@ module PlaceOS::Api | |
result.status_code.should eq 202 | ||
end | ||
|
||
it "should receive valid payload when google sends change notification" do | ||
it "should receive valid payload when google sends change notification to unscoped destination" do | ||
PlaceOS::Model::Authority.find_by_domain("localhost").not_nil! | ||
subscription_channel = "4ba78bf0-6a47-11e2-bcfd-0800200c9a66/event" | ||
|
||
|
@@ -63,6 +63,50 @@ module PlaceOS::Api | |
subs.terminate | ||
end | ||
end | ||
|
||
it "should receive valid payload when google sends change notification to scoped destination" do | ||
authority = PlaceOS::Model::Authority.find_by_domain("localhost").not_nil! | ||
subscription_channel = "#{authority.id}/4ba78bf0-6a47-11e2-bcfd-0800200c9a66/event" | ||
|
||
channel = Channel(String).new | ||
subs = PlaceOS::Driver::Subscriptions.new | ||
|
||
_subscription = subs.channel subscription_channel do |_, message| | ||
channel.send(message) | ||
end | ||
|
||
result = client.post("#{PushNotifications.base_route}/google", headers: HTTP::Headers{ | ||
"Host" => "localhost", | ||
"Content-Type" => "application/json", | ||
"Content-Length" => "0", | ||
"X-Goog-Channel-ID" => "4ba78bf0-6a47-11e2-bcfd-0800200c9a66", | ||
"X-Goog-Channel-Token" => "398348u3tu83ut8uu38", | ||
"X-Goog-Channel-Expiration" => "Fri, 26 May 2023 01:13:52 GMT", | ||
"X-Goog-Resource-ID" => "ret08u3rv24htgh289g", | ||
"X-Goog-Resource-URI" => "https://www.googleapis.com/calendar/v3/calendars/[email protected]/events", | ||
"X-Goog-Resource-State" => "exists", | ||
"X-Goog-Message-Number" => "1", | ||
}) | ||
result.status_code.should eq 202 | ||
|
||
begin | ||
select | ||
when message = channel.receive | ||
{ | ||
"event_type": "updated", | ||
"resource_id": "ret08u3rv24htgh289g", | ||
"resource_uri": "https://www.googleapis.com/calendar/v3/calendars/[email protected]/events", | ||
"subscription_id": "4ba78bf0-6a47-11e2-bcfd-0800200c9a66", | ||
"client_secret": "398348u3tu83ut8uu38", | ||
"expiration_time": 1685063632, | ||
}.to_json.should eq(message) | ||
when timeout 2.seconds | ||
raise "timeout" | ||
end | ||
ensure | ||
subs.terminate | ||
end | ||
end | ||
end | ||
|
||
describe "microsoft push notifications" do | ||
|
@@ -78,7 +122,64 @@ module PlaceOS::Api | |
result.body.should eq(token) | ||
end | ||
|
||
it "should receive valid payload when microsoft sends change notification" do | ||
it "should receive valid payload when microsoft sends change notification on scoped channel" do | ||
authority = PlaceOS::Model::Authority.find_by_domain("localhost").not_nil! | ||
subscription_channel = "#{authority.id}/f37536ac-b308-4bc7-b239-b2b51cd2ff24/event" | ||
|
||
channel = Channel(String).new | ||
subs = PlaceOS::Driver::Subscriptions.new | ||
|
||
_subscription = subs.channel subscription_channel do |_, message| | ||
channel.send(message) | ||
end | ||
|
||
payload = <<-'JSON' | ||
{ | ||
"value": [ | ||
{ | ||
"subscriptionId": "f37536ac-b308-4bc7-b239-b2b51cd2ff24", | ||
"subscriptionExpirationDateTime": "2023-05-26T23:29:18.2277768+00:00", | ||
"changeType": "created", | ||
"resource": "Users/2189c720-90d5-44ff-818b-fe585706ee90/Events/AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=", | ||
"resourceData": { | ||
"@odata.type": "#Microsoft.Graph.Event", | ||
"@odata.id": "Users/2189c720-90d5-44ff-818b-fe585706ee90/Events/AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=", | ||
"@odata.etag": "W/\"DwAAABYAAAAXxlVK8zI/TZLFIn9D86hXAAAEB/jr\"", | ||
"id": "AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=" | ||
}, | ||
"clientState": "secretClientState", | ||
"tenantId": "7f1d0cb7-93b9-405a-8dad-c21703b7af18" | ||
} | ||
] | ||
} | ||
JSON | ||
result = client.post("#{PushNotifications.base_route}/office365", body: payload, headers: HTTP::Headers{ | ||
"Host" => "localhost", | ||
"Content-Type" => "application/json", | ||
}) | ||
|
||
result.status_code.should eq 202 | ||
|
||
begin | ||
select | ||
when message = channel.receive | ||
{ | ||
"event_type": "created", | ||
"resource_id": "AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=", | ||
"resource_uri": "Users/2189c720-90d5-44ff-818b-fe585706ee90/Events/AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=", | ||
"subscription_id": "f37536ac-b308-4bc7-b239-b2b51cd2ff24", | ||
"client_secret": "secretClientState", | ||
"expiration_time": 1685143758, | ||
}.to_json.should eq(message) | ||
when timeout 2.seconds | ||
raise "timeout" | ||
end | ||
ensure | ||
subs.terminate | ||
end | ||
end | ||
|
||
it "should receive valid payload when microsoft sends change notification on unscoped channel" do | ||
PlaceOS::Model::Authority.find_by_domain("localhost").not_nil! | ||
subscription_channel = "f37536ac-b308-4bc7-b239-b2b51cd2ff24/event" | ||
|
||
|
@@ -136,8 +237,8 @@ module PlaceOS::Api | |
end | ||
|
||
it "should receive valid payload when microsoft sends lifecycle notification" do | ||
PlaceOS::Model::Authority.find_by_domain("localhost").not_nil! | ||
subscription_channel = "f37536ac-b308-4bc7-b239-b2b51cd2ff24/event" | ||
authority = PlaceOS::Model::Authority.find_by_domain("localhost").not_nil! | ||
subscription_channel = "#{authority.id}/f37536ac-b308-4bc7-b239-b2b51cd2ff24/event" | ||
|
||
channel = Channel(String).new | ||
subs = PlaceOS::Driver::Subscriptions.new | ||
|
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
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
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