Skip to content

Commit

Permalink
Add organization ID as parameter on update_organization
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraBeatris committed Dec 17, 2023
1 parent a697d93 commit 3397781
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/workos/organizations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ defmodule WorkOS.Organizations do
* `:allow_profiles_outside_organization` - Whether the Connections within this Organization should allow Profiles that do not have a domain that is present in the set of the Organization’s User Email Domains.
"""
@spec update_organization(map()) :: WorkOS.Client.response(Organization.t())
@spec update_organization(WorkOS.Client.t(), map()) ::
@spec update_organization(String.t(), map()) :: WorkOS.Client.response(Organization.t())
@spec update_organization(WorkOS.Client.t(), String.t(), map()) ::
WorkOS.Client.response(Organization.t())
def update_organization(client \\ WorkOS.client(), opts)
when is_map_key(opts, :organization) and is_map_key(opts, :name) do
WorkOS.Client.put(client, Organization, "/organizations/#{opts[:organization]}", %{
def update_organization(client \\ WorkOS.client(), organization_id, opts)
when is_map_key(opts, :name) do
WorkOS.Client.put(client, Organization, "/organizations/#{organization_id}", %{
name: opts[:name],
domains: opts[:domains],
allow_profiles_outside_organization: !!opts[:allow_profiles_outside_organization]
Expand Down
5 changes: 3 additions & 2 deletions test/support/organizations_client_mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ defmodule WorkOS.Organizations.ClientMock do
Tesla.Mock.mock(fn request ->
%{api_key: api_key} = context

organization_id = opts |> Keyword.get(:assert_fields) |> Keyword.get(:organization)
organization_id = opts |> Keyword.get(:assert_fields) |> Keyword.get(:organization_id)
assert request.method == :put
assert request.url == "#{WorkOS.base_url()}/organizations/#{organization_id}"

Expand All @@ -158,7 +158,8 @@ defmodule WorkOS.Organizations.ClientMock do

body = Jason.decode!(request.body)

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

Expand Down
7 changes: 5 additions & 2 deletions test/workos/organizations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ defmodule WorkOS.OrganizationsTest do
describe "update_organization" do
test "with a valid payload, updates an organization", context do
opts = [
organization: "org_01EHT88Z8J8795GZNQ4ZP1J81T",
organization_id: "org_01EHT88Z8J8795GZNQ4ZP1J81T",
domains: ["example.com"],
name: "Test Organization 2"
]

context |> ClientMock.update_organization(assert_fields: opts)

assert {:ok, %WorkOS.Organizations.Organization{id: id}} =
WorkOS.Organizations.update_organization(opts |> Enum.into(%{}))
WorkOS.Organizations.update_organization(
opts |> Keyword.get(:organization_id),
opts |> Enum.into(%{})
)

refute is_nil(id)
end
Expand Down

0 comments on commit 3397781

Please sign in to comment.