import nrfdlModule, { Device, // @ts-ignore nrfdlModule Is not a module } from '../../../index'; import { RELEASE_DIR } from './common/config'; import { validateSchema } from './common/helpers'; require('../../../jasmine_shared.js'); /** * Test API: * - deviceControlGetProtectionStatus() * - deviceControlSetProtectionStatus() * - deviceControlRecover() * * Test schema: * - GetProtectionStatusResult */ describe('Device recovery: ', () => { let context = 0; const jLinkDevices: Device[] = []; beforeAll(async () => { context = nrfdlModule.createContext({ plugins_dir: RELEASE_DIR }); const jlink: Device[] = await nrfdlModule.enumerate(context, { jlink: true, }); jLinkDevices.push(...jlink); }); it('Set all devices protected', async () => { expect(jLinkDevices.length).toBeGreaterThan(0); const protections = jLinkDevices.map(async jLinkDevice => { let protectionStatus = await nrfdlModule.deviceControlGetProtectionStatus(context, jLinkDevice.id); const schemaValid = await validateSchema('#/definitions/GetProtectionStatusResult', protectionStatus, true); expect(schemaValid).toBe(true); if (protectionStatus.protectionStatus === 'NRFDL_PROTECTION_STATUS_NONE') { await nrfdlModule.deviceControlSetProtectionStatus( context, jLinkDevice.id, 'NRFDL_PROTECTION_STATUS_ALL' ); } protectionStatus = await nrfdlModule.deviceControlGetProtectionStatus(context, jLinkDevice.id); expect(protectionStatus.protectionStatus).not.toBe('NRFDL_PROTECTION_STATUS_NONE'); }); await Promise.all(protections); }); it('Recover protected devices', async () => { expect(jLinkDevices.length).toBeGreaterThan(0); const recoveryPromises = jLinkDevices.map(async jLinkDevice => { await nrfdlModule.deviceControlRecover(context, jLinkDevice.id); }); await Promise.all(recoveryPromises); const nonProtectedCheckPromises = jLinkDevices.map(async jLinkDevice => { const protectionStatus = await nrfdlModule.deviceControlGetProtectionStatus(context, jLinkDevice.id); const schemaValid = await validateSchema('#/definitions/GetProtectionStatusResult', protectionStatus, true); expect(schemaValid).toBe(true); expect(protectionStatus.protectionStatus).toBe('NRFDL_PROTECTION_STATUS_NONE'); }); await Promise.all(nonProtectedCheckPromises); }); });