/
identity_spec.rb
56 lines (43 loc) · 1.48 KB
/
identity_spec.rb
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
require 'spec_helper'
describe Dnsimple::Client, ".identity" do
subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").identity }
describe "#whoami" do
before do
stub_request(:get, %r{/v2/whoami$}).
to_return(read_http_fixture("whoami/success.http"))
end
it "builds the correct request" do
subject.whoami
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/whoami").
with(headers: { 'Accept' => 'application/json' })
end
it "returns the whoami" do
response = subject.whoami
expect(response).to be_a(Dnsimple::Response)
result = response.data
expect(result).to be_a(Dnsimple::Struct::Whoami)
end
context "when authenticated as account" do
before do
stub_request(:get, %r{/v2/whoami$}).
to_return(read_http_fixture("whoami/success_account.http"))
end
it "sets the account" do
result = subject.whoami.data
expect(result.account).to be_a(Dnsimple::Struct::Account)
expect(result.user).to be_nil
end
end
context "when authenticated as user" do
before do
stub_request(:get, %r{/v2/whoami$}).
to_return(read_http_fixture("whoami/success_user.http"))
end
it "sets the user" do
result = subject.whoami.data
expect(result.account).to be_nil
expect(result.user).to be_a(Dnsimple::Struct::User)
end
end
end
end