|
| 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