-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: refactor JsonParser unit tests and type handling enhancements #2801
test: refactor JsonParser unit tests and type handling enhancements #2801
Conversation
♻️ PR Preview 25e0248 has been successfully destroyed since this PR has been closed. 🤖 By surge-preview |
♻️ PR Preview 25e0248 has been successfully destroyed since this PR has been closed. 🤖 By surge-preview |
@@ -82,11 +82,14 @@ describe('parse bpmn as json for default sequence flow', () => { | |||
}); | |||
|
|||
it(`should NOT convert, when an sequence flow (defined as default) is an attribute of 'process' and attached to a flow node where is NOT possible in BPMN Semantic`, () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: I kept this test; however, given TypeScript's restriction that prevents accessing the default
property on an object if it's not defined in the type, I'm not sure it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember that the BpmnJsonModel instance is created from an XML source in real live and no types check is done at runtime. So, at runtime, we can actually have to deal with such data.
4fc7de9
to
dd10083
Compare
dd10083
to
329e1cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. This is now much more readable and types checks are better enforced 🏅
I suggest to update some comments, otherwise, some valuable information may be missed and wrong conclusions would be included IMHO.
const defaultFlow = bpmnElement.default; | ||
if (ShapeUtil.isWithDefaultSequenceFlow(kind) && defaultFlow) { | ||
this.defaultSequenceFlowIds.push(defaultFlow); | ||
if ('default' in bpmnElement && ShapeUtil.isWithDefaultSequenceFlow(kind)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Nice!
test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts
Outdated
Show resolved
Hide resolved
test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.conditional.test.ts
Outdated
Show resolved
Hide resolved
@@ -82,11 +82,14 @@ describe('parse bpmn as json for default sequence flow', () => { | |||
}); | |||
|
|||
it(`should NOT convert, when an sequence flow (defined as default) is an attribute of 'process' and attached to a flow node where is NOT possible in BPMN Semantic`, () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember that the BpmnJsonModel instance is created from an XML source in real live and no types check is done at runtime. So, at runtime, we can actually have to deal with such data.
definitions: { | ||
targetNamespace: '', | ||
process: { | ||
id: 'Process_1', | ||
// To enforce the type and test a case who never should happen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: see my previous comment, this cannot happen if the BpmnJsonModel was always created via some code. However, the actual data are generated from the BPMN source and so, such this use case can happen.
…onParser in the unit tests
…onParser in the unit tests for markers
329e1cf
to
3b3438d
Compare
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This pull request makes three improvements to
JsonParser
and its associated unit tests:Enforce the
BpmnJsonModel
type for the JsonParser dataset in the unit tests: This is a first step in addressing issue [BUG] Extra parsing oflane
elements which are not in the BPMN spec #2188.This enforcement ensures that the JSON passed to the parser adheres to the required format.
ℹ️ It's worth noting that I have observed cases where TypeScript failed to detect incorrect JSON formats when the type was not explicitly set.
Simplified JSON data initialization for
JsonParser
unit tests: This makes our test code more readable and easier to maintain.Detection of the TypeScript-based
default
property ofTProcess
in theProcessConverter
.These improvements enhance code reliability, readability and accuracy.