-
Notifications
You must be signed in to change notification settings - Fork 0
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
[PM-3626] Add Collections & Organizations Tests #68
base: main
Are you sure you want to change the base?
Conversation
- Add Helper Script for creating seperated databases for tests
- Add Tests - Prefer Method Syntax
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.
27 file(s) reviewed, 24 comment(s)
Edit PR Review Bot Settings | Greptile
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.cs
with utility methods for creating test datarestore.sh
script to set up test databases for different providersCollectionCipherRepository.cs
andGroupRepository.cs