Skip to content

Commit

Permalink
fix: check updated and created fields before assignment (#1895)
Browse files Browse the repository at this point in the history
Closes #1893
  • Loading branch information
roaminggypsy authored Nov 4, 2024
1 parent a0eab94 commit 3439410
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,18 @@ private fun ListMeasurementsRequest.toListMeasurementsPageToken(): ListMeasureme

this.externalMeasurementConsumerId = externalMeasurementConsumerId
states += measurementStatesList
updatedBefore = source.filter.updatedBefore
updatedAfter = source.filter.updatedAfter
createdBefore = source.filter.createdBefore
createdAfter = source.filter.createdAfter
if (source.filter.hasUpdatedBefore()) {
updatedBefore = source.filter.updatedBefore
}
if (source.filter.hasUpdatedAfter()) {
updatedAfter = source.filter.updatedAfter
}
if (source.filter.hasCreatedBefore()) {
createdBefore = source.filter.createdBefore
}
if (source.filter.hasCreatedAfter()) {
createdAfter = source.filter.createdAfter
}
}
}
}
Expand All @@ -829,10 +837,18 @@ private fun ListMeasurementsPageToken.toStreamMeasurementsRequest(): StreamMeasu
filter = filter {
externalMeasurementConsumerId = source.externalMeasurementConsumerId
states += source.statesList.map { it.toInternalState() }.flatten()
createdAfter = source.createdAfter
createdBefore = source.createdBefore
updatedBefore = source.updatedBefore
updatedAfter = source.updatedAfter
if (source.hasUpdatedBefore()) {
updatedBefore = source.updatedBefore
}
if (source.hasUpdatedAfter()) {
updatedAfter = source.updatedAfter
}
if (source.hasCreatedBefore()) {
createdBefore = source.createdBefore
}
if (source.hasCreatedAfter()) {
createdAfter = source.createdAfter
}
if (source.hasLastMeasurement()) {
after =
StreamMeasurementsRequestKt.FilterKt.after {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,40 @@ class MeasurementsServiceTest {
)
}

@Test
fun `listMeasurements with no filters returns response`() {
val request = listMeasurementsRequest { parent = MEASUREMENT_CONSUMER_NAME }

val result =
withMeasurementConsumerPrincipal(MEASUREMENT_CONSUMER_NAME) {
runBlocking { service.listMeasurements(request) }
}

val expected = listMeasurementsResponse {
measurements += MEASUREMENT.copy { name = MEASUREMENT_NAME }
measurements += MEASUREMENT.copy { name = MEASUREMENT_NAME_2 }
measurements += MEASUREMENT.copy { name = MEASUREMENT_NAME_3 }
}

val streamMeasurementsRequest: StreamMeasurementsRequest = captureFirst {
verify(internalMeasurementsMock).streamMeasurements(capture())
}

assertThat(streamMeasurementsRequest)
.ignoringRepeatedFieldOrder()
.isEqualTo(
streamMeasurementsRequest {
limit = DEFAULT_LIMIT + 1
filter =
StreamMeasurementsRequestKt.filter {
externalMeasurementConsumerId = EXTERNAL_MEASUREMENT_CONSUMER_ID
}
}
)

assertThat(result).ignoringRepeatedFieldOrder().isEqualTo(expected)
}

@Test
fun `listMeasurements throws PERMISSION_DENIED when mc caller doesn't match`() {
val request = listMeasurementsRequest { parent = MEASUREMENT_CONSUMER_NAME }
Expand Down

0 comments on commit 3439410

Please sign in to comment.