Skip to content

[PM-3626] Add Collections & Organizations Tests#68

Open
lizard-boy wants to merge 11 commits into
mainfrom
platform/pm-3626/write-collections-tests
Open

[PM-3626] Add Collections & Organizations Tests#68
lizard-boy wants to merge 11 commits into
mainfrom
platform/pm-3626/write-collections-tests

Conversation

@lizard-boy

@lizard-boy lizard-boy commented Oct 19, 2024

Copy link
Copy Markdown

Type of change

- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Add tests to confirm the exact same behavior across databases.

Code changes

  • test/Infrastructure.EFIntegration.Test/Repositories/OrganizationRepositoryTests.cs: Delete tests that have been moved
  • test/Infrastructure.IntegrationTest/Repositories/CollectionRepositoryTests.cs: Totally new collection repository tests that verify that we are retrieving the same collection permissions across DB's.
  • test/Infrastructure.IntegrationTest/Repositories/OrganizationRepositoryTests.cs: New and migrated tests for various IOrganizationRepository things.
  • test/Infrastructure.IntegrationTest/restore.sh: Add helper script for instantiating all databases into a seperate database from what you normally use so that you can blow it up and start over a bit easier.
  • test/Infrastructure.IntegrationTest/ServiceProviderExtensions.cs: Various helpers that will help in writing tests quicker.

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

Greptile Summary

This pull request adds and updates tests for collections and organizations to ensure consistent behavior across different databases. Key changes include:

  • Added new integration tests in test/Infrastructure.IntegrationTest/Repositories/ for CollectionCipher, Collection, Device, Group, Installation, Organization, Policy, and TaxRate repositories
  • Removed redundant tests from test/Infrastructure.EFIntegration.Test/Repositories/ directory
  • Introduced ServiceProviderExtensions.cs with utility methods for creating test data
  • Added restore.sh script to set up test databases for different providers
  • Refactored and optimized database queries in CollectionCipherRepository.cs and GroupRepository.cs

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Copy link
Copy Markdown

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());

Copy link
Copy Markdown

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()

Comment on lines +104 to +105
// 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.

Copy link
Copy Markdown

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);

Copy link
Copy Markdown

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

Comment on lines +60 to +71
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;
}

Copy link
Copy Markdown

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

Comment on lines +73 to +75
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);

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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.

Comment on lines +11 to +16
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/"
}

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants