Skip to content

Commit

Permalink
Merge branch 'main' into v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulAsjes authored Aug 29, 2024
2 parents ed03749 + 347b831 commit ad2d158
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 47 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/elixir.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ jobs:
if: matrix.lint
run: mix compile --warnings-as-errors

- name: Check linter
if: matrix.lint
run: mix credo --strict -a

- name: Run tests
run: mix test

Expand Down
21 changes: 17 additions & 4 deletions lib/workos/user_management/authentication.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,35 @@ defmodule WorkOS.UserManagement.Authentication do

@type t() :: %__MODULE__{
user: User.t(),
organization_id: String.t() | nil
organization_id: String.t() | nil,
access_token: String.t() | nil,
refresh_token: String.t() | nil,
impersonator: User.t() | nil,
authentication_method: String.t()
}

@enforce_keys [
:user
:user,
:authentication_method
]
defstruct [
:user,
:organization_id
:organization_id,
:access_token,
:refresh_token,
:impersonator,
:authentication_method
]

@impl true
def cast(map) do
%__MODULE__{
user: map["user"],
organization_id: map["organization_id"]
organization_id: map["organization_id"],
access_token: map["access_token"],
refresh_token: map["refresh_token"],
impersonator: map["impersonator"],
authentication_method: map["authentication_method"]
}
end
end
17 changes: 14 additions & 3 deletions test/support/user_management_client_mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ defmodule WorkOS.UserManagement.ClientMock do
"organization_id" => "organization_01H5JQDV7R7ATEYZDEG0W5PRYS"
}

@authentication_code_mock %{
"user" => @user_mock,
"organization_id" => "organization_01H5JQDV7R7ATEYZDEG0W5PRYS",
"access_token" => "01DMEK0J53CVMC32CK5SE0KZ8Q",
"refresh_token" => "01DMEK0J53CVMC32CK5SE0KZ8Q",
"authentication_method" => "SSO"
}

def get_user(context, opts \\ []) do
Tesla.Mock.mock(fn request ->
%{api_key: api_key} = context
Expand Down Expand Up @@ -183,12 +191,15 @@ defmodule WorkOS.UserManagement.ClientMock do

body = Jason.decode!(request.body)

for {field, value} <-
Keyword.get(opts, :assert_fields, []) do
for {field, value} <- Keyword.get(opts, :assert_fields, []) do
assert body[to_string(field)] == value
end

success_body = @authentication_mock
success_body =
case body do
%{"code" => _} -> @authentication_code_mock
_ -> @authentication_mock
end

{status, body} = Keyword.get(opts, :respond_with, {200, success_body})
%Tesla.Env{status: status, body: body}
Expand Down
6 changes: 4 additions & 2 deletions test/workos/user_management_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ defmodule WorkOS.UserManagementTest do

context |> ClientMock.authenticate(assert_fields: opts)

assert {:ok, %WorkOS.UserManagement.Authentication{user: user}} =
assert {:ok, auth = %WorkOS.UserManagement.Authentication{}} =
WorkOS.UserManagement.authenticate_with_code(opts |> Enum.into(%{}))

refute is_nil(user["id"])
refute is_nil(auth.user["id"])
refute is_nil(auth.access_token)
refute is_nil(auth.refresh_token)
end
end

Expand Down

0 comments on commit ad2d158

Please sign in to comment.