Skip to content

Commit

Permalink
fix: empty contacts data on list
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk committed Dec 30, 2024
1 parent 2de351f commit 9557242
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ ON CONFLICT(qualified_id) DO UPDATE SET
defederated = 0,
supported_protocols = excluded.supported_protocols
WHERE -- execute the update only if any of the fields changed
User.name != excluded.name
OR User.handle != excluded.handle
OR User.email != excluded.email
OR User.phone != excluded.phone
OR User.accent_id != excluded.accent_id
OR User.team != excluded.team
OR User.preview_asset_id != excluded.preview_asset_id
OR User.complete_asset_id != excluded.complete_asset_id
OR User.user_type != excluded.user_type
OR User.bot_service != excluded.bot_service
OR User.deleted != excluded.deleted
OR User.incomplete_metadata != excluded.incomplete_metadata
OR User.expires_at != excluded.expires_at
OR User.defederated != 0
OR User.supported_protocols != excluded.supported_protocols;
User.name IS NOT excluded.name
OR User.handle IS NOT excluded.handle
OR User.email IS NOT excluded.email
OR User.phone IS NOT excluded.phone
OR User.accent_id IS NOT excluded.accent_id
OR User.team IS NOT excluded.team
OR User.preview_asset_id IS NOT excluded.preview_asset_id
OR User.complete_asset_id IS NOT excluded.complete_asset_id
OR User.user_type IS NOT excluded.user_type
OR User.bot_service IS NOT excluded.bot_service
OR User.deleted IS NOT excluded.deleted
OR User.incomplete_metadata IS NOT excluded.incomplete_metadata
OR User.expires_at IS NOT excluded.expires_at
OR User.defederated IS NOT 0
OR User.supported_protocols IS NOT excluded.supported_protocols;

selectChanges:
SELECT changes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,41 @@ class UserDAOTest : BaseDatabaseTest() {
}
}

@Test
fun givenPersistedUserWithNullValues_whenUpsertingUpdatedUserWithoutNullValues_thenItShouldBeSaved() = runTest(dispatcher) {
// Given
val userDetails = newUserDetailsEntity().copy(
name = null,
handle = null,
email = null,
phone = null,
team = null,
previewAssetId = null,
completeAssetId = null,
supportedProtocols = null,
)
val user = userDetails.toSimpleEntity()
db.userDAO.upsertUser(user)

// When
val updatedUserDetails = userDetails.copy(
name = "name",
handle = "handle",
email = "email",
phone = "phone",
team = "team",
previewAssetId = UserAssetIdEntity("preview", "domain"),
completeAssetId = UserAssetIdEntity("complete", "domain"),
supportedProtocols = setOf(SupportedProtocolEntity.MLS, SupportedProtocolEntity.PROTEUS),
)
val updatedUser = updatedUserDetails.toSimpleEntity()
db.userDAO.upsertUser(updatedUser)

// Then
val result = db.userDAO.observeUserDetailsByQualifiedID(user.id).first()
assertEquals(updatedUserDetails, result)
}

private companion object {
val USER_ENTITY_1 = newUserEntity(QualifiedIDEntity("1", "wire.com"))
val USER_ENTITY_2 = newUserEntity(QualifiedIDEntity("2", "wire.com"))
Expand Down

0 comments on commit 9557242

Please sign in to comment.