|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Fastlane::Actions::AndroidGenerateApkFromAabAction do |
| 4 | + before do |
| 5 | + allow(File).to receive(:file?).with(aab_file_path).and_return('mocked file data') |
| 6 | + allow(File).to receive(:file?).with(apk_output_file_path).and_return('mocked file data') |
| 7 | + allow(File).to receive(:file?).with(keystore_path).and_return('mocked file data') |
| 8 | + end |
| 9 | + |
| 10 | + let(:aab_file_path) { 'path/to/app.aab' } |
| 11 | + let(:apk_output_file_path) { 'path/to/app.apk' } |
| 12 | + let(:keystore_path) { 'path/to/keystore' } |
| 13 | + let(:keystore_password) { 'keystore_password' } |
| 14 | + let(:keystore_key_alias) { 'keystore_key_alias' } |
| 15 | + let(:signing_key_password) { 'signing_key_password' } |
| 16 | + let(:move_and_clean_up_command) { '\\&\\& mv path/to/app.apk/universal.apk path/to/app.apk \\&\\& rm -rf path/to/app.apk' } |
| 17 | + |
| 18 | + describe 'android_generate_apk_from_aab' do |
| 19 | + it 'calls the `bundletool` command with the correct arguments when generating a signed APK' do |
| 20 | + cmd = run_described_fastlane_action( |
| 21 | + aab_file_path: aab_file_path, |
| 22 | + apk_output_file_path: apk_output_file_path, |
| 23 | + keystore_path: keystore_path, |
| 24 | + keystore_password: keystore_password, |
| 25 | + keystore_key_alias: keystore_key_alias, |
| 26 | + signing_key_password: signing_key_password |
| 27 | + ) |
| 28 | + # rubocop:disable Layout/LineLength |
| 29 | + expect(cmd).to eq("bundletool build-apks --mode universal --bundle #{aab_file_path} --output-format DIRECTORY --output #{apk_output_file_path} --ks #{keystore_path} --ks-pass #{keystore_password} --ks-key-alias #{keystore_key_alias} --key-pass #{signing_key_password} #{move_and_clean_up_command}") |
| 30 | + # rubocop:enable Layout/LineLength |
| 31 | + end |
| 32 | + |
| 33 | + it 'calls the `bundletool` command with the correct arguments when generating an unsigned APK' do |
| 34 | + cmd = run_described_fastlane_action( |
| 35 | + aab_file_path: aab_file_path, |
| 36 | + apk_output_file_path: apk_output_file_path |
| 37 | + ) |
| 38 | + expect(cmd).to eq("bundletool build-apks --mode universal --bundle #{aab_file_path} --output-format DIRECTORY --output #{apk_output_file_path} #{move_and_clean_up_command}") |
| 39 | + end |
| 40 | + |
| 41 | + it 'calls the `bundletool` command with the correct arguments and use the path to the AAB from the lane context if the SharedValues::GRADLE_AAB_OUTPUT_PATH key is set' do |
| 42 | + aab_path_from_context = 'path/from/context/app.aab' |
| 43 | + |
| 44 | + Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GRADLE_AAB_OUTPUT_PATH] = aab_path_from_context |
| 45 | + |
| 46 | + cmd = run_described_fastlane_action( |
| 47 | + apk_output_file_path: apk_output_file_path |
| 48 | + ) |
| 49 | + expect(cmd).to eq("bundletool build-apks --mode universal --bundle #{aab_path_from_context} --output-format DIRECTORY --output #{apk_output_file_path} #{move_and_clean_up_command}") |
| 50 | + end |
| 51 | + |
| 52 | + it 'calls the `bundletool` command with the correct arguments and use the path to the AAB from the lane context if the SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS key is set' do |
| 53 | + all_aab_paths_from_context = ['first/path/from/context/app.aab'] |
| 54 | + |
| 55 | + Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS] = all_aab_paths_from_context |
| 56 | + |
| 57 | + cmd = run_described_fastlane_action( |
| 58 | + apk_output_file_path: apk_output_file_path |
| 59 | + ) |
| 60 | + expect(cmd).to eq("bundletool build-apks --mode universal --bundle #{all_aab_paths_from_context.first} --output-format DIRECTORY --output #{apk_output_file_path} #{move_and_clean_up_command}") |
| 61 | + end |
| 62 | + end |
| 63 | +end |
0 commit comments