Skip to content

Commit

Permalink
Add tests for access to all builds
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentisambart committed Aug 28, 2023
1 parent aa933c4 commit c3a2f4a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
4 changes: 3 additions & 1 deletion spaceship/lib/spaceship/connect_api/models/beta_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BetaGroup
attr_accessor :public_link_limit
attr_accessor :public_link
attr_accessor :beta_testers
attr_accessor :has_access_to_all_builds

attr_mapping({
"name" => "name",
Expand All @@ -23,7 +24,8 @@ class BetaGroup
"publicLinkLimitEnabled" => "public_link_limit_enabled",
"publicLinkLimit" => "public_link_limit",
"publicLink" => "public_link",
"betaTesters" => "beta_testers"
"betaTesters" => "beta_testers",
"hasAccessToAllBuilds" => "has_access_to_all_builds",
})

def self.type
Expand Down
7 changes: 6 additions & 1 deletion spaceship/lib/spaceship/connect_api/testflight/testflight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ def delete_beta_groups_from_build(build_id: nil, beta_group_ids: [])
end

def create_beta_group(app_id: nil, group_name: nil, is_internal_group: false, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false, has_access_to_all_builds: nil)
has_access_to_all_builds = is_internal_group ? true : false if has_access_to_all_builds.nil?
if is_internal_group
has_access_to_all_builds = true if has_access_to_all_builds.nil?
else
# Access to all builds is only for internal groups
has_access_to_all_builds = nil
end
body = {
data: {
attributes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"publicLinkId" : "abcd1234",
"publicLinkLimitEnabled" : false,
"publicLinkLimit" : 10000,
"publicLink" : "https://testflight.apple.com/join/abcd1234"
"publicLink" : "https://testflight.apple.com/join/abcd1234",
"hasAccessToAllBuilds" : null
}
}
}
20 changes: 20 additions & 0 deletions spaceship/spec/connect_api/models/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@

model = app.create_beta_group(group_name: "Brand New Group", public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false)
expect(model.id).to eq("123456789")
expect(model.is_internal_group).to eq(false)
expect(model.has_access_to_all_builds).to be_nil

# `has_access_to_all_builds` is ignored for external groups
model = app.create_beta_group(group_name: "Brand New Group", public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false, has_access_to_all_builds: true)
expect(model.id).to eq("123456789")
expect(model.is_internal_group).to eq(false)
expect(model.has_access_to_all_builds).to be_nil

# `has_access_to_all_builds` is set to `true` by default for internal groups
model = app.create_beta_group(group_name: "Brand New Group", is_internal_group: true, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false)
expect(model.id).to eq("123456789")
expect(model.is_internal_group).to eq(true)
expect(model.has_access_to_all_builds).to eq(true)

# `has_access_to_all_builds` can be set to `false` for internal groups
model = app.create_beta_group(group_name: "Brand New Group", is_internal_group: true, public_link_enabled: false, public_link_limit: 10_000, public_link_limit_enabled: false, has_access_to_all_builds: false)
expect(model.id).to eq("123456789")
expect(model.is_internal_group).to eq(true)
expect(model.has_access_to_all_builds).to eq(false)
end

it '#get_review_submissions' do
Expand Down
10 changes: 9 additions & 1 deletion spaceship/spec/connect_api/testflight/testflight_stubbing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,16 @@ def stub_beta_groups
stub_request(:get, "https://appstoreconnect.apple.com/iris/v1/betaGroups").
to_return(status: 200, body: read_fixture_file('beta_groups.json'), headers: { 'Content-Type' => 'application/json' })

created_beta_group = JSON.parse(read_fixture_file('beta_create_group.json'))
stub_request(:post, "https://appstoreconnect.apple.com/iris/v1/betaGroups").
to_return(status: 200, body: read_fixture_file('beta_create_group.json'), headers: { 'Content-Type' => 'application/json' })
to_return { |request|
request_body = JSON.parse(request.body)
response_body = created_beta_group.dup
%w{isInternalGroup hasAccessToAllBuilds}.each do |attribute|
response_body["data"]["attributes"][attribute] = request_body["data"]["attributes"][attribute]
end
{ status: 200, body: JSON.dump(response_body), headers: { 'Content-Type' => 'application/json' } }
}

stub_request(:delete, "https://appstoreconnect.apple.com/iris/v1/betaGroups/123456789").
to_return(status: 200, body: "", headers: {})
Expand Down

0 comments on commit c3a2f4a

Please sign in to comment.