Skip to content

Commit

Permalink
Addressing ESLint violation (Azure#22830)
Browse files Browse the repository at this point in the history
* Fixing id encoding issues when using special characters for customers already on ComputeGateway

* Update CHANGELOG.md

* Update CHANGELOG.md

* Fixing typos

* Update cosmos-integration-public.yml

* Update itemIdEncoding.spec.ts

* Reformatting
  • Loading branch information
FabianMeiswinkel committed Aug 5, 2022
1 parent ce35c33 commit 44ef7fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions sdk/cosmosdb/cosmos/src/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ export function isItemResourceValid(resource: { id?: string }, err: { message?:
return false;
}

if (resource.id.indexOf("/") !== -1 || resource.id.indexOf("\\") !== -1 || resource.id.indexOf("#") !== -1) {
if (
resource.id.indexOf("/") !== -1 ||
resource.id.indexOf("\\") !== -1 ||
resource.id.indexOf("#") !== -1
) {
err.message = "Id contains illegal chars.";
return false;
}
Expand Down Expand Up @@ -287,7 +291,7 @@ export function validateResourceId(resourceId: string): boolean {
/**
* @hidden
*/
export function validateItemResourceId(resourceId: string): boolean {
export function validateItemResourceId(resourceId: string): boolean {
// if resourceId is not a string or is empty throw an error
if (typeof resourceId !== "string" || isStringNullOrEmpty(resourceId)) {
throw new Error("Resource ID must be a string and cannot be undefined, null or empty");
Expand Down
22 changes: 15 additions & 7 deletions sdk/cosmosdb/cosmos/test/public/functional/itemIdEncoding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import assert from "assert";
import { Suite } from "mocha";
import { Container, CosmosClient } from "../../../src";
import { getTestContainer, removeAllDatabases, defaultClient, defaultComputeGatewayClient } from "../common/TestHelpers";
import {
getTestContainer,
removeAllDatabases,
defaultClient,
defaultComputeGatewayClient,
} from "../common/TestHelpers";

interface ItemPayload {
id?: string;
Expand All @@ -27,12 +32,11 @@ const createPayload = function (id: string): ItemPayload {
};
};

const executeTestCaseOnComputeGateway = async function (scenario: TestScenario) {
return executeTestCase(scenario, true);
}

const executeTestCase = async function (scenario: TestScenario, useComputeGateway: boolean = false) {
const client: CosmosClient = useComputeGateway ? defaultComputeGatewayClient : defaultClient
const executeTestCase = async function (
scenario: TestScenario,
useComputeGateway: boolean = false
) {
const client: CosmosClient = useComputeGateway ? defaultComputeGatewayClient : defaultClient;
const container: Container = await getTestContainer(scenario.name, client, {
partitionKey: {
paths: ["/pk"],
Expand Down Expand Up @@ -109,6 +113,10 @@ const executeTestCase = async function (scenario: TestScenario, useComputeGatewa
}
};

const executeTestCaseOnComputeGateway = async function (scenario: TestScenario) {
return executeTestCase(scenario, true);
};

describe("Id encoding", function (this: Suite) {
this.timeout(process.env.MOCHA_TIMEOUT || 10000);
beforeEach(async function () {
Expand Down

0 comments on commit 44ef7fc

Please sign in to comment.