Skip to content

Commit

Permalink
Merge pull request #197 from gregolsky/v4.1
Browse files Browse the repository at this point in the history
RDBC-265
  • Loading branch information
gregolsky authored Jan 18, 2019
2 parents 4905243 + c0a909c commit 6cb7465
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ravendb",
"version": "4.1.3",
"version": "4.1.4",
"description": "RavenDB client for Node.js",
"files": [
"dist/"
Expand Down
4 changes: 3 additions & 1 deletion src/Documents/Commands/SeedIdentityForCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { throwError } from "../../Exceptions";
import { HttpRequestParameters } from "../../Primitives/Http";
import { ServerNode } from "../../Http/ServerNode";
import * as stream from "readable-stream";
import { TypeUtil } from "../../Utility/TypeUtil";

export class SeedIdentityForCommand extends RavenCommand<number> {

Expand Down Expand Up @@ -34,6 +35,7 @@ export class SeedIdentityForCommand extends RavenCommand<number> {
if (this._forced) {
uri += "&force=true";
}

return {
method: "POST",
uri
Expand All @@ -49,7 +51,7 @@ export class SeedIdentityForCommand extends RavenCommand<number> {
await this._defaultPipeline(_ => body = _).process(bodyStream)
.then(result => {
const newSeedValue = result["newSeedValue"];
if (!newSeedValue) {
if (TypeUtil.isNullOrUndefined(newSeedValue)) {
this._throwInvalidResponse();
}

Expand Down
58 changes: 58 additions & 0 deletions test/Issues/RDBC_265.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as mocha from "mocha";
import * as assert from "assert";
import { User, Company, Order } from "../Assets/Entities";
import { testContext, disposeTestDocumentStore } from "../Utils/TestUtil";

import {
RavenErrorType,
IDocumentStore,
SeedIdentityForCommand,
GetIdentitiesOperation,
} from "../../src";

describe("RDBC-265", function () {

let store: IDocumentStore;

beforeEach(async function () {
store = await testContext.getDocumentStore();
});

afterEach(async () =>
await disposeTestDocumentStore(store));

it("sets identity back to 0 only when forced", async () => {
{
const session = store.openSession();
const user = Object.assign(new User(), { lastName: "Adi" });
await session.store(user, "users|");
await session.saveChanges();
assert.strictEqual(user.id, "users/1");
}

let identities = await store.maintenance.send(new GetIdentitiesOperation());
assert.strictEqual(identities["users|"], 1);

let command = new SeedIdentityForCommand("users", 0);
await store.getRequestExecutor().execute(command);

identities = await store.maintenance.send(new GetIdentitiesOperation());
assert.strictEqual(identities["users|"], 1);

command = new SeedIdentityForCommand("users", 0, true);
await store.getRequestExecutor().execute(command);

identities = await store.maintenance.send(new GetIdentitiesOperation());
assert.strictEqual(identities["users|"], 0);

// the below won't work however
// due to https://github.com/ravendb/ravendb/blob/v4.1/test/SlowTests/Issues/RavenDB_9576.cs#L14
// {
// const session = store.openSession();
// const user = Object.assign(new User(), { lastName: "Avivi" });
// await session.store(user, "users|");
// await session.saveChanges();
// assert.strictEqual(user.id, "users/1");
// }
});
});
1 change: 0 additions & 1 deletion test/Ported/NextAndSeedIdentitiesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,4 @@ describe("NextAndSeedIdentitiesTest", function () {
const identities = await store.maintenance.send(new GetIdentitiesOperation());
assert.strictEqual(identities["users|"], 1991);
});

});

0 comments on commit 6cb7465

Please sign in to comment.