fix: resolve Android APK download URLs for mobile updates
Prefers a real APK asset when the update API points to an AAB Keeps direct APK links from the API unchanged Uses the GitHub releases API as a fallback for Android mobile downloads
This commit is contained in:
@@ -141,6 +141,66 @@ describe('checkForUpdates', () => {
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('resolves an Android APK asset when the update API returns an AAB', async () => {
|
||||
fetchMock
|
||||
.when('api.openchamber.dev', {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
latestVersion: '1.10.0',
|
||||
updateAvailable: true,
|
||||
downloadUrl: 'https://github.com/openchamber/openchamber/releases/download/v1.10.0/OpenChamber-1.10.0-42-android.aab',
|
||||
}),
|
||||
})
|
||||
.when('api.github.com/repos/openchamber/openchamber/releases/tags/v1.10.0', {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
assets: [
|
||||
{
|
||||
name: 'OpenChamber-1.10.0-42-android.aab',
|
||||
browser_download_url: 'https://downloads.example/OpenChamber-1.10.0-42-android.aab',
|
||||
},
|
||||
{
|
||||
name: 'app-release.apk',
|
||||
browser_download_url: 'https://downloads.example/app-release.apk',
|
||||
},
|
||||
{
|
||||
name: 'OpenChamber-1.10.0-42-android.apk',
|
||||
browser_download_url: 'https://downloads.example/OpenChamber-1.10.0-42-android.apk',
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
const result = await checkForUpdates({
|
||||
appType: 'mobile-capacitor',
|
||||
platform: 'android',
|
||||
currentVersion: '1.9.10',
|
||||
});
|
||||
|
||||
expect(result.downloadUrl).toBe('https://downloads.example/OpenChamber-1.10.0-42-android.apk');
|
||||
});
|
||||
|
||||
it('keeps a direct Android APK URL from the update API', async () => {
|
||||
const apkUrl = 'https://github.com/openchamber/openchamber/releases/download/v1.10.0/OpenChamber-1.10.0-42-android.apk';
|
||||
fetchMock.when('api.openchamber.dev', {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
latestVersion: '1.10.0',
|
||||
updateAvailable: true,
|
||||
downloadUrl: apkUrl,
|
||||
}),
|
||||
});
|
||||
|
||||
const result = await checkForUpdates({
|
||||
appType: 'mobile-capacitor',
|
||||
platform: 'android',
|
||||
currentVersion: '1.9.10',
|
||||
});
|
||||
|
||||
expect(result.downloadUrl).toBe(apkUrl);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('returns available=false when API claims update but npm is behind', async () => {
|
||||
fetchMock
|
||||
.when('api.openchamber.dev', {
|
||||
|
||||
Reference in New Issue
Block a user