mirror of
https://github.com/mudita/mudita-center.git
synced 2025-12-23 22:28:03 -05:00
[CP-3917] Clear device data system action (#2689)
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
import { clearContact } from "./helpers/clear-contact-data"
|
||||
import { exec } from "child_process"
|
||||
import util from "util"
|
||||
import { clearDeviceData } from "./helpers/clear-device-data"
|
||||
export const execPromise = util.promisify(exec)
|
||||
|
||||
jest.mock("shared/utils", () => {
|
||||
@@ -48,8 +49,8 @@ describe("Contact entities", () => {
|
||||
}, 10000)
|
||||
|
||||
beforeEach(async () => {
|
||||
await clearContactsDatabase()
|
||||
deviceProtocol = setActiveDevice(await setKompaktConnection())
|
||||
await clearDatabase(deviceProtocol)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -242,12 +243,9 @@ describe("Contact entities", () => {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const clearContactsDatabase = async (): Promise<void> => {
|
||||
try {
|
||||
const command = `adb shell pm clear com.android.providers.contacts`
|
||||
await execPromise(command)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
const clearDatabase = async (
|
||||
deviceProtocol: DeviceProtocol
|
||||
): Promise<void> => {
|
||||
await clearDeviceData(deviceProtocol)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) Mudita sp. z o.o. All rights reserved.
|
||||
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
import { DeviceProtocol } from "device-protocol/feature"
|
||||
import { DeviceSystemActionsService } from "device/feature"
|
||||
|
||||
export const clearDeviceData = async (deviceProtocol: DeviceProtocol) => {
|
||||
const systemActionsService = new DeviceSystemActionsService(deviceProtocol)
|
||||
return await systemActionsService.clearDeviceData()
|
||||
}
|
||||
@@ -18,3 +18,4 @@ export * from "./lib/data-transfer"
|
||||
export * from "./lib/msc-device"
|
||||
export * from "./lib/service-bridge"
|
||||
export * from "./lib/api-test-tools"
|
||||
export * from "./lib/device-system-actions"
|
||||
|
||||
@@ -53,4 +53,9 @@ export class DeviceSystemActionsService {
|
||||
public powerOff({ deviceId }: { deviceId?: string } = {}) {
|
||||
return this.sendSystemRequest("powerOff", { deviceId })
|
||||
}
|
||||
|
||||
@IpcEvent(DeviceSystemActionsServiceEvents.ClearData)
|
||||
public clearDeviceData({ deviceId }: { deviceId?: string } = {}) {
|
||||
return this.sendSystemRequest("clearData", { deviceId })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Copyright (c) Mudita sp. z o.o. All rights reserved.
|
||||
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
export * from "./device-system-actions.service"
|
||||
@@ -7,4 +7,5 @@ export enum DeviceSystemActionsServiceEvents {
|
||||
Reboot = "apiservice_device_system_actions-reboot",
|
||||
Lock = "apiservice_device_system_actions-lock",
|
||||
PowerOff = "apiservice_device_system_actions-power-off",
|
||||
ClearData = "apiservice_device_system_actions-clear-data",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user