@devicecloud.dev/dcd
Version:
Better cloud maestro testing
75 lines (74 loc) • 3.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceValidationService = void 0;
/**
* Service for validating device configurations against compatibility data
*/
class DeviceValidationService {
/**
* Validate Android device configuration
* @param androidApiLevel Android API level to validate
* @param androidDevice Android device model to validate
* @param googlePlay Whether Google Play services are enabled
* @param compatibilityData Compatibility data from API
* @param options Validation options
* @returns void
* @throws Error if device/API level combination is not supported
*/
validateAndroidDevice(androidApiLevel, androidDevice, googlePlay, compatibilityData, options = {}) {
const { debug = false, logger } = options;
if (!androidApiLevel && !androidDevice) {
return;
}
const androidDeviceID = androidDevice || 'pixel-7';
const lookup = googlePlay
? compatibilityData.androidPlay
: compatibilityData.android;
const supportedAndroidVersions = lookup?.[androidDeviceID] || [];
const version = androidApiLevel || '34';
if (supportedAndroidVersions.length === 0) {
throw new Error(`We don't support that device configuration - please check the docs for supported devices: https://docs.devicecloud.dev/getting-started/devices-configuration`);
}
if (Array.isArray(supportedAndroidVersions) &&
!supportedAndroidVersions.includes(version)) {
throw new Error(`${androidDeviceID} ${googlePlay ? '(Play Store) ' : ''}only supports these Android API levels: ${supportedAndroidVersions.join(', ')}`);
}
if (debug && logger) {
logger(`[DEBUG] Android device: ${androidDeviceID}`);
logger(`[DEBUG] Android API level: ${version}`);
logger(`[DEBUG] Google Play enabled: ${googlePlay}`);
logger(`[DEBUG] Supported Android versions: ${supportedAndroidVersions.join(', ')}`);
}
}
/**
* Validate iOS device configuration
* @param iOSVersion iOS version to validate
* @param iOSDevice iOS device model to validate
* @param compatibilityData Compatibility data from API
* @param options Validation options
* @returns void
* @throws Error if device/version combination is not supported
*/
validateiOSDevice(iOSVersion, iOSDevice, compatibilityData, options = {}) {
const { debug = false, logger } = options;
if (!iOSVersion && !iOSDevice) {
return;
}
const iOSDeviceID = iOSDevice || 'iphone-14';
const supportediOSVersions = compatibilityData?.ios?.[iOSDeviceID] || [];
const version = iOSVersion || '17';
if (supportediOSVersions.length === 0) {
throw new Error(`Device ${iOSDeviceID} is not supported. Please check the docs for supported devices: https://docs.devicecloud.dev/getting-started/devices-configuration`);
}
if (Array.isArray(supportediOSVersions) &&
!supportediOSVersions.includes(version)) {
throw new Error(`${iOSDeviceID} only supports these iOS versions: ${supportediOSVersions.join(', ')}`);
}
if (debug && logger) {
logger(`[DEBUG] iOS device: ${iOSDeviceID}`);
logger(`[DEBUG] iOS version: ${version}`);
logger(`[DEBUG] Supported iOS versions: ${supportediOSVersions.join(', ')}`);
}
}
}
exports.DeviceValidationService = DeviceValidationService;