Skip to content

Commit

Permalink
[CosmosDB] formatting (#10268)
Browse files Browse the repository at this point in the history
  • Loading branch information
deyaaeldeen authored Jul 29, 2020
1 parent d4a9ed6 commit bf0ed88
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
14 changes: 7 additions & 7 deletions sdk/cosmosdb/cosmos/src/client/Item/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getPathFromLink,
isResourceValid,
ResourceType,
StatusCodes,
StatusCodes
} from "../../common";
import { PartitionKey } from "../../documents";
import { extractPartitionKey, undefinedPartitionKey } from "../../extractPartitionKey";
Expand Down Expand Up @@ -75,7 +75,7 @@ export class Item {
): Promise<ItemResponse<T>> {
if (this.partitionKey === undefined) {
const {
resource: partitionKeyDefinition,
resource: partitionKeyDefinition
} = await this.container.readPartitionKeyDefinition();
this.partitionKey = undefinedPartitionKey(partitionKeyDefinition);
}
Expand All @@ -88,7 +88,7 @@ export class Item {
resourceType: ResourceType.item,
resourceId: id,
options,
partitionKey: this.partitionKey,
partitionKey: this.partitionKey
});
} catch (error) {
if (error.code !== StatusCodes.NotFound) {
Expand Down Expand Up @@ -139,7 +139,7 @@ export class Item {
): Promise<ItemResponse<T>> {
if (this.partitionKey === undefined) {
const {
resource: partitionKeyDefinition,
resource: partitionKeyDefinition
} = await this.container.readPartitionKeyDefinition();
this.partitionKey = extractPartitionKey(body, partitionKeyDefinition);
}
Expand All @@ -158,7 +158,7 @@ export class Item {
resourceType: ResourceType.item,
resourceId: id,
options,
partitionKey: this.partitionKey,
partitionKey: this.partitionKey
});
return new ItemResponse(
response.result,
Expand All @@ -182,7 +182,7 @@ export class Item {
): Promise<ItemResponse<T>> {
if (this.partitionKey === undefined) {
const {
resource: partitionKeyDefinition,
resource: partitionKeyDefinition
} = await this.container.readPartitionKeyDefinition();
this.partitionKey = undefinedPartitionKey(partitionKeyDefinition);
}
Expand All @@ -195,7 +195,7 @@ export class Item {
resourceType: ResourceType.item,
resourceId: id,
options,
partitionKey: this.partitionKey,
partitionKey: this.partitionKey
});
return new ItemResponse(
response.result,
Expand Down
13 changes: 8 additions & 5 deletions sdk/cosmosdb/cosmos/src/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function parseLink(resourcePath: string) {
/* for DatabaseAccount case, both type and objectBody will be undefined. */
return {
type: undefined,
objectBody: undefined,
objectBody: undefined
};
}

Expand Down Expand Up @@ -64,8 +64,8 @@ export function parseLink(resourcePath: string) {
type,
objectBody: {
id,
self: resourcePath,
},
self: resourcePath
}
};

return result;
Expand Down Expand Up @@ -93,7 +93,10 @@ export function sleep(time: number): Promise<void> {
* @ignore
*/
export function getContainerLink(link: string) {
return link.split("/").slice(0, 4).join("/");
return link
.split("/")
.slice(0, 4)
.join("/");
}

/**
Expand Down Expand Up @@ -308,7 +311,7 @@ export function parseConnectionString(connectionString: string): CosmosClientOpt
}
return {
endpoint: AccountEndpoint,
key: AccountKey,
key: AccountKey
};
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/cosmosdb/cosmos/src/request/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function httpRequest(requestContext: RequestContext) {
return parsedUrl.protocol === "http" ? defaultHttpAgent : defaultHttpsAgent;
},
signal,
body: requestContext.body,
body: requestContext.body
} as RequestInit);
} catch (error) {
if (error.name === "AbortError") {
Expand Down Expand Up @@ -119,7 +119,7 @@ async function httpRequest(requestContext: RequestContext) {
Object.defineProperty(errorResponse, "retryAfterInMilliseconds", {
get: () => {
return errorResponse.retryAfterInMs;
},
}
});
}

Expand All @@ -129,7 +129,7 @@ async function httpRequest(requestContext: RequestContext) {
headers,
result,
code: response.status,
substatus,
substatus
};
}

Expand All @@ -147,6 +147,6 @@ export async function request<T>(requestContext: RequestContext): Promise<Cosmos

return RetryUtility.execute({
requestContext,
executeRequest,
executeRequest
});
}
30 changes: 15 additions & 15 deletions sdk/cosmosdb/cosmos/test/functional/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import {
getTestDatabase,
getTestContainer,
generateDocuments,
bulkInsertItems,
bulkInsertItems
} from "../common/TestHelpers";
import AbortController from "node-abort-controller";

describe("NodeJS CRUD Tests", function () {
describe("NodeJS CRUD Tests", function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);

describe("Validate client request timeout", function () {
it("timeout occurs within expected timeframe", async function () {
describe("Validate client request timeout", function() {
it("timeout occurs within expected timeframe", async function() {
// making timeout 1 ms to make sure it will throw
// (create database request takes 10ms-15ms to finish on emulator)
const client = new CosmosClient({
endpoint,
key: masterKey,
connectionPolicy: { requestTimeout: 1 },
connectionPolicy: { requestTimeout: 1 }
});
// create database
try {
Expand All @@ -34,27 +34,27 @@ describe("NodeJS CRUD Tests", function () {
});
});

describe("Constructor", function () {
it("Accepts node Agent", function () {
describe("Constructor", function() {
it("Accepts node Agent", function() {
const client = new CosmosClient({
endpoint: "https://faaaaaake.com",
agent: new Agent(),
agent: new Agent()
});
assert.ok(client !== undefined, "client shouldn't be undefined if it succeeded");
});
it("Accepts a connection string", function () {
it("Accepts a connection string", function() {
const client = new CosmosClient(`AccountEndpoint=${endpoint};AccountKey=${masterKey};`);
assert.ok(client !== undefined, "client shouldn't be undefined if it succeeded");
});
it("throws on a bad connection string", function () {
it("throws on a bad connection string", function() {
assert.throws(() => new CosmosClient(`bad;Connection=string;`));
});
it("throws on a bad endpoint", function () {
assert.throws(() => new CosmosClient({ endpoint: "asda=asda;asada;" }));
});
});
describe("Validate user passed AbortController.signal", function () {
it("should throw exception if aborted during the request", async function () {
describe("Validate user passed AbortController.signal", function() {
it("should throw exception if aborted during the request", async function() {
const client = new CosmosClient({ endpoint, key: masterKey });
try {
const controller = new AbortController();
Expand All @@ -66,7 +66,7 @@ describe("NodeJS CRUD Tests", function () {
assert.equal(err.name, "AbortError", "client should throw exception");
}
});
it("should throw exception if passed an already aborted signal", async function () {
it("should throw exception if passed an already aborted signal", async function() {
const client = new CosmosClient({ endpoint, key: masterKey });
try {
const controller = new AbortController();
Expand All @@ -78,7 +78,7 @@ describe("NodeJS CRUD Tests", function () {
assert.equal(err.name, "AbortError", "client should throw exception");
}
});
it("should abort a query", async function () {
it("should abort a query", async function() {
const container = await getTestContainer("abort query");
await bulkInsertItems(container, generateDocuments(20));
try {
Expand All @@ -94,7 +94,7 @@ describe("NodeJS CRUD Tests", function () {
assert.equal(err.name, "AbortError", "client should throw exception");
}
});
it("should not abort if abort signal is never called", async function () {
it("should not abort if abort signal is never called", async function() {
// Testing the happy path to prevent this bug https://github.com/Azure/azure-sdk-for-js/issues/9510
const client = new CosmosClient({ endpoint, key: masterKey });
try {
Expand Down

0 comments on commit bf0ed88

Please sign in to comment.