1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Fix Most Test Warnings (#4612)

* Add Collections Tests

* Update CollectionRepository Implementation

* Test Adding And Deleting Through Replace

* Format

* Fix Most Test Warnings

* Format
This commit is contained in:
Justin Baur
2024-08-15 17:14:22 -04:00
committed by GitHub
parent 2096923853
commit aa34bbb0e6
18 changed files with 50 additions and 23 deletions

View File

@ -38,6 +38,7 @@ public class OrganizationUserRepositoryTests
await organizationUserRepository.DeleteAsync(orgUser);
var newUser = await userRepository.GetByIdAsync(user.Id);
Assert.NotNull(newUser);
Assert.NotEqual(newUser.AccountRevisionDate, user.AccountRevisionDate);
}
@ -90,7 +91,9 @@ public class OrganizationUserRepositoryTests
});
var updatedUser1 = await userRepository.GetByIdAsync(user1.Id);
Assert.NotNull(updatedUser1);
var updatedUser2 = await userRepository.GetByIdAsync(user2.Id);
Assert.NotNull(updatedUser2);
Assert.NotEqual(updatedUser1.AccountRevisionDate, user1.AccountRevisionDate);
Assert.NotEqual(updatedUser2.AccountRevisionDate, user2.AccountRevisionDate);

View File

@ -165,12 +165,15 @@ public class AuthRequestRepositoryTests
// Assert that the unchanged auth request is still unchanged
var skippedAuthRequest = await authRequestRepository.GetByIdAsync(authRequestNotToBeUpdated.Id);
Assert.NotNull(skippedAuthRequest);
Assert.True(AuthRequestEquals(skippedAuthRequest, authRequestNotToBeUpdated));
// Assert that the values updated on the changed auth requests were updated, and no others
var updatedAuthRequest1 = await authRequestRepository.GetByIdAsync(authRequestToBeUpdated1.Id);
Assert.NotNull(updatedAuthRequest1);
Assert.True(AuthRequestEquals(authRequestToBeUpdated1, updatedAuthRequest1));
var updatedAuthRequest2 = await authRequestRepository.GetByIdAsync(authRequestToBeUpdated2.Id);
Assert.NotNull(updatedAuthRequest2);
Assert.True(AuthRequestEquals(authRequestToBeUpdated2, updatedAuthRequest2));
// Assert that the auth request we never created is not created by

View File

@ -39,6 +39,7 @@ public class EmergencyAccessRepositoriesTests
var updatedGrantee = await userRepository.GetByIdAsync(granteeUser.Id);
Assert.NotNull(updatedGrantee);
Assert.NotEqual(updatedGrantee.AccountRevisionDate, granteeUser.AccountRevisionDate);
}
}

View File

@ -21,9 +21,9 @@ public static class ConfigurationExtensions
public static Database[] GetDatabases(this IConfiguration config)
{
var typedConfig = config.Get<TypedConfig>();
if (typedConfig.Databases == null)
if (typedConfig?.Databases == null)
{
return Array.Empty<Database>();
return [];
}
return typedConfig.Databases.Where(d => d.Enabled).ToArray();

View File

@ -27,6 +27,7 @@ public class SendRepositoryTests
Assert.Equal(expirationDate, createdSend.ExpirationDate!.Value, LaxDateTimeComparer.Default);
var sendFromDatabase = await sendRepository.GetByIdAsync(createdSend.Id);
Assert.NotNull(sendFromDatabase);
Assert.Equal(expirationDate, sendFromDatabase.ExpirationDate!.Value, LaxDateTimeComparer.Default);
Assert.Equal(SendType.Text, sendFromDatabase.Type);
Assert.Equal(0, sendFromDatabase.AccessCount);

View File

@ -40,6 +40,7 @@ public class CipherRepositoryTests
Assert.Null(deletedCipher);
var updatedUser = await userRepository.GetByIdAsync(user.Id);
Assert.NotNull(updatedUser);
Assert.NotEqual(updatedUser.AccountRevisionDate, user.AccountRevisionDate);
}
@ -61,6 +62,7 @@ public class CipherRepositoryTests
});
user = await userRepository.GetByIdAsync(user.Id);
Assert.NotNull(user);
var organization = await organizationRepository.CreateAsync(new Organization
{
@ -110,6 +112,7 @@ public class CipherRepositoryTests
var updatedUser = await userRepository.GetByIdAsync(user.Id);
Assert.NotNull(updatedUser);
Assert.True(updatedUser.AccountRevisionDate - user.AccountRevisionDate > TimeSpan.Zero,
"The AccountRevisionDate is expected to be changed");
@ -135,6 +138,7 @@ public class CipherRepositoryTests
user = await userRepository.GetByIdAsync(user.Id);
Assert.NotNull(user);
// Create cipher in personal vault
var createdCipher = await cipherRepository.CreateAsync(new Cipher
@ -176,6 +180,7 @@ public class CipherRepositoryTests
var updatedCipher = await cipherRepository.GetByIdAsync(createdCipher.Id);
Assert.NotNull(updatedCipher);
Assert.Null(updatedCipher.UserId);
Assert.Equal(organization.Id, updatedCipher.OrganizationId);
Assert.NotNull(updatedCipher.Folders);