This repository has been archived by the owner on Jul 22, 2023. It is now read-only.
forked from freddi-kit/fastlane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iap_spec.rb
155 lines (144 loc) · 5.72 KB
/
iap_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
describe Spaceship::Tunes::IAP do
before { TunesStubbing.itc_stub_iap }
before { Spaceship::Tunes.login }
let(:client) { Spaceship::Tunes.client }
let(:app) { Spaceship::Application.all.find { |a| a.apple_id == "898536088" } }
describe "returns all purchases" do
it "returns as IAPList" do
expect(app.in_app_purchases.all.first.class).to eq(Spaceship::Tunes::IAPList)
end
it "Finds shared secret key" do
secret = app.in_app_purchases.get_shared_secret
expect(secret.class).to eq(String)
expect(secret.length).to be(32)
end
it "Generates new shared secret key" do
old_secret = app.in_app_purchases.get_shared_secret
new_secret = app.in_app_purchases.generate_shared_secret
expect(old_secret).not_to(eq(new_secret))
expect(new_secret.class).to eq(String)
expect(new_secret.length).to be(32)
end
it "Finds a specific product" do
expect(app.in_app_purchases.find("go.find.me")).not_to(eq(nil))
expect(app.in_app_purchases.find("go.find.me").reference_name).to eq("localizeddemo")
end
it "Finds families" do
expect(app.in_app_purchases.families.class).to eq(Spaceship::Tunes::IAPFamilies)
expect(app.in_app_purchases.families.all.first.class).to eq(Spaceship::Tunes::IAPFamilyList)
expect(app.in_app_purchases.families.all.first.name).to eq("Product name1234")
end
describe "Create new IAP" do
it "create consumable" do
expect(client.du_client).to receive(:get_picture_type).and_return("SortedScreenShot")
expect(client.du_client).to receive(:upload_purchase_review_screenshot).and_return({ "token" => "tok", "height" => 100, "width" => 200, "md5" => "xxxx" })
expect(Spaceship::UploadFile).to receive(:from_path).with("ftl_FAKEMD5_screenshot1024.jpg").and_return(du_uploadimage_correct_screenshot)
app.in_app_purchases.create!(
type: Spaceship::Tunes::IAPType::CONSUMABLE,
versions: {
'en-US' => {
name: "test name1",
description: "Description has at least 10 characters"
},
'de-DE' => {
name: "test name german1",
description: "German has at least 10 characters"
}
},
reference_name: "localizeddemo",
product_id: "x.a.a.b.b.c.d.x.y.f",
cleared_for_sale: true,
review_notes: "Some Review Notes here bla bla bla",
review_screenshot: "ftl_FAKEMD5_screenshot1024.jpg",
pricing_intervals:
[
{
country: "WW",
begin_date: nil,
end_date: nil,
tier: 1
}
]
)
end
it "create auto renewable subscription with pricing" do
pricing_intervals = [
{
country: "WW",
begin_date: nil,
end_date: nil,
tier: 1
}
]
transformed_pricing_intervals = pricing_intervals.map do |interval|
{
"value" => {
"tierStem" => interval[:tier],
"priceTierEffectiveDate" => interval[:begin_date],
"priceTierEndDate" => interval[:end_date],
"country" => interval[:country] || "WW",
"grandfathered" => interval[:grandfathered]
}
}
end
expect(client).to receive(:update_recurring_iap_pricing!).with(app_id: '898536088', purchase_id: "1195137657", pricing_intervals: transformed_pricing_intervals)
app.in_app_purchases.create!(
type: Spaceship::Tunes::IAPType::RECURRING,
versions: {
'en-US' => {
name: "test name2",
description: "Description has at least 10 characters"
},
'de-DE' => {
name: "test name german2",
description: "German has at least 10 characters"
}
},
reference_name: "localizeddemo",
product_id: "x.a.a.b.b.c.d.x.y.z",
cleared_for_sale: true,
review_notes: "Some Review Notes here bla bla bla",
pricing_intervals: pricing_intervals
)
end
it "create auto renewable subscription with subscription price target" do
subscription_price_target = {
currency: "EUR",
tier: 1
}
price_goal = TunesStubbing.itc_read_fixture_file('iap_price_goal_calc.json')
transformed_pricing_intervals = JSON.parse(price_goal)["data"].map do |language_code, value|
{
"value" => {
"tierStem" => value["tierStem"],
"priceTierEffectiveDate" => value["priceTierEffectiveDate"],
"priceTierEndDate" => value["priceTierEndDate"],
"country" => language_code,
"grandfathered" => { "value" => "FUTURE_NONE" }
}
}
end
expect(client).to receive(:update_recurring_iap_pricing!).with(app_id: '898536088',
purchase_id: "1195137657", pricing_intervals: transformed_pricing_intervals)
app.in_app_purchases.create!(
type: Spaceship::Tunes::IAPType::RECURRING,
versions: {
'en-US' => {
name: "test name2",
description: "Description has at least 10 characters"
},
'de-DE' => {
name: "test name german2",
description: "German has at least 10 characters"
}
},
reference_name: "localizeddemo",
product_id: "x.a.a.b.b.c.d.x.y.z",
cleared_for_sale: true,
review_notes: "Some Review Notes here bla bla bla",
subscription_price_target: subscription_price_target
)
end
end
end
end