-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CP-3206][API Device][Kompakt] Contacts - mock helpers (#2250)
Co-authored-by: Katarzyna Stegienko <[email protected]>
- Loading branch information
1 parent
094f90c
commit 04cdd76
Showing
11 changed files
with
2,368 additions
and
170 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
apps/mudita-center-e2e/src/helpers/mock-entity-download-process.helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} |
22 changes: 22 additions & 0 deletions
22
apps/mudita-center-e2e/src/helpers/utils/generate-base-64-info.helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
apps/mudita-center-e2e/src/helpers/utils/generate-unique-number-id.helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.