Skip to content

Commit

Permalink
[CP-3206][API Device][Kompakt] Contacts - mock helpers (#2250)
Browse files Browse the repository at this point in the history
Co-authored-by: Katarzyna Stegienko <[email protected]>
  • Loading branch information
dkarski and katarzynastegienko authored Dec 20, 2024
1 parent 094f90c commit 04cdd76
Show file tree
Hide file tree
Showing 11 changed files with 2,368 additions and 170 deletions.
998 changes: 998 additions & 0 deletions apps/mudita-center-e2e/src/helpers/entity-fixtures.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/mudita-center-e2e/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

export * from "./mock-entity-download-process.helper"
export * from "./sleep.helper"
export * from "./testid.helper"
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { E2EMockClient } from "../../../../libs/e2e-mock/client/src/lib/e2e-mock-client"
import { generateUniqueNumber } from "./utils/generate-unique-number-id.helper"
import { generateBase64Info } from "./utils/generate-base-64-info.helper"

interface mockEntityDownloadProcessOptions {
path: string
entityType: string
data: Record<string, unknown>[]
}

export const mockEntityDownloadProcess = ({
path,
entityType,
data,
}: mockEntityDownloadProcessOptions) => {
const { base64, sizeInBytes, crc32Hex } = generateBase64Info({ data })
const totalEntities = data.length
const transferId = generateUniqueNumber()

E2EMockClient.mockResponse({
path,
body: { totalEntities, uniqueKey: "1733750368390" },
match: {
expected: {
entityType: entityType,
},
},
endpoint: "ENTITIES_METADATA",
method: "GET",
status: 200,
})

E2EMockClient.mockResponse({
path,
body: {
filePath: `../${entityType}_entities.json`,
progress: 100,
},
match: {
expected: {
entityType: entityType,
responseType: "file",
},
},
endpoint: "ENTITIES_DATA",
method: "GET",
status: 200,
})

E2EMockClient.mockResponse({
path,
body: {
transferId,
chunkSize: sizeInBytes,
fileSize: sizeInBytes,
crc32: crc32Hex,
},
match: {
expected: {
filePath: `../${entityType}_entities.json`,
},
},
endpoint: "PRE_FILE_TRANSFER",
method: "GET",
status: 200,
})

E2EMockClient.mockResponse({
path,
body: {
transferId,
chunkNumber: 1,
data: base64,
},
match: {
expected: {
transferId,
chunkNumber: 1,
},
},
endpoint: "FILE_TRANSFER",
method: "GET",
status: 200,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import crc32 from "crc-32"

export function generateBase64Info(obj: Record<string, unknown>) {
const jsonString = JSON.stringify(obj)
const data = Buffer.from(jsonString, "utf8").toString()
const base64String = Buffer.from(data).toString("base64")
const sizeInBytes = Buffer.byteLength(data, "utf8")
const crc32Hex = (crc32.buf(Buffer.from(base64String, "utf8")) >>> 0)
.toString(16)
.padStart(8, "0")

return {
base64: base64String,
sizeInBytes: sizeInBytes,
crc32Hex: crc32Hex,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

export const generateUniqueNumber = () =>
Date.now() + Math.floor(Math.random() * 1000)
145 changes: 129 additions & 16 deletions apps/mudita-center-e2e/src/specs/overview/e2e-mock-lock-sample.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// import { DEFAULT_RESPONSES } from "Libs/e2e-mock/responses/src/lib/default-responses"
import { E2EMockClient } from "../../../../../libs/e2e-mock/client/src"
import { DEFAULT_RESPONSES } from "../../../../../libs/e2e-mock/responses/src"
import { mockEntityDownloadProcess } from "../../helpers/mock-entity-download-process.helper"
import {
DEFAULT_RESPONSES,
outboxReloadOverview,
overviewDataWithoutBadge,
} from "../../../../../libs/e2e-mock/responses/src"
// import { outboxReloadOverview } from "Libs/e2e-mock/responses/src"
audioFileEntities,
selectedContactsEntities,
} from "../../helpers/entity-fixtures"

function getBodyAsRecord(body: unknown): Record<string, any> {
return body ? (body as Record<string, any>) : {}
}

describe("E2E mock lock sample", () => {
before(async () => {
Expand Down Expand Up @@ -66,34 +69,111 @@ describe("E2E mock lock sample", () => {

E2EMockClient.mockResponse({
path: "path-1",
body: DEFAULT_RESPONSES.FEATURE_DATA?.GET?.body as Record<string, any>,
body: getBodyAsRecord(
DEFAULT_RESPONSES.API_CONFIGURATION?.GET?.[0]?.body
),
endpoint: "API_CONFIGURATION",
method: "GET",
status: 200,
})

await browser.pause(2000)

E2EMockClient.mockResponse({
path: "path-1",
body: getBodyAsRecord(DEFAULT_RESPONSES.FEATURE_DATA?.GET?.[0]?.body),
match: {
expected: {
feature: "mc-overview",
lang: "en-US",
},
},
endpoint: "FEATURE_DATA",
method: "GET",
status: 200,
})

// await browser.pause(2000)
E2EMockClient.mockResponse({
path: "path-1",
body: DEFAULT_RESPONSES.FEATURE_CONFIGURATION?.GET?.body as Record<
string,
any
>,
body: getBodyAsRecord(DEFAULT_RESPONSES.FEATURE_DATA?.GET?.[1]?.body),
match: {
expected: {
feature: "fileManager",
lang: "en-US",
},
},
endpoint: "FEATURE_DATA",
method: "GET",
status: 200,
})

await browser.pause(2000)

E2EMockClient.mockResponse({
path: "path-1",
body: getBodyAsRecord(
DEFAULT_RESPONSES.FEATURE_CONFIGURATION?.GET?.[0]?.body
),
match: {
expected: {
feature: "contacts",
lang: "en-US",
},
},
endpoint: "FEATURE_CONFIGURATION",
method: "GET",
status: 200,
})
E2EMockClient.mockResponse({
path: "path-1",
body: getBodyAsRecord(
DEFAULT_RESPONSES.FEATURE_CONFIGURATION?.GET?.[1]?.body
),
match: {
expected: {
feature: "mc-overview",
lang: "en-US",
},
},
endpoint: "FEATURE_CONFIGURATION",
method: "GET",
status: 200,
})
E2EMockClient.mockResponse({
path: "path-1",
body: getBodyAsRecord(
DEFAULT_RESPONSES.FEATURE_CONFIGURATION?.GET?.[2]?.body
),
match: {
expected: {
feature: "fileManager",
lang: "en-US",
},
},
endpoint: "FEATURE_CONFIGURATION",
method: "GET",
status: 200,
})
E2EMockClient.mockResponse({
path: "path-1",
body: DEFAULT_RESPONSES.MENU_CONFIGURATION?.GET?.body as Record<
string,
any
>,
body: getBodyAsRecord(
DEFAULT_RESPONSES.MENU_CONFIGURATION?.GET?.[0]?.body
),
endpoint: "MENU_CONFIGURATION",
method: "GET",
status: 200,
})

E2EMockClient.mockResponse({
path: "path-1",
body: getBodyAsRecord(
DEFAULT_RESPONSES.ENTITIES_METADATA?.GET?.[0]?.body
),
endpoint: "ENTITIES_METADATA",
method: "GET",
status: 200,
})

E2EMockClient.mockResponse({
path: "path-1",
body: {
Expand All @@ -105,6 +185,39 @@ describe("E2E mock lock sample", () => {
status: 200,
})

E2EMockClient.mockResponse({
path: "path-1",
body: getBodyAsRecord(
DEFAULT_RESPONSES.ENTITIES_CONFIGURATION?.GET?.[0]?.body
),
match: { expected: { entityType: "contacts" } },
endpoint: "ENTITIES_CONFIGURATION",
method: "GET",
status: 200,
})

E2EMockClient.mockResponse({
path: "path-1",
body: getBodyAsRecord(
DEFAULT_RESPONSES.ENTITIES_CONFIGURATION?.GET?.[1]?.body
),
match: { expected: { entityType: "audioFiles" } },
endpoint: "ENTITIES_CONFIGURATION",
method: "GET",
status: 200,
})

mockEntityDownloadProcess({
path: "path-1",
data: selectedContactsEntities,
entityType: "contacts",
})
mockEntityDownloadProcess({
path: "path-1",
data: audioFileEntities,
entityType: "audioFiles",
})

await browser.pause(10000)
})
})
Loading

0 comments on commit 04cdd76

Please sign in to comment.