Skip to content

Commit 68fdd2a

Browse files
authored
Merge pull request #196 from gregolsky/v4.0
RDBC-265
2 parents e3fa4c4 + 22bfcf8 commit 68fdd2a

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ravendb",
3-
"version": "4.0.8",
3+
"version": "4.0.9",
44
"description": "RavenDB client for Node.js",
55
"files": [
66
"dist/"

src/Documents/Commands/SeedIdentityForCommand.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { throwError } from "../../Exceptions";
33
import { HttpRequestParameters } from "../../Primitives/Http";
44
import { ServerNode } from "../../Http/ServerNode";
55
import * as stream from "readable-stream";
6+
import { TypeUtil } from "../../Utility/TypeUtil";
67

78
export class SeedIdentityForCommand extends RavenCommand<number> {
89

@@ -34,6 +35,7 @@ export class SeedIdentityForCommand extends RavenCommand<number> {
3435
if (this._forced) {
3536
uri += "&force=true";
3637
}
38+
3739
return {
3840
method: "POST",
3941
uri
@@ -49,7 +51,7 @@ export class SeedIdentityForCommand extends RavenCommand<number> {
4951
await this._defaultPipeline(_ => body = _).process(bodyStream)
5052
.then(result => {
5153
const newSeedValue = result["newSeedValue"];
52-
if (!newSeedValue) {
54+
if (TypeUtil.isNullOrUndefined(newSeedValue)) {
5355
this._throwInvalidResponse();
5456
}
5557

test/Issues/RDBC_265.ts

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as mocha from "mocha";
2+
import * as assert from "assert";
3+
import { User, Company, Order } from "../Assets/Entities";
4+
import { testContext, disposeTestDocumentStore } from "../Utils/TestUtil";
5+
6+
import {
7+
RavenErrorType,
8+
IDocumentStore,
9+
SeedIdentityForCommand,
10+
GetIdentitiesOperation,
11+
} from "../../src";
12+
13+
describe("RDBC-265", function () {
14+
15+
let store: IDocumentStore;
16+
17+
beforeEach(async function () {
18+
store = await testContext.getDocumentStore();
19+
});
20+
21+
afterEach(async () =>
22+
await disposeTestDocumentStore(store));
23+
24+
it("sets identity back to 0 only when forced", async () => {
25+
{
26+
const session = store.openSession();
27+
const user = Object.assign(new User(), { lastName: "Adi" });
28+
await session.store(user, "users|");
29+
await session.saveChanges();
30+
assert.strictEqual(user.id, "users/1");
31+
}
32+
33+
let identities = await store.maintenance.send(new GetIdentitiesOperation());
34+
assert.strictEqual(identities["users|"], 1);
35+
36+
let command = new SeedIdentityForCommand("users", 0);
37+
await store.getRequestExecutor().execute(command);
38+
39+
identities = await store.maintenance.send(new GetIdentitiesOperation());
40+
assert.strictEqual(identities["users|"], 1);
41+
42+
command = new SeedIdentityForCommand("users", 0, true);
43+
await store.getRequestExecutor().execute(command);
44+
45+
identities = await store.maintenance.send(new GetIdentitiesOperation());
46+
assert.strictEqual(identities["users|"], 0);
47+
48+
// the below won't work however
49+
// due to https://github.com/ravendb/ravendb/blob/v4.1/test/SlowTests/Issues/RavenDB_9576.cs#L14
50+
// {
51+
// const session = store.openSession();
52+
// const user = Object.assign(new User(), { lastName: "Avivi" });
53+
// await session.store(user, "users|");
54+
// await session.saveChanges();
55+
// assert.strictEqual(user.id, "users/1");
56+
// }
57+
});
58+
});

test/Ported/NextAndSeedIdentitiesTest.ts

-1
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,4 @@ describe("NextAndSeedIdentitiesTest", function () {
103103
const identities = await store.maintenance.send(new GetIdentitiesOperation());
104104
assert.strictEqual(identities["users|"], 1991);
105105
});
106-
107106
});

0 commit comments

Comments
 (0)