Skip to content

Commit 3ada529

Browse files
authored
Adding tests for pg nested filtering (#1149)
## Why make this change? - This is just to validate that the nested filtering implementation works for pg. @Aniruddh25 implemented the actual feature. ## What is this change? - Adding skipped nested filtering tests for pg ## How was this tested? - [x] Integration Tests ## Sample Request(s) N/A
1 parent 6ac10dd commit 3ada529

File tree

4 files changed

+384
-250
lines changed

4 files changed

+384
-250
lines changed

ConfigGenerators/configGenerator.sh

100644100755
File mode changed.

src/Service.Tests/SqlTests/GraphQLFilterTests/GraphQLFilterTestBase.cs

+255
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,265 @@ public async Task TestPassingVariablesToAndField()
727727
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
728728
}
729729

730+
/// <summary>
731+
/// Test Nested Filter for Many-One relationship.
732+
/// </summary>
733+
[TestMethod]
734+
public async Task TestNestedFilterManyOne(string existsPredicate)
735+
{
736+
string graphQLQueryName = "comics";
737+
// Gets all the comics that have their series name = 'Foundation'
738+
string gqlQuery = @"{
739+
comics (" + QueryBuilder.FILTER_FIELD_NAME + ": {" +
740+
@"myseries: { name: { eq: ""Foundation"" }}})
741+
{
742+
items {
743+
id
744+
title
745+
}
746+
}
747+
}";
748+
749+
string dbQuery = MakeQueryOn(
750+
table: "comics",
751+
queriedColumns: new List<string> { "id", "title" },
752+
existsPredicate,
753+
GetDefaultSchema());
754+
755+
JsonElement actual = await ExecuteGraphQLRequestAsync(
756+
gqlQuery,
757+
graphQLQueryName,
758+
isAuthenticated: false);
759+
string expected = await GetDatabaseResultAsync(dbQuery);
760+
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
761+
}
762+
763+
/// <summary>
764+
/// Test Nested Filter for One-Many relationship
765+
/// </summary>
766+
[TestMethod]
767+
public async Task TestNestedFilterOneMany(string existsPredicate)
768+
{
769+
string graphQLQueryName = "series";
770+
// Gets the series that have comics with categoryName containing Fairy
771+
string gqlQuery = @"{
772+
series (" + QueryBuilder.FILTER_FIELD_NAME +
773+
@": { comics: { categoryName: { contains: ""Fairy"" }}} )
774+
{
775+
items {
776+
id
777+
name
778+
}
779+
}
780+
}";
781+
782+
string dbQuery = MakeQueryOn(
783+
table: "series",
784+
queriedColumns: new List<string> { "id", "name" },
785+
existsPredicate,
786+
GetDefaultSchema());
787+
788+
JsonElement actual = await ExecuteGraphQLRequestAsync(
789+
gqlQuery,
790+
graphQLQueryName,
791+
isAuthenticated: false);
792+
string expected = await GetDatabaseResultAsync(dbQuery);
793+
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
794+
}
795+
796+
/// <summary>
797+
/// Test Nested Filter for Many-Many relationship
798+
/// </summary>
799+
[TestMethod]
800+
public async Task TestNestedFilterManyMany(string existsPredicate)
801+
{
802+
string graphQLQueryName = "books";
803+
// Gets the books that have been written by Aaron as author
804+
string gqlQuery = @"{
805+
books (" + QueryBuilder.FILTER_FIELD_NAME +
806+
@": { authors : { name: { eq: ""Aaron""}}} )
807+
{
808+
items {
809+
title
810+
}
811+
}
812+
}";
813+
814+
string dbQuery = MakeQueryOn(
815+
table: "books",
816+
queriedColumns: new List<string> { "title" },
817+
existsPredicate,
818+
GetDefaultSchema());
819+
820+
JsonElement actual = await ExecuteGraphQLRequestAsync(
821+
gqlQuery,
822+
graphQLQueryName,
823+
isAuthenticated: false);
824+
string expected = await GetDatabaseResultAsync(dbQuery);
825+
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
826+
}
827+
828+
/// <summary>
829+
/// Test a field of the nested filter is null.
830+
/// </summary>
831+
[TestMethod]
832+
public async Task TestNestedFilterFieldIsNull(string existsPredicate)
833+
{
834+
string graphQLQueryName = "stocks";
835+
// Gets stocks which have a null price.
836+
string gqlQuery = @"{
837+
stocks (" + QueryBuilder.FILTER_FIELD_NAME +
838+
@": { stocks_price: { price: { isNull: true }}} )
839+
{
840+
items {
841+
categoryName
842+
}
843+
}
844+
}";
845+
846+
string dbQuery = MakeQueryOn(
847+
table: "stocks",
848+
queriedColumns: new List<string> { "categoryName" },
849+
existsPredicate,
850+
GetDefaultSchema(),
851+
pkColumns: new List<string> { "categoryid", "pieceid" });
852+
853+
JsonElement actual = await ExecuteGraphQLRequestAsync(
854+
gqlQuery,
855+
graphQLQueryName,
856+
isAuthenticated: false);
857+
string expected = await GetDatabaseResultAsync(dbQuery);
858+
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
859+
}
860+
861+
/// <summary>
862+
/// Tests nested filter having another nested filter.
863+
/// </summary>
864+
[TestMethod]
865+
public async Task TestNestedFilterWithinNestedFilter(string existsPredicate)
866+
{
867+
string graphQLQueryName = "books";
868+
869+
// Gets all the books written by Aaron
870+
// only if the title of one of his books contains 'Awesome'.
871+
string gqlQuery = @"{
872+
books (" + QueryBuilder.FILTER_FIELD_NAME +
873+
@": { authors: {
874+
books: { title: { contains: ""Awesome"" }}
875+
name: { eq: ""Aaron"" }
876+
}} )
877+
{
878+
items {
879+
title
880+
}
881+
}
882+
}";
883+
884+
string dbQuery = MakeQueryOn(
885+
table: "books",
886+
queriedColumns: new List<string> { "title" },
887+
existsPredicate,
888+
GetDefaultSchema());
889+
890+
JsonElement actual = await ExecuteGraphQLRequestAsync(
891+
gqlQuery,
892+
graphQLQueryName,
893+
isAuthenticated: false);
894+
string expected = await GetDatabaseResultAsync(dbQuery);
895+
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
896+
}
897+
898+
/// <summary>
899+
/// Tests nested filter and an AND clause.
900+
/// </summary>
901+
[TestMethod]
902+
public async Task TestNestedFilterWithAnd(string existsPredicate)
903+
{
904+
string graphQLQueryName = "books";
905+
906+
// Gets all the books written by Aniruddh and the publisher is 'Small Town Publisher'.
907+
string gqlQuery = @"{
908+
books (" + QueryBuilder.FILTER_FIELD_NAME +
909+
@": { authors: {
910+
name: { eq: ""Aniruddh""}
911+
}
912+
and: {
913+
publishers: { name: { eq: ""Small Town Publisher"" } }
914+
}
915+
})
916+
{
917+
items {
918+
title
919+
}
920+
}
921+
}";
922+
923+
string dbQuery = MakeQueryOn(
924+
table: "books",
925+
queriedColumns: new List<string> { "title" },
926+
existsPredicate,
927+
GetDefaultSchema());
928+
929+
JsonElement actual = await ExecuteGraphQLRequestAsync(
930+
gqlQuery,
931+
graphQLQueryName,
932+
isAuthenticated: false);
933+
string expected = await GetDatabaseResultAsync(dbQuery);
934+
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
935+
}
936+
937+
/// <summary>
938+
/// Tests nested filter alongwith an OR clause.
939+
/// </summary>
940+
[TestMethod]
941+
public async Task TestNestedFilterWithOr(string existsPredicate)
942+
{
943+
string graphQLQueryName = "books";
944+
945+
// Gets all the books written by Aniruddh OR if their publisher is 'TBD Publishing One'.
946+
string gqlQuery = @"{
947+
books (" + QueryBuilder.FILTER_FIELD_NAME +
948+
@": { or: [{
949+
publishers: { name: { eq: ""TBD Publishing One"" } } }
950+
{ authors : {
951+
name: { eq: ""Aniruddh""}}}
952+
]
953+
})
954+
{
955+
items {
956+
title
957+
}
958+
}
959+
}";
960+
961+
string dbQuery = MakeQueryOn(
962+
table: "books",
963+
queriedColumns: new List<string> { "title" },
964+
existsPredicate,
965+
GetDefaultSchema());
966+
967+
JsonElement actual = await ExecuteGraphQLRequestAsync(
968+
gqlQuery,
969+
graphQLQueryName,
970+
isAuthenticated: false);
971+
string expected = await GetDatabaseResultAsync(dbQuery);
972+
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
973+
}
974+
730975
#endregion
731976

732977
protected abstract string GetDefaultSchema();
733978

979+
/// <summary>
980+
/// Formats the default schema so that it can be
981+
/// placed right before the identity that it is qualifying
982+
/// </summary>
983+
protected string GetPreIndentDefaultSchema()
984+
{
985+
string defaultSchema = GetDefaultSchema();
986+
return string.IsNullOrEmpty(defaultSchema) ? string.Empty : defaultSchema + ".";
987+
}
988+
734989
/// <remarks>
735990
/// This function does not escape special characters from column names so those might lead to errors
736991
/// </remarks>

0 commit comments

Comments
 (0)