Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-2931 [API Device][Kompakt] Backup - PRE_BACKUP API #2227

Merged
merged 13 commits into from
Dec 12, 2024
Merged
30 changes: 30 additions & 0 deletions apps/mudita-center-e2e/src/helpers/mock-prebackup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { E2EMockClient } from "../../../../libs/e2e-mock/client/src"

// Helper function to mock PRE_BACKUP responses
export function mockPreBackupResponses(path: string) {
// Mock initial PRE_BACKUP response with status 202 (processing)
E2EMockClient.mockResponse({
path,
endpoint: "PRE_BACKUP",
method: "POST",
status: 202,
body: {},
})

// After 10 seconds, update the response to status 200 (completed)
// setTimeout(() => {
// E2EMockClient.mockResponse({
// path,
// endpoint: "PRE_BACKUP",
// method: "POST",
// status: 200,
// body: {
// backupId,
// features: {
// CONTACTS_V1: "path/to/backup/calls.json",
// CALL_LOGS_V1: "path/to/backup/call_logs.json",
// },
// },
// })
// }, 10000)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import {
PredefinedBackupProgressTestIds,
ProgressBarTestIds,
} from "../../../../libs/e2e-test-ids/src"
import { OverviewPage } from "./overview.page"

class ModalBackupKompaktPage extends OverviewPage {
Expand Down Expand Up @@ -87,5 +91,27 @@ class ModalBackupKompaktPage extends OverviewPage {
public get passwordsDoNotMatch() {
return $('[data-testid="interactive-text-input-error-text"]')
}

public get backupInProgressModal() {
return $('//*[@data-testid="modal-content-backupbackup-create"]')
}

public get creatingBackupTitle() {
return $(`//*[@data-testid="predefined-backup-progress-title"]`)
}

public get creatingBackupDescription() {
return $(
`//*[@data-testid="${PredefinedBackupProgressTestIds.Description}"]`
)
}

public get creatingBackupProgressBar() {
return $(`//*[@data-testid="${ProgressBarTestIds.Progress}"]`)
}

public get creatingBackupProgressBarDetails() {
return $(`//*[@data-testid="${ProgressBarTestIds.Details}"]`)
}
}
export default new ModalBackupKompaktPage()
90 changes: 90 additions & 0 deletions apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { E2EMockClient } from "../../../../../libs/e2e-mock/client/src"
import {
overviewConfigForBackup,
overviewDataWithOneSimCard,
} from "../../../../../libs/e2e-mock/responses/src"
import ModalBackupKompaktPage from "../../page-objects/modal-backup-kompakt.page"
import { mockPreBackupResponses } from "../../helpers/mock-prebackup"

describe("E2E mock sample - overview view", () => {
before(async () => {
E2EMockClient.connect()
//wait for a connection to be established
await browser.waitUntil(() => {
return E2EMockClient.checkConnection()
})
})

after(() => {
E2EMockClient.stopServer()
E2EMockClient.disconnect()
})

it("Connect device", async () => {
E2EMockClient.mockResponse({
path: "path-1",
body: overviewConfigForBackup,
endpoint: "FEATURE_CONFIGURATION",
method: "GET",
status: 200,
})
E2EMockClient.mockResponse({
path: "path-1",
body: overviewDataWithOneSimCard,
endpoint: "FEATURE_DATA",
method: "GET",
status: 200,
})
E2EMockClient.addDevice({
path: "path-1",
serialNumber: "first-serial-number",
})

await browser.pause(6000)
const menuItem = await $(`//a[@href="#/generic/mc-overview"]`)

await menuItem.waitForDisplayed({ timeout: 10000 })
await expect(menuItem).toBeDisplayed()
})

it("Mock prebackup, wait for Overview Page and click Create Backup", async () => {
mockPreBackupResponses("path-1")
const createBackupButton = await ModalBackupKompaktPage.createBackupButton
await expect(createBackupButton).toBeDisplayed()
await expect(createBackupButton).toBeClickable()
await createBackupButton.click()
})

it("Click Create backup and click skip password to start backup", async () => {
const createBackupProceedNext =
await ModalBackupKompaktPage.createBackupProceedNext
await expect(createBackupProceedNext).toBeClickable()
await createBackupProceedNext.click()

const createBackupPasswordSkip =
await ModalBackupKompaktPage.createBackupPasswordSkip
await createBackupPasswordSkip.click()
})

it("Verify backup creating modal, check if backup is in progress", async () => {
const backupInProgressModal =
await ModalBackupKompaktPage.backupInProgressModal
await expect(backupInProgressModal).toBeDisplayed()
await expect(ModalBackupKompaktPage.creatingBackupTitle).toHaveText(
"Creating backup"
)
await expect(ModalBackupKompaktPage.creatingBackupDescription).toHaveText(
"Please wait and do not unplug your device from computer."
)
const creatingBackupProgressBar =
await ModalBackupKompaktPage.creatingBackupProgressBar

const creatingBackupProgressBarValue =
await creatingBackupProgressBar.getAttribute("value")
expect(creatingBackupProgressBarValue).toBe("10")

const creatingBackupProgressBarDetails =
await ModalBackupKompaktPage.creatingBackupProgressBarDetails
await expect(creatingBackupProgressBarDetails).toHaveText("10%")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export enum TestFilesPaths {
helpVerifyFeedback = "src/specs/help/help-verify-feedback.ts",
helpSectionSearchNoResults = "src/specs/help/help-section-search-noresults.e2e.ts",
helpLinkInsideContainer = "src/specs/help/help-link-inside-container.ts",
kompaktPrebackupApi = "src/specs/overview/kompakt-prebackup-api.ts",
}
export const toRelativePath = (path: string) => `./${path}`
3 changes: 3 additions & 0 deletions apps/mudita-center-e2e/wdio.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.helpVerifyFeedback),
toRelativePath(TestFilesPaths.helpSectionSearchNoResults),
toRelativePath(TestFilesPaths.helpLinkInsideContainer),
toRelativePath(TestFilesPaths.kompaktPrebackupApi),
],
suites: {
standalone: [
Expand Down Expand Up @@ -113,6 +114,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.kompaktConnectedDevicesModalStressTest),
toRelativePath(TestFilesPaths.kompaktDrawerStressTest),
toRelativePath(TestFilesPaths.kompaktBackupModalGettingInitialInfo),
toRelativePath(TestFilesPaths.kompaktPrebackupApi),
],
multidevicePureHarmony: [],
multideviceSingleHarmony: [],
Expand Down Expand Up @@ -152,6 +154,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.kompaktConnectedDevicesModalStressTest),
toRelativePath(TestFilesPaths.kompaktDrawerStressTest),
toRelativePath(TestFilesPaths.kompaktBackupModalGettingInitialInfo),
toRelativePath(TestFilesPaths.kompaktPrebackupApi),
],
},
// Patterns to exclude.
Expand Down
33 changes: 13 additions & 20 deletions libs/core/settings/services/configuration.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import MockAdapter from "axios-mock-adapter"
import axios from "axios"
import { Configuration } from "Core/settings/dto"
import { ConfigurationService } from "Core/settings/services/configuration.service"

Expand All @@ -19,12 +17,6 @@ jest.mock("history", () => ({
})),
}))

const createMockAdapter = (): MockAdapter => {
return new MockAdapter(axios)
}

let axiosMock: MockAdapter = createMockAdapter()

const previousEnvironment = { ...process.env }

const configuration: Configuration = {
Expand All @@ -45,10 +37,6 @@ const defaultConfig = {
},
}

beforeEach(() => {
axiosMock = createMockAdapter()
})

beforeAll(() => {
process.env = {
...previousEnvironment,
Expand All @@ -62,16 +50,24 @@ afterAll(() => {
}
})

const mockGet = jest.fn()

jest.mock("shared/http-client", () => ({
HttpClient: {
create: jest.fn(() => ({
get: mockGet,
})),
},
}))

jest.doMock(
"Core/settings/static/default-app-configuration.json",
() => defaultConfig
)

describe("When API return success status code", () => {
test("returns API response", async () => {
axiosMock
.onGet("http://localhost/v2-app-configuration")
.replyOnce(200, configuration)
mockGet.mockResolvedValueOnce({ data: configuration, status: 200 })

const subject = new ConfigurationService()
const result = await subject.getConfiguration()
Expand All @@ -81,11 +77,8 @@ describe("When API return success status code", () => {

describe("When API return failed status code", () => {
test("returns default configuration value", async () => {
axiosMock.onGet("http://localhost/v2-app-configuration").replyOnce(500, {
error: "Luke, I'm your error",
})
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
mockGet.mockResolvedValueOnce({ error: "Luke, I'm your error", status: 500 })

const appConfiguration = require("../static/app-configuration.json")
const subject = new ConfigurationService()
const result = await subject.getConfiguration()
Expand Down
11 changes: 7 additions & 4 deletions libs/core/settings/services/configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*/

import https from "https"
import { Axios, AxiosResponse } from "axios"
import { HttpClient } from "shared/http-client"
import {
BaseHttpAxiosResponse,
BaseHttpClientService,
HttpClient,
} from "shared/http-client"
import defaultConfiguration from "Core/settings/static/default-app-configuration.json"
import { Configuration } from "Core/settings/dto"
import { MuditaCenterServerRoutes } from "Core/__deprecated__/api/mudita-center-server/mudita-center-server-routes"
Expand All @@ -20,7 +23,7 @@ export interface getNewConfigurationParams {
}

export class ConfigurationService {
private instance: Axios
private instance: BaseHttpClientService
private defaultConfiguration: Configuration =
defaultConfiguration as unknown as Configuration

Expand Down Expand Up @@ -52,7 +55,7 @@ export class ConfigurationService {

private async getNewConfiguration(
params: getNewConfigurationParams
): Promise<AxiosResponse<Configuration>> {
): Promise<BaseHttpAxiosResponse<Configuration>> {
return this.instance.get<Configuration>(
MuditaCenterServerRoutes.AppConfigurationV2,
{
Expand Down
27 changes: 24 additions & 3 deletions libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { findIndex, pullAt, find } from "lodash"
import { findIndex, pullAt, find, merge } from "lodash"
import { PortInfo } from "serialport"
import {
AddKompakt,
Expand Down Expand Up @@ -205,7 +205,25 @@ class MockDescriptor {
method,
responses: perDeviceOnceResponses,
})
return foundResponse.response
return merge(
foundResponse.response,
this.fillEndpointSpecificFields(endpoint, method, body)
)
}
}
return undefined
}

private fillEndpointSpecificFields(
endpoint: APIEndpointType,
method: APIMethodsType,
body: Record<string, unknown> | undefined
) {
if ((method === "POST" || method === "GET") && endpoint === "PRE_BACKUP") {
return {
body: {
backupId: body?.["backupId"],
},
}
}
return undefined
Expand All @@ -223,7 +241,10 @@ class MockDescriptor {
const foundResponse = this.findResponse(perDeviceResponses, body)

if (foundResponse) {
return foundResponse.response
return merge(
foundResponse.response,
this.fillEndpointSpecificFields(endpoint, method, body)
)
}
}
return undefined
Expand Down
Loading