@itwin/core-backend 5.5.0-dev.13 → 5.5.0-dev.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ import { Code, IModel, QueryBinder, SubCategoryAppearance } from "@itwin/core-co
7
7
  import * as chai from "chai";
8
8
  import * as chaiAsPromised from "chai-as-promised";
9
9
  import { HubWrappers, IModelTestUtils, KnownTestLocations } from "..";
10
- import { BriefcaseManager, ChangesetECAdaptor, ChannelControl, DrawingCategory, IModelHost, SqliteChangesetReader } from "../../core-backend";
10
+ import { BriefcaseManager, ChangesetECAdaptor, ChannelControl, DrawingCategory, ElementGroupsMembers, IModelHost, SqliteChangesetReader } from "../../core-backend";
11
11
  import { HubMock } from "../../internal/HubMock";
12
12
  import { StashManager } from "../../StashManager";
13
13
  import { existsSync, unlinkSync, writeFileSync } from "fs";
@@ -1186,5 +1186,85 @@ describe("rebase changes & stashing api", function () {
1186
1186
  chai.expect(b2.elements.tryGetElementProps(e3)).to.undefined; // add by rebase so should not exist either
1187
1187
  chai.expect(BriefcaseManager.containsRestorePoint(b2, BriefcaseManager.PULL_MERGE_RESTORE_POINT_NAME)).is.false;
1188
1188
  });
1189
+ it("two users insert same ElementGroupsMembers instance", async () => {
1190
+ const b1 = await testIModel.openBriefcase();
1191
+ const b2 = await testIModel.openBriefcase();
1192
+ const e1 = await testIModel.insertElement(b1);
1193
+ const e2 = await testIModel.insertElement(b1);
1194
+ const e3 = await testIModel.insertElement(b1);
1195
+ const e4 = await testIModel.insertElement(b1);
1196
+ chai.expect(e1).to.exist;
1197
+ chai.expect(e2).to.exist;
1198
+ chai.expect(e3).to.exist;
1199
+ chai.expect(e4).to.exist;
1200
+ b1.saveChanges();
1201
+ await b1.pushChanges({ description: `inserted elements` });
1202
+ await b2.pullChanges();
1203
+ const r1 = b1.relationships.insertInstance(ElementGroupsMembers.create(b1, e1, e2, 10).toJSON());
1204
+ const r2 = b1.relationships.insertInstance(ElementGroupsMembers.create(b1, e3, e4, 20).toJSON());
1205
+ chai.expect(r1).to.exist;
1206
+ chai.expect(r2).to.exist;
1207
+ b1.saveChanges();
1208
+ await b1.pushChanges({ description: `inserted relationship` });
1209
+ const r3 = b2.relationships.insertInstance(ElementGroupsMembers.create(b2, e1, e2, 10).toJSON());
1210
+ const r4 = b2.relationships.insertInstance(ElementGroupsMembers.create(b2, e3, e4, 20).toJSON());
1211
+ chai.expect(r3).to.exist;
1212
+ chai.expect(r4).to.exist;
1213
+ b2.saveChanges();
1214
+ await b2.pushChanges({ description: `inserted relationship` });
1215
+ await b2.pullChanges();
1216
+ chai.expect(b2.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r1)).to.exist;
1217
+ chai.expect(b2.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r2)).to.exist;
1218
+ chai.expect(b2.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r3)).to.be.undefined;
1219
+ chai.expect(b2.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r4)).to.be.undefined;
1220
+ chai.expect(b1.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r1)).to.exist;
1221
+ chai.expect(b1.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r2)).to.exist;
1222
+ chai.expect(b1.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r3)).to.be.undefined;
1223
+ chai.expect(b1.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r4)).to.be.undefined;
1224
+ });
1225
+ it("one user update and other delete the link table relationships", async () => {
1226
+ const b1 = await testIModel.openBriefcase();
1227
+ const b2 = await testIModel.openBriefcase();
1228
+ const e1 = await testIModel.insertElement(b1);
1229
+ const e2 = await testIModel.insertElement(b1);
1230
+ const r1 = b1.relationships.insertInstance(ElementGroupsMembers.create(b1, e1, e2, 10).toJSON());
1231
+ const r2 = b1.relationships.insertInstance(ElementGroupsMembers.create(b1, e1, e2, 20).toJSON());
1232
+ chai.expect(e1).to.exist;
1233
+ chai.expect(e2).to.exist;
1234
+ chai.expect(r1).to.exist;
1235
+ chai.expect(r2).to.exist;
1236
+ b1.saveChanges();
1237
+ await b1.pushChanges({ description: `inserted elements and relationship` });
1238
+ await b2.pullChanges();
1239
+ // intentionally change memberPriority to 10 for which there is another relationship already exists.
1240
+ chai.expect(() => b2.relationships.updateInstance({
1241
+ id: r1,
1242
+ classFullName: ElementGroupsMembers.classFullName,
1243
+ sourceId: e1,
1244
+ targetId: e2,
1245
+ memberPriority: 20
1246
+ })).to.throws("error updating relationship");
1247
+ b2.relationships.updateInstance({
1248
+ id: r1,
1249
+ classFullName: ElementGroupsMembers.classFullName,
1250
+ sourceId: e1,
1251
+ targetId: e2,
1252
+ memberPriority: 60
1253
+ });
1254
+ b1.relationships.deleteInstance({
1255
+ id: r1,
1256
+ classFullName: ElementGroupsMembers.classFullName,
1257
+ sourceId: e1,
1258
+ targetId: e2
1259
+ });
1260
+ b1.saveChanges();
1261
+ await b1.pushChanges({ description: `deleted relationship` });
1262
+ b2.saveChanges();
1263
+ await b2.pushChanges({ description: `updated relationship` });
1264
+ await b2.pullChanges();
1265
+ await b1.pullChanges();
1266
+ chai.expect(b1.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r1)).to.be.undefined;
1267
+ chai.expect(b1.relationships.tryGetInstanceProps(ElementGroupsMembers.classFullName, r2)).to.exist;
1268
+ });
1189
1269
  });
1190
1270
  //# sourceMappingURL=Rebase.test.js.map