-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
manager_spec.rb
169 lines (135 loc) 路 5.78 KB
/
manager_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
describe Pilot do
describe Pilot::Manager do
let(:fake_manager) { Pilot::Manager.new }
let(:fake_api_key_json_path) do
"./spaceship/spec/connect_api/fixtures/asc_key.json"
end
let(:fake_api_key) do
JSON.parse(File.read(fake_api_key_json_path), { symbolize_names: true })
end
describe "what happens on 'start'" do
context "when 'config' variable is already set" do
before(:each) do
fake_manager.instance_variable_set(:@config, { api_key: fake_api_key })
end
it "doesn't override the 'config' variable value" do
options = {}
fake_manager.start(options)
expected_options = { api_key: fake_api_key }
expect(fake_manager.instance_variable_get(:@config)).to eq(expected_options)
end
it "doesn't call login" do
expect(fake_manager).not_to receive(:login)
options = {}
fake_manager.start(options)
end
end
context "when using the default 'should_login' value" do
before(:each) do
expect(fake_manager).to receive(:login)
end
it "sets the 'config' variable value and calls login" do
options = {}
fake_manager.start(options)
expect(fake_manager.instance_variable_get(:@config)).to eq(options)
end
end
context "when passing 'should_login' value as TRUE" do
before(:each) do
expect(fake_manager).to receive(:login)
end
it "sets the 'config' variable value and calls login" do
options = {}
fake_manager.start(options, should_login: true)
expect(fake_manager.instance_variable_get(:@config)).to eq(options)
end
end
context "when passing 'should_login' value as FALSE" do
context "when input options has no 'api_key' or 'api_key_path' param" do
before(:each) do
expect(fake_manager).not_to receive(:login)
end
it "sets the 'config' variable value and doesn't call login" do
options = {}
fake_manager.start(options, should_login: false)
expect(fake_manager.instance_variable_get(:@config)).to eq(options)
end
end
context "when input options has 'api_key' param" do
before(:each) do
expect(fake_manager).to receive(:login)
end
it "sets the 'config' variable value and calls login for appstore connect api token" do
options = { api_key: "fake_api_key" }
fake_manager.start(options, should_login: false)
expect(fake_manager.instance_variable_get(:@config)).to eq(options)
end
end
context "when input options has 'api_key_path' param" do
before(:each) do
expect(fake_manager).to receive(:login)
end
it "sets the 'config' variable value and calls login for appstore connect api token" do
options = { api_key_path: "fake api_key_path" }
fake_manager.start(options, should_login: false)
expect(fake_manager.instance_variable_get(:@config)).to eq(options)
end
end
end
end
describe "what happens on 'login'" do
context "when using app store connect api token" do
before(:each) do
allow(Spaceship::ConnectAPI)
.to receive(:token)
.and_return(Spaceship::ConnectAPI::Token.from(filepath: fake_api_key_json_path))
end
it "uses the existing API token if found" do
expect(Spaceship::ConnectAPI::Token).to receive(:from).with(hash: nil, filepath: nil).and_return(false)
expect(UI).to receive(:message).with("Using existing authorization token for App Store Connect API")
fake_manager.instance_variable_set(:@config, {})
fake_manager.login
end
it "creates and sets new API token using config api_key and api_key_path" do
expect(Spaceship::ConnectAPI::Token).to receive(:from).with(hash: "api_key", filepath: "api_key_path").and_return(true)
expect(UI).to receive(:message).with("Creating authorization token for App Store Connect API")
expect(Spaceship::ConnectAPI).to receive(:token=)
options = {}
options[:api_key] = "api_key"
options[:api_key_path] = "api_key_path"
fake_manager.instance_variable_set(:@config, options)
fake_manager.login
end
end
shared_examples "performing the spaceship login using username and password by pilot" do
before(:each) do
expect(fake_manager.config).to receive(:fetch).with(:username, force_ask: true)
expect(UI).to receive(:message).with("Login to App Store Connect (username)")
expect(Spaceship::ConnectAPI).to receive(:login)
expect(UI).to receive(:message).with("Login successful")
end
it "performs the login using username and password" do
fake_manager.login
end
end
context "when using web session" do
context "when username input param is given" do
before(:each) do
fake_manager.instance_variable_set(:@config, { username: "username" })
end
it_behaves_like "performing the spaceship login using username and password by pilot"
end
context "when username input param is not given but found apple_id in AppFile" do
before(:each) do
fake_manager.instance_variable_set(:@config, {})
allow(CredentialsManager::AppfileConfig)
.to receive(:try_fetch_value)
.with(:apple_id)
.and_return("username")
end
it_behaves_like "performing the spaceship login using username and password by pilot"
end
end
end
end
end