/
organization_domains_client_mock.ex
80 lines (58 loc) · 2.45 KB
/
organization_domains_client_mock.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
defmodule WorkOS.OrganizationDomains.ClientMock do
@moduledoc false
use ExUnit.Case
@organization_domain_mock %{
"object" => "organization_domain",
"id" => "org_domain_01HCZRAP3TPQ0X0DKJHR32TATG",
"domain" => "workos.com",
"state" => "verified",
"verification_token" => nil,
"verification_strategy" => "manual"
}
def get_organization_domain(context, opts \\ []) do
Tesla.Mock.mock(fn request ->
%{api_key: api_key} = context
organization_domain_id =
opts |> Keyword.get(:assert_fields) |> Keyword.get(:organization_domain_id)
assert request.method == :get
assert request.url == "#{WorkOS.base_url()}/organization_domains/#{organization_domain_id}"
assert Enum.find(request.headers, &(elem(&1, 0) == "Authorization")) ==
{"Authorization", "Bearer #{api_key}"}
success_body = @organization_domain_mock
{status, body} = Keyword.get(opts, :respond_with, {200, success_body})
%Tesla.Env{status: status, body: body}
end)
end
def create_organization_domain(context, opts \\ []) do
Tesla.Mock.mock(fn request ->
%{api_key: api_key} = context
assert request.method == :post
assert request.url == "#{WorkOS.base_url()}/organization_domains"
assert Enum.find(request.headers, &(elem(&1, 0) == "Authorization")) ==
{"Authorization", "Bearer #{api_key}"}
body = Jason.decode!(request.body)
for {field, value} <-
Keyword.get(opts, :assert_fields, []) do
assert body[to_string(field)] == value
end
success_body = @organization_domain_mock
{status, body} = Keyword.get(opts, :respond_with, {200, success_body})
%Tesla.Env{status: status, body: body}
end)
end
def verify_organization_domain(context, opts \\ []) do
Tesla.Mock.mock(fn request ->
%{api_key: api_key} = context
organization_domain_id =
opts |> Keyword.get(:assert_fields) |> Keyword.get(:organization_domain_id)
assert request.method == :post
assert request.url ==
"#{WorkOS.base_url()}/organization_domains/#{organization_domain_id}/verify"
assert Enum.find(request.headers, &(elem(&1, 0) == "Authorization")) ==
{"Authorization", "Bearer #{api_key}"}
success_body = @organization_domain_mock
{status, body} = Keyword.get(opts, :respond_with, {200, success_body})
%Tesla.Env{status: status, body: body}
end)
end
end