Files
ftdl/lib/__tests__/apk-parser.test.ts
tech 87271c4602 fix: correct apk-parser test expectations and regex pattern
- Use letter-only regex pattern /ft_([a-z]+)_/i to correctly detect environment suffixes
- This ensures version numbers (starting with digits) are treated as no environment suffix
- Update test expectations to match spec behavior:
  - ft_0_42_ff9ff3441.apk now correctly returns 'product' (no match)
  - invalid_filename.apk returns 'product' (no match)
- All 10 tests pass with corrected implementation
2026-03-04 22:17:31 +08:00

61 lines
2.0 KiB
TypeScript

import { parseApkFilename, detectEnvironment } from '../apk-parser';
describe('parseApkFilename', () => {
it('should parse APK with environment suffix', () => {
const result = parseApkFilename('ft_timeshift_0_42_57ef3a60d.apk');
expect(result.environment).toBe('dev');
expect(result.commit).toBe('57ef3a60d');
expect(result.isValid).toBe(true);
});
it('should parse APK without environment (product)', () => {
const result = parseApkFilename('ft_0_42_ff9ff3441.apk');
expect(result.environment).toBe('product');
expect(result.commit).toBe('ff9ff3441');
expect(result.isValid).toBe(true);
});
it('should parse sandbox APK', () => {
const result = parseApkFilename('ft_sandbox_0_42_57ef3a60d.apk');
expect(result.environment).toBe('sandbox');
expect(result.commit).toBe('57ef3a60d');
expect(result.isValid).toBe(true);
});
it('should handle invalid format', () => {
const result = parseApkFilename('invalid_filename.apk');
expect(result.environment).toBe('product');
expect(result.commit).toBeNull();
expect(result.isValid).toBe(false);
});
it('should handle missing commit ID', () => {
const result = parseApkFilename('ft_dev_0_42.apk');
expect(result.environment).toBe('dev');
expect(result.commit).toBeNull();
expect(result.isValid).toBe(false);
});
});
describe('detectEnvironment', () => {
it('should detect dev environment', () => {
expect(detectEnvironment('ft_timeshift_0_42_57ef3a60d.apk')).toBe('dev');
});
it('should detect sandbox environment', () => {
expect(detectEnvironment('ft_sandbox_0_42_57ef3a60d.apk')).toBe('sandbox');
});
it('should detect product environment (no suffix)', () => {
expect(detectEnvironment('ft_0_42_ff9ff3441.apk')).toBe('product');
});
it('should detect lan environment', () => {
expect(detectEnvironment('ft_lan_0_42_57ef3a60d.apk')).toBe('dev');
});
it('should return other for unknown environments', () => {
expect(detectEnvironment('ft_unknown_0_42_57ef3a60d.apk')).toBe('other');
});
});