fix: Downloads for iOS (#1869)

- Closes #1863

---------

Co-authored-by: Ilya Rakhlin <i.rakhlin@gmail.com>
This commit is contained in:
Dermot Duffy
2025-02-01 16:08:32 -08:00
committed by GitHub
co-authored by Ilya Rakhlin
parent a6ecb76efe
commit 43947b49dc
4 changed files with 70 additions and 24 deletions
+49 -1
View File
@@ -1,5 +1,9 @@
import { describe, expect, it } from 'vitest';
import { isCompanionApp } from '../../src/utils/companion';
import {
isCompanionApp,
isAndroidCompanionApp,
isIOSCompanionApp,
} from '../../src/utils/companion';
describe('isCompanionApp', () => {
it('should return true for userAgent starting with "Home Assistant/"', () => {
@@ -18,3 +22,47 @@ describe('isCompanionApp', () => {
expect(isCompanionApp('')).toBe(false);
});
});
describe('isAndroidCompanionApp', () => {
it('should return true for userAgent containing "Home Assistant" and "Android"', () => {
expect(isAndroidCompanionApp('Home Assistant/1.0 (Android 1.0; 1.0)')).toBe(true);
});
it('should return true for userAgent containing "HomeAssistant" and "Android"', () => {
expect(isAndroidCompanionApp('HomeAssistant/2.0 (Android 2.0; 2.0)')).toBe(true);
});
it('should return false for userAgent not starting with "Home Assistant/" or "HomeAssistant/"', () => {
expect(isAndroidCompanionApp('Mozilla/5.0')).toBe(false);
});
it('should return false for userAgent containing "Home Assistant/" or "HomeAssistant/" and iOS', () => {
expect(
isAndroidCompanionApp(
'Home Assistant/2025.1.1 (io.robbie.HomeAssistant; build:2025.1077; iOS 18.3.0',
),
).toBe(false);
});
});
describe('isIOSCompanionApp', () => {
it('should return true for userAgent containing "Home Assistant" and "iOS"', () => {
expect(isIOSCompanionApp('Home Assistant/1.0 (iOS 1.0; 1.0)')).toBe(true);
});
it('should return true for userAgent containing "HomeAssistant" and "iOS"', () => {
expect(isIOSCompanionApp('HomeAssistant/2.0 (iOS 2.0; 2.0)')).toBe(true);
});
it('should return false for userAgent not starting with "Home Assistant/" or "HomeAssistant/"', () => {
expect(isIOSCompanionApp('Mozilla/5.0')).toBe(false);
});
it('should return false for userAgent containing "Home Assistant/" or "HomeAssistant/" and Android', () => {
expect(
isIOSCompanionApp(
'Home Assistant/2025.1.1 (io.robbie.HomeAssistant; build:2025.1077; Android 18.3.0',
),
).toBe(false);
});
});