Set valid_until date.
This commit is contained in:
parent
a2ca3b8605
commit
34a1ce00ec
@ -18,9 +18,11 @@ def websub_subscription_request(conn, %{"nickname" => nickname} = params) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def websub_subscription_confirmation(conn, %{"id" => id, "hub.mode" => "subscribe", "hub.challenge" => challenge, "hub.topic" => topic}) do
|
# TODO: Extract this into the Websub module
|
||||||
|
def websub_subscription_confirmation(conn, %{"id" => id, "hub.mode" => "subscribe", "hub.challenge" => challenge, "hub.topic" => topic, "hub.lease_seconds" => lease_seconds}) do
|
||||||
with %WebsubClientSubscription{} = websub <- Repo.get_by(WebsubClientSubscription, id: id, topic: topic) do
|
with %WebsubClientSubscription{} = websub <- Repo.get_by(WebsubClientSubscription, id: id, topic: topic) do
|
||||||
change = Ecto.Changeset.change(websub, %{state: "accepted"})
|
valid_until = NaiveDateTime.add(NaiveDateTime.utc_now, String.to_integer(lease_seconds))
|
||||||
|
change = Ecto.Changeset.change(websub, %{state: "accepted", valid_until: valid_until})
|
||||||
{:ok, _websub} = Repo.update(change)
|
{:ok, _websub} = Repo.update(change)
|
||||||
conn
|
conn
|
||||||
|> send_resp(200, challenge)
|
|> send_resp(200, challenge)
|
||||||
|
@ -31,7 +31,7 @@ test "websub subscription confirmation", %{conn: conn} do
|
|||||||
"hub.mode" => "subscribe",
|
"hub.mode" => "subscribe",
|
||||||
"hub.topic" => websub.topic,
|
"hub.topic" => websub.topic,
|
||||||
"hub.challenge" => "some challenge",
|
"hub.challenge" => "some challenge",
|
||||||
"hub.lease_seconds" => 100
|
"hub.lease_seconds" => "100"
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = conn
|
conn = conn
|
||||||
@ -41,8 +41,7 @@ test "websub subscription confirmation", %{conn: conn} do
|
|||||||
|
|
||||||
assert response(conn, 200) == "some challenge"
|
assert response(conn, 200) == "some challenge"
|
||||||
assert websub.state == "accepted"
|
assert websub.state == "accepted"
|
||||||
|
assert_in_delta NaiveDateTime.diff(websub.valid_until, NaiveDateTime.utc_now), 100, 5
|
||||||
# TODO valid_until
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "handles incoming feed updates", %{conn: conn} do
|
test "handles incoming feed updates", %{conn: conn} do
|
||||||
|
Loading…
Reference in New Issue
Block a user