-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Send from Deribit connection
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Tai.Events.StreamTerminate do | ||
alias __MODULE__ | ||
|
||
@type venue :: Tai.Venue.id() | ||
@type t :: %StreamTerminate{venue: venue, reason: term} | ||
|
||
@enforce_keys ~w(venue reason)a | ||
defstruct ~w(venue reason)a | ||
end | ||
|
||
defimpl TaiEvents.LogEvent, for: Tai.Events.StreamTerminate do | ||
def to_data(event) do | ||
keys = | ||
event | ||
|> Map.keys() | ||
|> Enum.filter(&(&1 != :__struct__)) | ||
|
||
event | ||
|> Map.take(keys) | ||
|> Map.put(:reason, event.reason |> inspect) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Tai.Events.StreamTerminateTest do | ||
use ExUnit.Case, async: true | ||
|
||
@base_attrs %{ | ||
venue: :venue_a, | ||
reason: {:remote, :normal} | ||
} | ||
|
||
test ".to_data/1 transforms reason to a string" do | ||
event = struct!(Tai.Events.StreamTerminate, @base_attrs) | ||
|
||
assert %{} = json = TaiEvents.LogEvent.to_data(event) | ||
assert json.venue == :venue_a | ||
assert json.reason == "{:remote, :normal}" | ||
end | ||
end |