-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
build_manager_spec.rb
723 lines (613 loc) 路 29.3 KB
/
build_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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
describe "Build Manager" do
describe ".truncate_changelog" do
it "Truncates Changelog if it exceeds character size" do
changelog = File.read("./pilot/spec/fixtures/build_manager/changelog_long")
changelog = Pilot::BuildManager.truncate_changelog(changelog)
expect(changelog).to eq(File.read("./pilot/spec/fixtures/build_manager/changelog_long_truncated"))
end
it "Truncates Changelog if it exceeds byte size" do
changelog = File.binread("./pilot/spec/fixtures/build_manager/changelog_bytes_long").force_encoding("UTF-8")
changelog = Pilot::BuildManager.truncate_changelog(changelog)
expect(changelog).to eq(File.binread("./pilot/spec/fixtures/build_manager/changelog_bytes_long_truncated").force_encoding("UTF-8"))
end
it "Keeps changelog if short enough" do
changelog = "1234"
changelog = Pilot::BuildManager.truncate_changelog(changelog)
expect(changelog).to eq("1234")
end
it "Truncates based on bytes not characters" do
changelog = "眉" * 4000
expect(changelog.unpack("C*").length).to eq(8000)
changelog = Pilot::BuildManager.truncate_changelog(changelog)
# Truncation appends "...", so the result is 1998 two-byte characters plus "..." for 3999 bytes.
expect(changelog.unpack("C*").length).to eq(3999)
end
end
describe ".sanitize_changelog" do
it "removes emoji" do
changelog = "I'm 馃B馃彠an馃!"
changelog = Pilot::BuildManager.sanitize_changelog(changelog)
expect(changelog).to eq("I'm Ban!")
end
it "removes less than symbols" do
changelog = "I'm <script>man<<!"
changelog = Pilot::BuildManager.sanitize_changelog(changelog)
expect(changelog).to eq("I'm script>man!")
end
it "removes prohibited symbols before truncating" do
changelog = File.read("./pilot/spec/fixtures/build_manager/changelog_long")
changelog = "馃帀<馃帀<馃帀#{changelog}馃帀<馃帀<馃帀"
changelog = Pilot::BuildManager.sanitize_changelog(changelog)
expect(changelog).to eq(File.read("./pilot/spec/fixtures/build_manager/changelog_long_truncated"))
end
end
describe ".has_changelog_or_whats_new?" do
let(:fake_build_manager) { Pilot::BuildManager.new }
let(:no_options) { {} }
let(:changelog) { { changelog: "Sup" } }
let(:whats_new_symbol) { { localized_build_info: { 'en-us' => { whats_new: 'Sup' } } } }
let(:whats_new_string) { { localized_build_info: { 'en-us' => { 'whats_new' => 'Sup' } } } }
it "returns false for no changelog or whats_new" do
has = fake_build_manager.has_changelog_or_whats_new?(no_options)
expect(has).to eq(false)
end
it "returns true for changelog" do
has = fake_build_manager.has_changelog_or_whats_new?(changelog)
expect(has).to eq(true)
end
it "returns true for whats_new with symbol" do
has = fake_build_manager.has_changelog_or_whats_new?(whats_new_symbol)
expect(has).to eq(true)
end
it "returns true for whats_new with string" do
has = fake_build_manager.has_changelog_or_whats_new?(whats_new_string)
expect(has).to eq(true)
end
end
describe "distribute submits the build for review" do
let(:mock_base_client) { "fake api base client" }
let(:fake_build_manager) { Pilot::BuildManager.new }
let(:app) do
Spaceship::ConnectAPI::App.new("123-123-123-123", {
name: "Mock App"
})
end
let(:pre_release_version) do
Spaceship::ConnectAPI::PreReleaseVersion.new("123-123-123-123", {
version: "1.0"
})
end
let(:app_localizations) do
[
Spaceship::ConnectAPI::BetaAppLocalization.new("234", {
feedbackEmail: 'email@email.com',
marketingUrl: 'https://url.com',
privacyPolicyUrl: 'https://url.com',
description: 'desc desc desc',
locale: 'en-us'
}),
Spaceship::ConnectAPI::BetaAppLocalization.new("432", {
feedbackEmail: 'email@email.com',
marketingUrl: 'https://url.com',
privacyPolicyUrl: 'https://url.com',
description: 'desc desc desc',
locale: 'en-gb'
})
]
end
let(:build_localizations) do
[
Spaceship::ConnectAPI::BetaBuildLocalization.new("234", {
whatsNew: 'some more words',
locale: 'en-us'
}),
Spaceship::ConnectAPI::BetaBuildLocalization.new("432", {
whatsNew: 'some words',
locale: 'en-gb'
})
]
end
let(:build_beta_detail_still_processing) do
Spaceship::ConnectAPI::BuildBetaDetail.new("321", {
internal_build_state: Spaceship::ConnectAPI::BuildBetaDetail::InternalState::PROCESSING,
external_build_state: Spaceship::ConnectAPI::BuildBetaDetail::ExternalState::PROCESSING
})
end
let(:build_beta_detail_missing_export_compliance) do
Spaceship::ConnectAPI::BuildBetaDetail.new("321", {
internal_build_state: Spaceship::ConnectAPI::BuildBetaDetail::InternalState::MISSING_EXPORT_COMPLIANCE,
external_build_state: Spaceship::ConnectAPI::BuildBetaDetail::ExternalState::MISSING_EXPORT_COMPLIANCE
})
end
let(:build_beta_detail) do
Spaceship::ConnectAPI::BuildBetaDetail.new("321", {
internal_build_state: Spaceship::ConnectAPI::BuildBetaDetail::InternalState::READY_FOR_BETA_TESTING,
external_build_state: Spaceship::ConnectAPI::BuildBetaDetail::ExternalState::READY_FOR_BETA_SUBMISSION
})
end
let(:beta_groups) do
[
Spaceship::ConnectAPI::BetaGroup.new("987", {
name: "Blue Man Group"
}),
Spaceship::ConnectAPI::BetaGroup.new("654", {
name: "Green Eggs and Ham"
})
]
end
let(:ready_to_submit_mock_build) do
Spaceship::ConnectAPI::Build.new("123", {
version: '',
uploadedDate: '',
processingState: Spaceship::ConnectAPI::Build::ProcessingState::VALID,
usesNonExemptEncryption: nil
})
end
let(:distribute_options) do
{
apple_id: 'mock_apple_id',
app_identifier: 'mock_app_id',
distribute_external: true,
groups: ["Blue Man Group"],
skip_submission: false
}
end
let(:mock_api_client_beta_app_localizations) do
[
{ "id" => "234", "attributes" => { "locale" => "en-us" } },
{ "id" => "432", "attributes" => { "locale" => "en-gb" } }
]
end
let(:mock_api_client_beta_build_localizations) do
[
{ "id" => "234", "attributes" => { "locale" => "en-us" } },
{ "id" => "432", "attributes" => { "locale" => "en-gb" } }
]
end
let(:mock_api_client_beta_groups) do
[
{ "id" => "987", "attributes" => { "name" => "Blue Man Group" } },
{ "id" => "654", "attributes" => { "name" => "Green Eggs and Ham" } }
]
end
describe "distribute success" do
let(:distribute_options_skip_waiting_non_localized_changelog) do
{
apple_id: 'mock_apple_id',
app_identifier: 'mock_app_id',
distribute_external: false,
skip_submission: false,
skip_waiting_for_build_processing: true,
notify_external_testers: true,
uses_non_exempt_encryption: false,
changelog: "log of changing"
}
end
let(:distribute_options_non_localized) do
{
apple_id: 'mock_apple_id',
app_identifier: 'mock_app_id',
distribute_external: true,
groups: ["Blue Man Group"],
skip_submission: false,
demo_account_required: true,
notify_external_testers: true,
beta_app_feedback_email: "josh+oldfeedback@rokkincat.com",
beta_app_description: "old description for all the things",
uses_non_exempt_encryption: false,
changelog: "log of changing"
}
end
before(:each) do
allow(fake_build_manager).to receive(:login)
allow(mock_base_client).to receive(:team_id).and_return('')
allow(Spaceship::ConnectAPI).to receive(:post_beta_app_review_submissions) # pretend it worked.
allow(Spaceship::ConnectAPI::TestFlight).to receive(:instance).and_return(mock_base_client)
# Allow build to return app, buidl_beta_detail, and pre_release_version
# These are models that are expected to usually be included in the build passed into distribute
allow(ready_to_submit_mock_build).to receive(:app).and_return(app)
allow(ready_to_submit_mock_build).to receive(:pre_release_version).and_return(pre_release_version)
end
it "updates non-localized changelog and doesn't distribute" do
expect(ready_to_submit_mock_build).to receive(:build_beta_detail).and_return(build_beta_detail_still_processing).exactly(4).times
options = distribute_options_skip_waiting_non_localized_changelog
# Expect beta build localizations to be fetched
expect(Spaceship::ConnectAPI).to receive(:get_beta_build_localizations).with({
filter: { build: ready_to_submit_mock_build.id },
includes: nil,
limit: nil,
sort: nil
}).and_return(Spaceship::ConnectAPI::Response.new)
expect(ready_to_submit_mock_build).to receive(:get_beta_build_localizations).and_wrap_original do |m, *args|
m.call(*args)
build_localizations
end
# Expect beta build localizations to be patched with a UI.success after
mock_api_client_beta_build_localizations.each do |localization|
expect(Spaceship::ConnectAPI).to receive(:patch_beta_build_localizations).with({
localization_id: localization['id'],
attributes: {
whatsNew: options[:changelog]
}
})
end
expect(FastlaneCore::UI).to receive(:success).with("Successfully set the changelog for build")
# Expect build beta details to be patched
expect(Spaceship::ConnectAPI).to receive(:patch_build_beta_details).with({
build_beta_details_id: build_beta_detail.id,
attributes: { autoNotifyEnabled: options[:notify_external_testers] }
})
# Don't expect success messages
expect(FastlaneCore::UI).to_not(receive(:message).with(/Distributing new build to testers/))
expect(FastlaneCore::UI).to_not(receive(:success).with(/Successfully distributed build to/))
fake_build_manager.distribute(options, build: ready_to_submit_mock_build)
end
it "updates non-localized demo_account_required, notify_external_testers, beta_app_feedback_email, and beta_app_description and distributes" do
expect(ready_to_submit_mock_build).to receive(:build_beta_detail).and_return(build_beta_detail_missing_export_compliance).exactly(7).times
options = distribute_options_non_localized
# Expect App.find to be called from within Pilot::Manager
expect(Spaceship::ConnectAPI::App).to receive(:get).and_return(app)
# Expect a beta app review detail to be patched
expect(Spaceship::ConnectAPI).to receive(:patch_beta_app_review_detail).with({
app_id: ready_to_submit_mock_build.app_id,
attributes: { demoAccountRequired: options[:demo_account_required] }
})
# Expect beta app localizations to be fetched
expect(Spaceship::ConnectAPI).to receive(:get_beta_app_localizations).with({
filter: { app: ready_to_submit_mock_build.app.id },
includes: nil,
limit: nil,
sort: nil
}).and_return(Spaceship::ConnectAPI::Response.new)
expect(app).to receive(:get_beta_app_localizations).and_wrap_original do |m, *args|
m.call(*args)
app_localizations
end
# Expect beta app localizations to be patched with a UI.success after
mock_api_client_beta_app_localizations.each do |localization|
expect(Spaceship::ConnectAPI).to receive(:patch_beta_app_localizations).with({
localization_id: localization['id'],
attributes: {
feedbackEmail: options[:beta_app_feedback_email],
description: options[:beta_app_description]
}
})
end
expect(FastlaneCore::UI).to receive(:success).with("Successfully set the beta_app_feedback_email and/or beta_app_description")
# Expect beta build localizations to be fetched
expect(Spaceship::ConnectAPI).to receive(:get_beta_build_localizations).with({
filter: { build: ready_to_submit_mock_build.id },
includes: nil,
limit: nil,
sort: nil
}).and_return(Spaceship::ConnectAPI::Response.new)
expect(ready_to_submit_mock_build).to receive(:get_beta_build_localizations).and_wrap_original do |m, *args|
m.call(*args)
build_localizations
end
# Expect beta build localizations to be patched with a UI.success after
mock_api_client_beta_build_localizations.each do |localization|
expect(Spaceship::ConnectAPI).to receive(:patch_beta_build_localizations).with({
localization_id: localization['id'],
attributes: {
whatsNew: options[:changelog]
}
})
end
expect(FastlaneCore::UI).to receive(:success).with("Successfully set the changelog for build")
# Expect build beta details to be patched
expect(Spaceship::ConnectAPI).to receive(:patch_build_beta_details).with({
build_beta_details_id: build_beta_detail.id,
attributes: { autoNotifyEnabled: options[:notify_external_testers] }
})
# A build will go back into a processing state after a patch
# Expect wait_for_export compliance processing_to_be_complete to be called after patching
expect(Spaceship::ConnectAPI).to receive(:patch_builds).with({
build_id: ready_to_submit_mock_build.id, attributes: { usesNonExemptEncryption: false }
})
expect(Spaceship::ConnectAPI::Build).to receive(:get).and_return(ready_to_submit_mock_build).exactly(2).times
expect(FastlaneCore::UI).to receive(:message).with("Waiting for build 123 to process export compliance")
expect(ready_to_submit_mock_build).to receive(:build_beta_detail).and_return(build_beta_detail).exactly(3).times
# Expect beta groups fetched from app. This tests:
# 1. app.get_beta_groups is called
# 2. client.get_beta_groups is called inside of app.beta_groups
expect(Spaceship::ConnectAPI).to receive(:get_beta_groups).with({
filter: { app: ready_to_submit_mock_build.app.id },
includes: nil,
limit: nil,
sort: nil
}).and_return(Spaceship::ConnectAPI::Response.new)
expect(app).to receive(:get_beta_groups).and_wrap_original do |m, *args|
m.call(*args)
beta_groups
end
# Expect beta groups to be added to a builds. This tests:
# 1. build.add_beta_groups is called
# 2. client.add_beta_groups_to_build is called inside of build.add_beta_groups
expect(Spaceship::ConnectAPI).to receive(:add_beta_groups_to_build).with({
build_id: ready_to_submit_mock_build.id,
beta_group_ids: [beta_groups[0].id]
}).and_return(Spaceship::ConnectAPI::Response.new)
expect(ready_to_submit_mock_build).to receive(:add_beta_groups).with(beta_groups: [beta_groups[0]]).and_wrap_original do |m, *args|
options = args.first
m.call(**options)
end
# Expect success messages
expect(FastlaneCore::UI).to receive(:message).with(/Distributing new build to testers/)
expect(FastlaneCore::UI).to receive(:success).with(/Successfully distributed build to/)
fake_build_manager.distribute(options, build: ready_to_submit_mock_build)
end
end
end
describe "#wait_for_build_processing_to_be_complete" do
let(:fake_build_manager) { Pilot::BuildManager.new }
let(:app) do
Spaceship::ConnectAPI::App.new("123-123-123-123", {
name: "Mock App"
})
end
before(:each) do
allow(fake_build_manager).to receive(:login)
allow(fake_build_manager).to receive(:app).and_return(app)
end
it "wait given :ipa" do
options = { ipa: "some_path.ipa" }
fake_build_manager.instance_variable_set(:@config, options)
expect(fake_build_manager).to receive(:fetch_app_platform)
expect(FastlaneCore::IpaFileAnalyser).to receive(:fetch_app_version).and_return("1.2.3")
expect(FastlaneCore::IpaFileAnalyser).to receive(:fetch_app_build).and_return("123")
fake_build = double
expect(fake_build).to receive(:app_version).and_return("1.2.3")
expect(fake_build).to receive(:version).and_return("123")
expect(FastlaneCore::BuildWatcher).to receive(:wait_for_build_processing_to_be_complete).and_return(fake_build)
fake_build_manager.wait_for_build_processing_to_be_complete
end
it "wait given :app_version and :build_number" do
options = { app_version: "1.2.3", build_number: "123" }
fake_build_manager.instance_variable_set(:@config, options)
expect(fake_build_manager).to receive(:fetch_app_platform)
fake_build = double
expect(fake_build).to receive(:app_version).and_return("1.2.3")
expect(fake_build).to receive(:version).and_return("123")
expect(FastlaneCore::BuildWatcher).to receive(:wait_for_build_processing_to_be_complete).and_return(fake_build)
fake_build_manager.wait_for_build_processing_to_be_complete
end
it "wait given :ipa, :app_version and :build_number" do
options = { app_version: "4.5.6", build_number: "456", ipa: "some_path.ipa" }
fake_build_manager.instance_variable_set(:@config, options)
expect(fake_build_manager).to receive(:fetch_app_platform)
expect(FastlaneCore::IpaFileAnalyser).to receive(:fetch_app_version).and_return("1.2.3")
expect(FastlaneCore::IpaFileAnalyser).to receive(:fetch_app_build).and_return("123")
fake_build = double
expect(fake_build).to receive(:app_version).and_return("1.2.3")
expect(fake_build).to receive(:version).and_return("123")
expect(FastlaneCore::BuildWatcher).to receive(:wait_for_build_processing_to_be_complete).and_return(fake_build)
fake_build_manager.wait_for_build_processing_to_be_complete
end
end
describe "#update_beta_app_meta" do
let(:fake_build_manager) { Pilot::BuildManager.new }
let(:fake_build) { double("fake build") }
it "does not attempt to set demo account required" do
options = {}
expect(fake_build_manager).not_to receive(:update_review_detail)
expect(fake_build_manager).not_to receive(:update_build_beta_details)
fake_build_manager.update_beta_app_meta(options, fake_build)
end
it "does not attempt to set demo account required" do
options = { notify_external_testers: true }
expect(fake_build_manager).not_to receive(:update_review_detail)
expect(fake_build_manager).to receive(:update_build_beta_details)
fake_build_manager.update_beta_app_meta(options, fake_build)
end
it "sets demo account required to false" do
options = { demo_account_required: false }
expect(fake_build_manager).to receive(:update_review_detail)
expect(fake_build_manager).not_to receive(:update_build_beta_details)
fake_build_manager.update_beta_app_meta(options, fake_build)
expect(options[:beta_app_review_info][:demo_account_required]).to be(false)
end
it "sets demo account required to true" do
options = { demo_account_required: true }
expect(fake_build_manager).to receive(:update_review_detail)
expect(fake_build_manager).not_to receive(:update_build_beta_details)
fake_build_manager.update_beta_app_meta(options, fake_build)
expect(options[:beta_app_review_info][:demo_account_required]).to be(true)
end
end
describe "#upload" do
describe "uses Manager.login (which does spaceship login)" do
let(:fake_build_manager) { Pilot::BuildManager.new }
let(:upload_options) do
{
apple_id: 'mock_apple_id',
skip_waiting_for_build_processing: true,
ipa: 'foo'
}
end
before(:each) do
allow(fake_build_manager).to receive(:fetch_app_platform).and_return('ios')
fake_ipauploadpackagebuilder = double
allow(fake_ipauploadpackagebuilder).to receive(:generate).and_return(true)
allow(FastlaneCore::IpaUploadPackageBuilder).to receive(:new).and_return(fake_ipauploadpackagebuilder)
fake_itunestransporter = double
allow(fake_itunestransporter).to receive(:upload).and_return(true)
allow(FastlaneCore::ItunesTransporter).to receive(:new).and_return(fake_itunestransporter)
end
it "NOT when skip_waiting_for_build_processing and apple_id are set" do
# should not execute Manager.login (which does spaceship login)
expect(fake_build_manager).not_to(receive(:login))
fake_build_manager.upload(upload_options)
end
it "when skip_waiting_for_build_processing and apple_id are not set" do
# remove options that make login unnecessary
upload_options.delete(:apple_id)
upload_options.delete(:skip_waiting_for_build_processing)
# allow Manager.login method this time
expect(fake_build_manager).to receive(:login).at_least(:once)
# other stuff required to let `upload` work:
expect(fake_build_manager).to receive(:fetch_app_id).and_return(123).exactly(2).times
expect(FastlaneCore::IpaFileAnalyser).to receive(:fetch_app_version)
expect(FastlaneCore::IpaFileAnalyser).to receive(:fetch_app_build)
fake_app = double
expect(fake_app).to receive(:id).and_return(123)
expect(fake_build_manager).to receive(:app).and_return(fake_app)
fake_build = double
expect(fake_build).to receive(:app_version)
expect(fake_build).to receive(:version)
expect(FastlaneCore::BuildWatcher).to receive(:wait_for_build_processing_to_be_complete).and_return(fake_build)
expect(fake_build_manager).to receive(:distribute)
fake_build_manager.upload(upload_options)
end
shared_examples "performing the spaceship login for JWT auth by pilot" do
before(:each) do
expect(fake_build_manager).to(receive(:login))
end
it "performs the login using Manager.login" do
fake_build_manager.upload(upload_options)
end
end
shared_examples "skipping the spaceship login for JWT auth by pilot" do
before(:each) do
expect(fake_build_manager).not_to(receive(:login))
end
it "skips the login using Manager.login" do
fake_build_manager.upload(upload_options)
end
end
describe "what happens when spaceship token is nil" do
before(:each) do
allow(Spaceship::ConnectAPI).to receive(:token).and_return(nil)
end
context "when input options has NO api_key or api_key_path input" do
before(:each) do
upload_options[:api_key] = nil
upload_options[:api_key_path] = nil
end
it_behaves_like "skipping the spaceship login for JWT auth by pilot"
end
context "when input options has api_key input" do
before(:each) do
upload_options[:api_key] = "fake api key"
end
it_behaves_like "performing the spaceship login for JWT auth by pilot"
end
context "when input options has api_key_path input" do
before(:each) do
upload_options[:api_key_path] = "./spaceship/spec/connect_api/fixtures/asc_key.json"
end
it_behaves_like "performing the spaceship login for JWT auth by pilot"
end
end
describe "what happens when spaceship token is already set" do
before(:each) do
fake_api_key_json_path = "./spaceship/spec/connect_api/fixtures/asc_key.json"
allow(Spaceship::ConnectAPI).to receive(:token).and_return(Spaceship::ConnectAPI::Token.from(filepath: fake_api_key_json_path))
end
context "when input options has NO api_key or api_key_path input" do
before(:each) do
upload_options[:api_key] = nil
upload_options[:api_key_path] = nil
end
it_behaves_like "skipping the spaceship login for JWT auth by pilot"
end
context "when input options has api_key input" do
before(:each) do
upload_options[:api_key] = "fake api key"
end
it_behaves_like "skipping the spaceship login for JWT auth by pilot"
end
context "when input options has api_key_path input" do
before(:each) do
upload_options[:api_key_path] = "./spaceship/spec/connect_api/fixtures/asc_key.json"
end
it_behaves_like "skipping the spaceship login for JWT auth by pilot"
end
end
end
end
describe "#transporter_for_selected_team" do
let(:fake_manager) { Pilot::BuildManager.new }
let(:fake_api_key_json_path) do
"./spaceship/spec/connect_api/fixtures/asc_key.json"
end
let(:selected_team_id) { "123" }
let(:selected_team_name) { "123 name" }
let(:selected_team) do
{
"contentProvider" => {
"contentProviderId" => selected_team_id,
"name" => selected_team_name
}
}
end
let(:unselected_team) do
{
"contentProvider" => {
"contentProviderId" => "456",
"name" => "456 name"
}
}
end
it "with API token" do
options = {}
allow(Spaceship::ConnectAPI).to receive(:token).and_return(Spaceship::ConnectAPI::Token.from(filepath: fake_api_key_json_path))
transporter = fake_manager.send(:transporter_for_selected_team, options)
expect(transporter.instance_variable_get(:@jwt)).not_to(be_nil)
expect(transporter.instance_variable_get(:@user)).to be_nil
expect(transporter.instance_variable_get(:@password)).to be_nil
expect(transporter.instance_variable_get(:@provider_short_name)).to be_nil
end
describe "with itc_provider" do
it "with nil Spaceship::TunesClient" do
options = { username: "josh", itc_provider: "123456789" }
fake_manager.instance_variable_set(:@config, options)
allow(Spaceship::ConnectAPI).to receive(:client).and_return(nil)
transporter = fake_manager.send(:transporter_for_selected_team, options)
expect(transporter.instance_variable_get(:@jwt)).to be_nil
expect(transporter.instance_variable_get(:@user)).not_to(be_nil)
expect(transporter.instance_variable_get(:@password)).not_to(be_nil) # Loaded with spec_helper
expect(transporter.instance_variable_get(:@provider_short_name)).to eq("123456789")
end
it "with nil Spaceship::TunesClient" do
options = { username: "josh", itc_provider: "123456789" }
fake_manager.instance_variable_set(:@config, options)
allow(Spaceship::ConnectAPI).to receive(:client).and_return(double)
allow(Spaceship::ConnectAPI.client).to receive(:tunes_client).and_return(double)
transporter = fake_manager.send(:transporter_for_selected_team, options)
expect(transporter.instance_variable_get(:@jwt)).to be_nil
expect(transporter.instance_variable_get(:@user)).not_to(be_nil)
expect(transporter.instance_variable_get(:@password)).not_to(be_nil) # Loaded with spec_helper
expect(transporter.instance_variable_get(:@provider_short_name)).to eq("123456789")
end
end
it "with one team id" do
options = { username: "josh" }
fake_manager.instance_variable_set(:@config, options)
fake_tunes_client = double('tunes client')
allow(Spaceship::ConnectAPI).to receive(:client).and_return(double)
allow(Spaceship::ConnectAPI.client).to receive(:tunes_client).and_return(fake_tunes_client)
expect(fake_tunes_client).to receive(:teams).and_return([selected_team])
transporter = fake_manager.send(:transporter_for_selected_team, options)
expect(transporter.instance_variable_get(:@jwt)).to be_nil
expect(transporter.instance_variable_get(:@user)).not_to(be_nil)
expect(transporter.instance_variable_get(:@password)).not_to(be_nil) # Loaded with spec_helper
expect(transporter.instance_variable_get(:@provider_short_name)).to be_nil
end
it "with inferred provider id" do
options = { username: "josh" }
fake_manager.instance_variable_set(:@config, options)
fake_tunes_client = double('tunes client')
allow(Spaceship::ConnectAPI).to receive(:client).and_return(double)
allow(Spaceship::ConnectAPI.client).to receive(:tunes_client).and_return(fake_tunes_client)
allow(fake_tunes_client).to receive(:team_id).and_return(selected_team_id)
allow(fake_tunes_client).to receive(:teams).and_return([unselected_team, selected_team])
allow_any_instance_of(FastlaneCore::ItunesTransporter).to receive(:provider_ids).and_return({ selected_team_name.to_s => selected_team_id })
transporter = fake_manager.send(:transporter_for_selected_team, options)
expect(transporter.instance_variable_get(:@jwt)).to be_nil
expect(transporter.instance_variable_get(:@user)).not_to(be_nil)
expect(transporter.instance_variable_get(:@password)).not_to(be_nil) # Loaded with spec_helper
expect(transporter.instance_variable_get(:@provider_short_name)).to eq(selected_team_id)
end
end
end