Skip to content

Commit c706aa7

Browse files
committed
RDBC-259 use i instead of 0 when iterating over results of batch op
1 parent 2b0021b commit c706aa7

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

src/Documents/Session/Operations/BatchOperation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class BatchOperation {
4545

4646
const results = result.results;
4747
for (let i = 0; i < this._sessionCommandsCount; i++) {
48-
const batchResult = results[0];
48+
const batchResult = results[i];
4949
if (!batchResult) {
5050
throwError("InvalidArgumentException", "result");
5151
}

test/Issues/RDBC_259.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
} from "../../src";
10+
11+
describe("RDBC-259", function () {
12+
13+
let store: IDocumentStore;
14+
15+
beforeEach(async function () {
16+
testContext.customizeStore = async store => {
17+
store.conventions.findCollectionNameForObjectLiteral =
18+
e => e ? e["type"] + "s" : "@empty";
19+
};
20+
21+
store = await testContext.getDocumentStore();
22+
});
23+
24+
afterEach(async () =>
25+
await disposeTestDocumentStore(store));
26+
27+
describe("if you take part (a subobject) of the object A and put into B", function () {
28+
29+
it("it's gonna update both of them and won't mix up IDs when updating using batch op response", async () => {
30+
31+
let configId;
32+
let extensionId;
33+
34+
{
35+
const session = store.openSession();
36+
const config: any = {
37+
type: "config",
38+
properties: {
39+
A: 1,
40+
B: 2
41+
}
42+
};
43+
44+
await session.store(config);
45+
await session.saveChanges();
46+
47+
assert.strictEqual(config.id, "configs/1-A");
48+
configId = config.id;
49+
}
50+
51+
{
52+
const session = store.openSession();
53+
const config: any = await session.load(configId);
54+
55+
const customConfig = config.properties;
56+
customConfig["A"] = 2;
57+
58+
const extension: any = {
59+
type: "extension",
60+
config: customConfig
61+
};
62+
63+
assert.ok(session.advanced.hasChanged(config));
64+
65+
await session.store(extension);
66+
67+
assert.ok(session.advanced.hasChanged(extension));
68+
69+
const changes = session.advanced.whatChanged();
70+
71+
await session.saveChanges();
72+
73+
assert.strictEqual(extension.id, "extensions/1-A");
74+
assert.strictEqual(config.id, "configs/1-A");
75+
extensionId = extension.id;
76+
}
77+
78+
{
79+
const session = store.openSession();
80+
const config: any = await session.load(configId);
81+
const extension: any = await session.load(extensionId);
82+
83+
assert.strictEqual(config.id, "configs/1-A");
84+
assert.strictEqual(config.type, "config");
85+
assert.strictEqual(config.properties["A"], 2);
86+
assert.strictEqual(config.properties["B"], 2);
87+
88+
assert.strictEqual(extension.id, "extensions/1-A");
89+
assert.strictEqual(extension.type, "extension");
90+
assert.strictEqual(extension.config["A"], 2);
91+
assert.strictEqual(extension.config["B"], 2);
92+
}
93+
});
94+
95+
});
96+
97+
});

0 commit comments

Comments
 (0)