Skip to content

Commit

Permalink
Merge branch 'main' into users/ramukaritik/entityForeignKeyDataMap
Browse files Browse the repository at this point in the history
  • Loading branch information
ritikramuka authored Nov 8, 2023
2 parents ab52927 + b0b51a2 commit 142b9ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ describe("Authentication Provider", () => {
expect(result).empty;
});

it("dataverseAuthentication_return_blank_if_excetion_thrown", async () => {
it("dataverseAuthentication_return_blank_if_exception_thrown", async () => {
//Action
const errorMessage = "access token not fount";
const errorMessage = "access token not found";
const dataverseOrgURL = "f068ee9f-a010-47b9-b1e1-7e6353730e7d";
const _mockgetSession = sinon
.stub(await vscode.authentication, "getSession")
Expand All @@ -98,15 +98,16 @@ describe("Authentication Provider", () => {
WebExtensionContext.telemetry,
"sendErrorTelemetry"
);
// Act

// Act
const result = await dataverseAuthentication(dataverseOrgURL);

//Assert
sinon.assert.calledOnce(sendError);
sinon.assert.calledWith(
sendError,
telemetryEventNames.WEB_EXTENSION_DATAVERSE_AUTHENTICATION_FAILED,
dataverseAuthentication.name,
errorMessage
);
sinon.assert.calledOnce(_mockgetSession);
Expand Down
42 changes: 36 additions & 6 deletions src/web/client/test/integration/commonUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,37 @@ import {
} from "../../utilities/commonUtil";

describe("commonUtil", async () => {
it("convertfromBase64ToString_shouldConvertBase64ToString", () => {
it("convertContentToUint8Array_shouldReturnBase64AsUint8Output", () => {
//Act
const data = "this is test case";
const encodedString = "dGhpcyBpcyB0ZXN0IGNhc2U=";
const encodedString = "dGhpcyBpcyB0ZXN0IGNhc2U="; // "this is test case"
//Action
const base64toUint8Array = convertContentToUint8Array(encodedString, true);

//Assert
expect(base64toUint8Array).instanceOf(Uint8Array);
});

it("convertContentToUint8Array_shouldReturnStringAsUint8Output", () => {
//Act
const encodedString = "this is test case=";
//Action
const base64totext = convertContentToUint8Array(encodedString, true);
const base64toUint8Array = convertContentToUint8Array(encodedString, false);

//Assert
expect(base64totext).eq(data);
expect(base64toUint8Array).instanceOf(Uint8Array);
});

it("convertStringtoBase64_shouldConvertStringToBase64", () => {
it("shouldConvertBase64ToString", () => {
//Act
const encodedString = "dGhpcyBpcyB0ZXN0IGNhc2U="; // "this is test case"
//Action
const base64toUint8Array = convertContentToUint8Array(encodedString, true);
const unit8ArrayToBase64 = convertContentToString(base64toUint8Array, true);
//Assert
expect(unit8ArrayToBase64).eq(encodedString);
});

it("convertContentToString_shouldConvertBase64ToString", () => {
//Act
const data = "this is test case";
const encodedString = "dGhpcyBpcyB0ZXN0IGNhc2U=";
Expand All @@ -32,6 +52,16 @@ describe("commonUtil", async () => {
expect(base64).eq(encodedString);
});

it("convertContentToString_shouldReturnUint8ArrayAsUint8Array", () => {
//Act
const data = new Uint8Array(Buffer.from("this is test case"));
//Action
const uint8 = convertContentToString(data, false);
//Assert
expect(uint8).instanceOf(Uint8Array);
expect(uint8).eq(data);
});

it("GetFileNameWithExtension_withEntityWebpages_shouldAddFileNameWithExtension", () => {
//Act
const entity = schemaEntityName.WEBPAGES;
Expand Down
2 changes: 1 addition & 1 deletion src/web/client/utilities/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,5 @@ export function updateFileContentInFileDataMap(fileFsPath: string, fileContent:
export function getImageFileContent(fileFsPath: string, fileContent: Uint8Array) {
const webFileV2 = isWebFileV2(getFileEntityName(fileFsPath), getFileAttributePath(fileFsPath)?.source);

return webFileV2 ? fileContent : Buffer.from(fileContent).toString(BASE_64);
return webFileV2 ? fileContent : convertContentToString(fileContent, true);
}

0 comments on commit 142b9ae

Please sign in to comment.