Skip to content

Commit

Permalink
CP-2931 added helper - mock-prebackup.ts, removed prebackup mock from…
Browse files Browse the repository at this point in the history
… mock-descriptors, updated test to use the added helper instead of writing it in mockdescriptor or inside the test
  • Loading branch information
robertmudi committed Dec 12, 2024
1 parent 53c4923 commit 570d035
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
32 changes: 32 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,32 @@
import { E2EMockClient } from "../../../../libs/e2e-mock/client/src"

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

// 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 @@ -4,6 +4,7 @@ import {
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 () => {
Expand Down Expand Up @@ -46,6 +47,11 @@ describe("E2E mock sample - overview view", () => {
await expect(menuItem).toBeDisplayed()
})

it("Mock Pre-Backup Responses", async () => {
// Use the helper function to mock PRE_BACKUP responses (so the backup process will be progressing)
mockPreBackupResponses("path-1", 12345)
})

it("Wait for Overview Page and click Create Backup", async () => {
const createBackupButton = await ModalBackupKompaktPage.createBackupButton
await expect(createBackupButton).toBeDisplayed()
Expand Down
30 changes: 0 additions & 30 deletions libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,6 @@ class MockDescriptor {
},
}
}
// Add method for mocking PRE_BACKUP responses
public mockPreBackupResponses(path: string, backupId: number) {
// Mock initial PRE_BACKUP response with status 202 (processing)
this.addResponse({
path,
endpoint: "PRE_BACKUP",
method: "POST",
status: 202,
body: {
backupId,
},
})

// After 10 seconds, update the response to status 200 (completed)
setTimeout(() => {
this.addResponse({
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)
}

public removeResponses({ path, requests }: RestoreDefaultResponses) {
requests?.forEach((request) => {
Expand Down

0 comments on commit 570d035

Please sign in to comment.