[PM-3626] Add Collections & Organizations Tests#68
Conversation
- Add Helper Script for creating seperated databases for tests
- Add Tests - Prefer Method Syntax
There was a problem hiding this comment.
27 file(s) reviewed, 24 comment(s)
Edit PR Review Bot Settings | Greptile
There was a problem hiding this comment.
logic: The GetHashCode method was not properly implemented. It used the base GetHashCode, which doesn't consider the specific properties of the Collection object. If this class is still needed elsewhere, consider reimplementing it with a proper GetHashCode method.
There was a problem hiding this comment.
logic: The GetHashCode method was incorrectly implemented, returning the base GetHashCode instead of a hash based on the Installation properties. If this class is needed elsewhere, it should be reimplemented with a correct GetHashCode method.
| @@ -148,42 +81,4 @@ public async void GetManyAbilitiesAsync_Works(SqlRepo.OrganizationRepository sql | |||
| list.Concat(await sqlOrganizationRepo.GetManyAbilitiesAsync()); | |||
There was a problem hiding this comment.
logic: Same issue with list.Concat() here. Use list.AddRange()
| // The user will be apart of two groups, one that gives them little access to the collection | ||
| // and one that gives them fully access, via our rules, they should be given the full rights. |
There was a problem hiding this comment.
syntax: Typo: 'apart' should be 'a part'
| var group2 = groupsAndCollections.FirstOrDefault(t => t.Item1.ExternalId == groupExternalIds[1]); | ||
| Assert.NotNull(group2); | ||
| Assert.Single(group2!.Item2); | ||
| var group2Collection = Assert.Single(group1!.Item2); |
There was a problem hiding this comment.
logic: group2Collection is using group1 instead of group2
| public static async Task<IReadOnlyList<T>> CreateManyAsync<TService, T>(this IServiceProvider services, Func<TService, int, Task<T>> creator, int number) | ||
| where TService : class | ||
| { | ||
| var service = services.GetRequiredService<TService>(); | ||
|
|
||
| var items = new T[number]; | ||
| for (var i = 0; i < number; i++) | ||
| { | ||
| items[i] = await creator(service, i); | ||
| } | ||
| return items; | ||
| } |
There was a problem hiding this comment.
style: Consider using a more efficient approach for creating multiple entities, such as bulk insert
| public static async Task<IReadOnlyList<T>> CreateManyAsync<TService, T>(this IServiceProvider services, Func<TService, Task<T>> creator, int number) | ||
| where TService : class | ||
| => await services.CreateManyAsync(async (TService service, int _) => await creator(service), number); |
There was a problem hiding this comment.
style: This method could be simplified using LINQ
| @@ -0,0 +1,112 @@ | |||
| #!/usr/bin/env bash | |||
|
|
|||
| # DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) | |||
There was a problem hiding this comment.
style: This commented-out line seems unnecessary. Consider removing it if it's not used.
| get_db() { | ||
| # Takes | ||
| DB_NAME=$(echo "$1" | perl -nle"print $& while m{$2=\w+}g" | sed "s/$2=//g") | ||
| TEST_DB_NAME="${DB_NAME}_int_test" | ||
| echo "$1" | sed "s/$DB_NAME/$TEST_DB_NAME/" | ||
| } |
There was a problem hiding this comment.
style: The get_db function is missing a comment explaining what the second parameter ($2) represents.
|
|
||
| if [ ! -z "$SQLITE_CONN_STR" ]; then | ||
| echo "Making a test database for Sqlite: $SQLITE_CONN_STR" | ||
| # this makes the assumption it is a file which I think is likely for local dev |
There was a problem hiding this comment.
logic: This comment assumes SQLite is using a file, which may not always be true. Consider handling in-memory SQLite databases as well.
Type of change
Objective
Add tests to confirm the exact same behavior across databases.
Code changes
Before you submit
dotnet format --verify-no-changes) (required)Greptile Summary
This pull request adds and updates tests for collections and organizations to ensure consistent behavior across different databases. Key changes include:
test/Infrastructure.IntegrationTest/Repositories/for CollectionCipher, Collection, Device, Group, Installation, Organization, Policy, and TaxRate repositoriestest/Infrastructure.EFIntegration.Test/Repositories/directoryServiceProviderExtensions.cswith utility methods for creating test datarestore.shscript to set up test databases for different providersCollectionCipherRepository.csandGroupRepository.cs