From 217483d3952c3efa5f35ccec29d6217ae1d5935b Mon Sep 17 00:00:00 2001 From: Jason Chickneas <66284944+jchick-bentley@users.noreply.github.com> Date: Tue, 25 Jun 2024 06:30:41 -0700 Subject: [PATCH] Fix skipped test - new child element fails to be added. (#125) * bf: ADO# 1442586 - use package.json from core-common as example * run the lint:fix command * wip: fix remaining lint issues - duplicate import statements * wip: add interface ConnectorAuthenticationManagerParams to reduce constructor parameters to one * wip: update package version * wip: move dependencies ahead to 4.7.0-dev.15 * wip: npm install w --legacy-peer-deps switch * wip: install typdoc to attempt to fix error in build pipeline * wip: in spirit of test first development, remove 'skip' to produce failing test. Also fix duplicate and missing imports to remove lint errors * wip: add script test:larger-source-set * bf: handle mixed bag of children with and without ids * wip: update version and changelog * wip: remove npm install switch inadvertently reintroduced by branching and merging --- .vscode/launch.json | 13 +++++++++ CHANGELOG.md | 4 +++ package-lock.json | 42 ++++++++++++++++++++++++++++ package.json | 3 +- src/Synchronizer.ts | 4 +++ test/standalone/Synchronizer.test.ts | 12 ++++---- test/standalone/toys.ts | 6 ++++ 7 files changed, 76 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a451ff5..b1b6d24 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,6 +6,7 @@ "configurations": [ + { "name": "Documentation", "request": "launch", @@ -83,6 +84,18 @@ "test:integration" ] }, + { + "name": "iTwinConnectorFwk Tests (larger-source-set)", + "cwd": "${workspaceFolder}", + "type": "node", + "request": "launch", + "runtimeExecutable": "npm", + "runtimeArgs": [ + "run", + "test:larger-source-set" + ] + }, + { "name": "pretest", "cwd": "${workspaceFolder}", diff --git a/CHANGELOG.md b/CHANGELOG.md index 0185018..552bdd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log - @itwin/connector-framework +## 2.2.2 + +- fixed bug in synchronizer for updating mixed bag of new and changed child elements. New element(s) would be skipped. + ## 2.2.0-dev.1 - move access token handling to synchronizer diff --git a/package-lock.json b/package-lock.json index 3acec20..fafd946 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1671,6 +1671,20 @@ "@itwin/core-bentley": "^3.3.0 || ^4.0.0" } }, + "node_modules/@itwin/node-cli-authorization/node_modules/@itwin/core-common": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/@itwin/core-common/-/core-common-4.6.1.tgz", + "integrity": "sha512-SnnikTh7Rf1v4W8+uNBxMYQhssjMtLhWlimr7ura7IQGJkD/SyqaBGVBPnUAI/e6+PI83MdKs9LmaCRBhKH2GQ==", + "dev": true, + "dependencies": { + "flatbuffers": "~1.12.0", + "js-base64": "^3.6.1" + }, + "peerDependencies": { + "@itwin/core-bentley": "^4.6.1", + "@itwin/core-geometry": "^4.6.1" + } + }, "node_modules/@itwin/object-storage-azure": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/@itwin/object-storage-azure/-/object-storage-azure-2.2.2.tgz", @@ -1742,6 +1756,20 @@ "@itwin/core-bentley": "^3.3.0 || ^4.0.0" } }, + "node_modules/@itwin/oidc-signin-tool/node_modules/@itwin/core-common": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/@itwin/core-common/-/core-common-4.6.1.tgz", + "integrity": "sha512-SnnikTh7Rf1v4W8+uNBxMYQhssjMtLhWlimr7ura7IQGJkD/SyqaBGVBPnUAI/e6+PI83MdKs9LmaCRBhKH2GQ==", + "dev": true, + "dependencies": { + "flatbuffers": "~1.12.0", + "js-base64": "^3.6.1" + }, + "peerDependencies": { + "@itwin/core-bentley": "^4.6.1", + "@itwin/core-geometry": "^4.6.1" + } + }, "node_modules/@itwin/service-authorization": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@itwin/service-authorization/-/service-authorization-1.2.1.tgz", @@ -1757,6 +1785,20 @@ "@itwin/core-bentley": "^3.3.0 || ^4.0.0" } }, + "node_modules/@itwin/service-authorization/node_modules/@itwin/core-common": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/@itwin/core-common/-/core-common-4.6.1.tgz", + "integrity": "sha512-SnnikTh7Rf1v4W8+uNBxMYQhssjMtLhWlimr7ura7IQGJkD/SyqaBGVBPnUAI/e6+PI83MdKs9LmaCRBhKH2GQ==", + "dev": true, + "dependencies": { + "flatbuffers": "~1.12.0", + "js-base64": "^3.6.1" + }, + "peerDependencies": { + "@itwin/core-bentley": "^4.6.1", + "@itwin/core-geometry": "^4.6.1" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", diff --git a/package.json b/package.json index 7eb2714..d5953f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itwin/connector-framework", - "version": "2.2.1", + "version": "2.2.2", "description": "iTwin Connector Framework", "main": "lib/src/connector-framework.js", "typings": "lib/src/connector-framework.d.ts", @@ -28,6 +28,7 @@ "test:filebased": "npm run build && nyc mocha --grep file-based", "test:trimming": "npm run build && nyc mocha --grep trimming", "test:unmap": "npm run build && nyc mocha --grep unmap", + "test:larger-source-set":"npm run build && nyc mocha --grep larger-source-set", "test:connector": "node lib/test/TestConnector/Main.js test/assets/TestArgs.json", "documentation": "cross-env RUSHSTACK_FILE_ERROR_BASE_FOLDER=$npm_config_local_prefix betools docs --source=./src --out=./documentation --json=./documentation/file.json --tsIndexFile=./connector-framework.ts --onlyJson" }, diff --git a/src/Synchronizer.ts b/src/Synchronizer.ts index 2a61b43..3d39776 100644 --- a/src/Synchronizer.ts +++ b/src/Synchronizer.ts @@ -789,6 +789,10 @@ export class Synchronizer { if (stat !== IModelStatus.Success) { return stat; } + } else if (childRes.itemState === ItemState.New) { + const stat = this.insertResultsIntoIModel(childRes, parentAspectProps); + if (stat !== IModelStatus.Success) + return stat; } } return IModelStatus.Success; diff --git a/test/standalone/Synchronizer.test.ts b/test/standalone/Synchronizer.test.ts index de215ff..5e5a002 100644 --- a/test/standalone/Synchronizer.test.ts +++ b/test/standalone/Synchronizer.test.ts @@ -3,18 +3,16 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import type { ExternalSourceAspectProps, RepositoryLinkProps } from "@itwin/core-common"; -import { Code, IModelError, IModelStatus } from "@itwin/core-common"; -import type { Subject } from "@itwin/core-backend"; -import { DefinitionGroup, ExternalSourceAspect, RepositoryLink, SnapshotDb } from "@itwin/core-backend"; +import { Code, ExternalSourceAspectProps, IModelError, IModelStatus, RepositoryLinkProps } from "@itwin/core-common"; +import { DefinitionGroup, ExternalSourceAspect, RepositoryLink, SnapshotDb, Subject } from "@itwin/core-backend"; import { assert } from "chai"; import { join } from "path"; import * as fs from "fs"; import * as utils from "../ConnectorTestUtils"; import { KnownTestLocations } from "../KnownTestLocations"; -import type { SourceItem } from "../../src/Synchronizer"; -import { ItemState, Synchronizer } from "../../src/Synchronizer"; +import { ItemState, SourceItem, Synchronizer } from "../../src/Synchronizer"; import { berryGroups } from "./toys"; +import {after, before} from "mocha"; describe("synchronizer #standalone", () => { const name = "my-fruits"; @@ -300,7 +298,7 @@ describe("synchronizer #standalone", () => { // TODO: This one fails, skipping so that it passes CI. Need to fix, it's a bug in the // synchronizer! // vvvv - it.skip("update modified root element with children, larger source set", () => { + it("update modified root element with children, larger-source-set", () => { const synchronizer = new Synchronizer(imodel, false); const { model, berryTree, berryTreeMeta } = berryGroups(synchronizer); diff --git a/test/standalone/toys.ts b/test/standalone/toys.ts index 184edb1..f9bcbf5 100644 --- a/test/standalone/toys.ts +++ b/test/standalone/toys.ts @@ -81,6 +81,12 @@ interface BerryGroups { berryTreeMeta: SourceItem; } +/** + * Creates and returns a set of berry groups for synchronization. + * + * @param sync - The synchronizer used for synchronization. + * @returns The berry groups for synchronization. + */ export function berryGroups(sync: Synchronizer): BerryGroups { // o - subject // |