Skip to content

Commit

Permalink
fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
Th3-M4jor committed Jun 22, 2024
1 parent cc30361 commit 38b9437
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/nostrum/cache/user_cache/ets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Nostrum.Cache.UserCache.ETS do

@table_name :nostrum_users

alias Nostrum.Snowflake
alias Nostrum.Struct.User
use Supervisor

Expand Down Expand Up @@ -54,7 +55,7 @@ defmodule Nostrum.Cache.UserCache.ETS do
# We don't know if the user_id is an atom or a string here.
user_id =
(Map.get(info, :id) || Map.get(info, "id"))
|> Nostrum.Snowflake.cast!()
|> Snowflake.cast!()

with {:ok, old_user} <- lookup(user_id),
new_user = User.to_struct(info, old_user),
Expand Down
3 changes: 2 additions & 1 deletion lib/nostrum/cache/user_cache/mnesia.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if Code.ensure_loaded?(:mnesia) do
@behaviour Nostrum.Cache.UserCache

alias Nostrum.Cache.UserCache
alias Nostrum.Snowflake
alias Nostrum.Struct.User
use Supervisor

Expand Down Expand Up @@ -86,7 +87,7 @@ if Code.ensure_loaded?(:mnesia) do
# We don't know if the user_id is an atom or a string here.
user_id =
(Map.get(payload, :id) || Map.get(payload, "id"))
|> Nostrum.Snowflake.cast!()
|> Snowflake.cast!()

:mnesia.activity(:sync_transaction, fn ->
case :mnesia.read(@table_name, user_id, :write) do
Expand Down
2 changes: 1 addition & 1 deletion lib/nostrum/struct/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ defmodule Nostrum.Struct.User do
end

@doc false
@spec to_struct(map(), nil) :: __MODULE__.t()
@spec to_struct(map(), nil | __MODULE__.t()) :: __MODULE__.t()
def to_struct(map, nil), do: to_struct(map)

def to_struct(map, old_user) do
Expand Down
2 changes: 1 addition & 1 deletion test/nostrum/cache/user_cache_meta_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule Nostrum.Cache.UserCacheMetaTest do

describe "update/1" do
test "returns `{nil, after}` on uncached user" do
payload = %{id: 8_284_967_893_178_597_859_421}
payload = %{id: 8_284_967_893_178_597}
expected = {nil, User.to_struct(payload)}
assert ^expected = @cache.update(payload)
end
Expand Down

0 comments on commit 38b9437

Please # to comment.