-
Notifications
You must be signed in to change notification settings - Fork 5
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
HAI-3321 Complete return values of kaivuilmoitus taydennys #919
base: dev
Are you sure you want to change the base?
HAI-3321 Complete return values of kaivuilmoitus taydennys #919
Conversation
second: Tyoalue, | ||
): String? = | ||
if (property.get(this) != property.get(second)) { | ||
"areas[$alueIndex].tyoalueet[$tyoalueIndex].${property.name}" |
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.
I think this method should just return the name of the property. The caller should handle placing the change in the proper context.
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.
I refactored to use a single fun <T : Any> T.checkChange(property: KProperty1<T, Any?>, second: T): String?
(in Utils.kt)
"areas[$index].${property.name}" | ||
} else null | ||
|
||
private fun Tyoalue.checkChange( |
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.
The same checkChange
method that's used in Hakemus could be used for all of these checkChange
methods, if the constraints on the D
type were relaxed. The method would also need to be moved to a shared location.
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.
I refactored to use a single fun <T : Any> T.checkChange(property: KProperty1<T, Any?>, second: T): String?
(in Utils.kt)
val changes = mutableListOf<String>() | ||
checkChange(alueIndex, tyoalueIndex, Tyoalue::geometry, other)?.let { changes.add(it) } | ||
return if (changes.isNotEmpty()) | ||
listOf("areas[$alueIndex].tyoalueet[$tyoalueIndex]") + changes |
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.
Instead of taking the previous indexes as parameters, it would be cleaner to take the previous path. So this method doesn't need to assume the context in which it's run. Similar to how the path
parameters are used in validations.
This would then reduce to changes + path
.
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.
Changed this as suggested.
): List<String> { | ||
val changedElementsInFirst = | ||
firstAreas.withIndex().mapNotNull { (i, tyoalue) -> | ||
tyoalue.listChanges(index, i, secondAreas.getOrNull(i)) |
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.
Since there's only one field that can be different in a tyoalue, it could be checked right here.
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.
I moved the check for Tyoalue.geometry
here.
Haittojenhallintatyyppi.entries.mapNotNull { tyyppi -> | ||
if (first[tyyppi] != second[tyyppi]) { | ||
"areas[$index].haittojenhallintasuunnitelma[${tyyppi.name}]" | ||
} else null | ||
} |
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.
I think this would be clearer if you first filtered out the changed ones and then changed the name.
Haittojenhallintatyyppi.entries.mapNotNull { tyyppi -> | |
if (first[tyyppi] != second[tyyppi]) { | |
"areas[$index].haittojenhallintasuunnitelma[${tyyppi.name}]" | |
} else null | |
} | |
Haittojenhallintatyyppi.entries | |
.filter { tyyppi -> first[tyyppi] != second[tyyppi] } | |
.map { "areas[$index].haittojenhallintasuunnitelma[${tyyppi.name}]" } |
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.
Changed as suggested.
other.haittojenhallintasuunnitelma, | ||
) | ||
) | ||
return if (changes.isNotEmpty()) changes else null |
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.
Isn't an empty list a good way to say there were no changes?
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.
Yes, it is. Changed this.
.map { it.index } | ||
val elementsInSecondButNotFirst = secondAreas.indices.drop(firstAreas.size) | ||
return (changedElementsInFirst + elementsInSecondButNotFirst).map { "areas[$it]" } | ||
firstAreas.withIndex().mapNotNull { (i, area) -> |
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.
If area.listChanges()
would return an empty list when there are no changes this could use flatMap
with no reason to flatten separately.
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.
Changed it as suggested.
assertThat(result).containsExactly("name", "startTime") | ||
} | ||
|
||
private fun commonFieldCases(): List<Arguments> = |
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.
Is there a reason to repeat these tests? Both the code and the data interfaces are shared between the two types of applications.
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.
Removed repeated tests that test the same data
fun `returns several changes when an area is added to the middle`() { | ||
val updated = | ||
@Nested | ||
inner class AreaChanges { |
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.
Since the code checking the area changes are in a different class now, maybe the test code should be for a different class as well?
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.
Created HakemusalueTest
and placed tests that test a single Hakemusalue
there. Kept those tests that test the area collection (changed the inner test class name to AreasChanges
).
val updated = | ||
base.copy( | ||
areas = | ||
listOf( | ||
ApplicationFactory.createExcavationNotificationArea( | ||
tyoalueet = | ||
listOf( | ||
ApplicationFactory.createTyoalue( | ||
geometry = GeometriaFactory.polygon() | ||
), | ||
ApplicationFactory.createTyoalue( | ||
geometry = GeometriaFactory.thirdPolygon() | ||
), | ||
ApplicationFactory.createTyoalue( | ||
geometry = GeometriaFactory.thirdPolygon() | ||
), | ||
ApplicationFactory.createTyoalue( | ||
geometry = GeometriaFactory.secondPolygon() | ||
), | ||
) | ||
) | ||
) | ||
) |
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.
The deep nesting makes these really hard to read. Some intermediary values would make these a lot more readable.
val updated = | |
base.copy( | |
areas = | |
listOf( | |
ApplicationFactory.createExcavationNotificationArea( | |
tyoalueet = | |
listOf( | |
ApplicationFactory.createTyoalue( | |
geometry = GeometriaFactory.polygon() | |
), | |
ApplicationFactory.createTyoalue( | |
geometry = GeometriaFactory.thirdPolygon() | |
), | |
ApplicationFactory.createTyoalue( | |
geometry = GeometriaFactory.thirdPolygon() | |
), | |
ApplicationFactory.createTyoalue( | |
geometry = GeometriaFactory.secondPolygon() | |
), | |
) | |
) | |
) | |
) | |
val tyoalueet = | |
listOf( | |
ApplicationFactory.createTyoalue(geometry = GeometriaFactory.polygon()), | |
ApplicationFactory.createTyoalue( | |
geometry = GeometriaFactory.thirdPolygon() | |
), | |
ApplicationFactory.createTyoalue( | |
geometry = GeometriaFactory.thirdPolygon() | |
), | |
ApplicationFactory.createTyoalue( | |
geometry = GeometriaFactory.secondPolygon() | |
), | |
) | |
val area = | |
ApplicationFactory.createExcavationNotificationArea(tyoalueet = tyoalueet) | |
val updated = base.copy(areas = listOf(area)) |
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.
Changed as suggested.
…hanges in contacts and in areas and work areas.
…ludes changes in contacts and in areas and work areas.
…his includes changes in contacts and in areas and work areas.
c02dd84
to
f4c4a9d
Compare
Quality Gate failedFailed conditions |
Description
checkChangeInYhteystieto
forKaivuilmoitusData
contactscheckChangesInAreas
- it will check changes inside areas, not just doequals
comparisonHakemusalue.listChanges
:equals
check for other thanKaivuilmoitusAlue
and field-by-field comparison forKaivuilmoitusAlue
Tyoalue.listChanges
Jira Issue: https://helsinkisolutionoffice.atlassian.net/browse/HAI-3321
Type of change
Instructions for testing
muutokset
value when the form is savedChecklist:
or other location:
Other relevant info
Please describe here if there is e.g. some requirements for this change or
other info that the tester/user needs to know.