Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mas v1.8.7/v1.9.0/v2.0.0 updates #1308

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/bundle/bundle.rb
Expand Up @@ -33,14 +33,6 @@ def whalebrew_installed?
@whalebrew_installed ||= which_formula("whalebrew")
end

def mas_signedin?
# mas account doesn't work on Monterey (yet)
# https://github.com/mas-cli/mas/issues/417#issuecomment-957963271
return true if MacOS.version >= :monterey

Kernel.system "mas account &>/dev/null"
end

def cask_installed?
@cask_installed ||= File.directory?("#{HOMEBREW_PREFIX}/Caskroom") &&
(File.directory?("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-cask") ||
Expand Down
23 changes: 7 additions & 16 deletions lib/bundle/mac_app_store_installer.rb
Expand Up @@ -24,11 +24,6 @@ def preinstall(name, id, no_upgrade: false, verbose: false)
return false
end

unless Bundle.mas_signedin?
puts "Not signed in to Mac App Store." if verbose
raise "Unable to install #{name} app. mas not signed in to Mac App Store."
end

true
end

Expand Down Expand Up @@ -70,17 +65,13 @@ def installed_app_ids
end

def outdated_app_ids
[]

# TODO: can't be trusted right now.
# Uncomment when https://github.com/mas-cli/mas/pull/496 is merged.
# @outdated_app_ids ||= if Bundle.mas_installed?
# `mas outdated 2>/dev/null`.split("\n").map do |app|
# app.split(" ", 2).first.to_i
# end
# else
# []
# end
@outdated_app_ids ||= if Bundle.mas_installed?
`mas outdated 2>/dev/null`.split("\n").map do |app|
app.split(" ", 2).first.to_i
end
else
[]
end
end
end
end
74 changes: 28 additions & 46 deletions spec/bundle/mac_app_store_installer_spec.rb
Expand Up @@ -41,64 +41,46 @@
allow(Bundle).to receive(:mas_installed?).and_return(true)
end

# TODO: can't be trusted right now.
# Uncomment when https://github.com/mas-cli/mas/pull/496 is merged.
# describe ".outdated_app_ids" do
# it "returns app ids" do
# expect(described_class).to receive(:`).and_return("foo 123")
# described_class.reset!
# described_class.outdated_app_ids
# end
# end

context "when mas is not signed in" do
it "outputs an error" do
allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123])
allow(MacOS).to receive(:version).and_return(:big_sur)
expect(Kernel).to receive(:system).with("mas account &>/dev/null").and_return(false)
expect { described_class.preinstall("foo", 123) }.to raise_error(RuntimeError)
describe ".outdated_app_ids" do
it "returns app ids" do
expect(described_class).to receive(:`).and_return("foo 123")
described_class.reset!
described_class.outdated_app_ids
end
end

context "when mas is signed in" do
context "when app is installed" do
before do
allow(Bundle).to receive(:mas_signedin?).and_return(true)
allow(described_class).to receive(:outdated_app_ids).and_return([])
allow(described_class).to receive(:installed_app_ids).and_return([123])
end

context "when app is installed" do
before do
allow(described_class).to receive(:installed_app_ids).and_return([123])
end

it "skips" do
expect(Bundle).not_to receive(:system)
expect(described_class.preinstall("foo", 123)).to be(false)
end
it "skips" do
expect(Bundle).not_to receive(:system)
expect(described_class.preinstall("foo", 123)).to be(false)
end
end

context "when app is outdated" do
before do
allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123])
end
context "when app is outdated" do
before do
allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123])
end

it "upgrades" do
expect(Bundle).to receive(:system).with("mas", "upgrade", "123", verbose: false).and_return(true)
expect(described_class.preinstall("foo", 123)).to be(true)
expect(described_class.install("foo", 123)).to be(true)
end
it "upgrades" do
expect(Bundle).to receive(:system).with("mas", "upgrade", "123", verbose: false).and_return(true)
expect(described_class.preinstall("foo", 123)).to be(true)
expect(described_class.install("foo", 123)).to be(true)
end
end

context "when app is not installed" do
before do
allow(described_class).to receive(:installed_app_ids).and_return([])
end
context "when app is not installed" do
before do
allow(described_class).to receive(:installed_app_ids).and_return([])
end

it "installs app" do
expect(Bundle).to receive(:system).with("mas", "install", "123", verbose: false).and_return(true)
expect(described_class.preinstall("foo", 123)).to be(true)
expect(described_class.install("foo", 123)).to be(true)
end
it "installs app" do
expect(Bundle).to receive(:system).with("mas", "install", "123", verbose: false).and_return(true)
expect(described_class.preinstall("foo", 123)).to be(true)
expect(described_class.install("foo", 123)).to be(true)
end
end
end
Expand Down