forked from fastlane/fastlane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_metadata_spec.rb
136 lines (119 loc) · 5.67 KB
/
upload_metadata_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
require 'deliver/upload_metadata'
require 'tempfile'
describe Deliver::UploadMetadata do
let(:uploader) { Deliver::UploadMetadata.new }
let(:tmpdir) { Dir.mktmpdir }
describe '#load_from_filesystem' do
context 'with review information' do
let(:options) { { metadata_path: tmpdir, app_review_information: app_review_information } }
def create_metadata(path, text)
File.open(File.join(path), 'w') do |f|
f.write(text)
end
end
before do
base_dir = FileUtils.mkdir_p(File.join(tmpdir, 'review_information'))
{
first_name: 'Alice',
last_name: 'Smith',
phone_number: '+819012345678',
email_address: '[email protected]',
demo_user: 'user',
demo_password: 'password',
notes: 'This is a note from file'
}.each do |prefix, text|
create_metadata(File.join(base_dir, "#{prefix}.txt"), text)
end
end
context 'without app_review_information' do
let(:app_review_information) { nil }
it 'can load review information from file' do
uploader.load_from_filesystem(options)
expect(options[:app_review_information][:first_name]).to eql('Alice')
expect(options[:app_review_information][:last_name]).to eql('Smith')
expect(options[:app_review_information][:phone_number]).to eql('+819012345678')
expect(options[:app_review_information][:email_address]).to eql('[email protected]')
expect(options[:app_review_information][:demo_user]).to eql('user')
expect(options[:app_review_information][:demo_password]).to eql('password')
expect(options[:app_review_information][:notes]).to eql('This is a note from file')
end
end
context 'with app_review_information' do
let(:app_review_information) { { notes: 'This is a note from option' } }
it 'values will be masked by the in options' do
uploader.load_from_filesystem(options)
expect(options[:app_review_information][:first_name]).to eql('Alice')
expect(options[:app_review_information][:last_name]).to eql('Smith')
expect(options[:app_review_information][:phone_number]).to eql('+819012345678')
expect(options[:app_review_information][:email_address]).to eql('[email protected]')
expect(options[:app_review_information][:demo_user]).to eql('user')
expect(options[:app_review_information][:demo_password]).to eql('password')
expect(options[:app_review_information][:notes]).to eql('This is a note from option')
end
end
after do
FileUtils.remove_entry_secure(tmpdir)
end
end
end
describe "#set_review_information" do
let(:options) { { metadata_path: tmpdir, app_review_information: app_review_information } }
let(:version) { double("version") }
before do
allow(version).to receive(:review_first_name=)
allow(version).to receive(:review_last_name=)
allow(version).to receive(:review_phone_number=)
allow(version).to receive(:review_email=)
allow(version).to receive(:review_demo_user=)
allow(version).to receive(:review_demo_password=)
allow(version).to receive(:review_notes=)
allow(version).to receive(:review_user_needed=)
allow(version).to receive(:review_demo_user).and_return(app_review_information[:demo_user])
allow(version).to receive(:review_demo_password).and_return(app_review_information[:demo_password])
end
context "with review_information" do
let(:app_review_information) do
{ first_name: "Alice",
last_name: "Smith",
phone_number: "+819012345678",
email_address: "[email protected]",
demo_user: "user",
demo_password: "password",
notes: "This is a note" }
end
it "set review information" do
uploader.send("set_review_information", version, options)
expect(version).to have_received(:review_first_name=).with(app_review_information[:first_name])
expect(version).to have_received(:review_last_name=).with(app_review_information[:last_name])
expect(version).to have_received(:review_phone_number=).with(app_review_information[:phone_number])
expect(version).to have_received(:review_email=).with(app_review_information[:email_address])
expect(version).to have_received(:review_demo_user=).with(app_review_information[:demo_user])
expect(version).to have_received(:review_demo_password=).with(app_review_information[:demo_password])
expect(version).to have_received(:review_notes=).with(app_review_information[:notes])
end
end
context "with demo_user and demo_password" do
context "with string" do
let(:app_review_information) { { demo_user: "user", demo_password: "password" } }
it "review_user_needed is true" do
uploader.send("set_review_information", version, options)
expect(version).to have_received(:review_user_needed=).with(true)
end
end
context "with empty string" do
let(:app_review_information) { { demo_user: "", demo_password: "" } }
it "review_user_needed is false" do
uploader.send("set_review_information", version, options)
expect(version).to have_received(:review_user_needed=).with(false)
end
end
context "with newline" do
let(:app_review_information) { { demo_user: "\n", demo_password: "\n" } }
it "review_user_needed is false" do
uploader.send("set_review_information", version, options)
expect(version).to have_received(:review_user_needed=).with(false)
end
end
end
end
end