Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ConfigGenerators/MsSqlCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add Notebook --config "dab-config.MsSql.json" --source "notebooks" --permissions
add Journal --config "dab-config.MsSql.json" --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete"
add ArtOfWar --config "dab-config.MsSql.json" --source "aow" --rest true --permissions "anonymous:*"
add series --config "dab-config.MsSql.json" --source "series" --permissions "anonymous:*"
add Sales --config "dab-config.MsSql.json" --source "sales" --permissions "anonymous:*" --rest true --graphql true
add GetBooks --config "dab-config.MsSql.json" --source "get_books" --source.type "stored-procedure" --permissions "anonymous:read" --rest true --graphql false
add GetBook --config "dab-config.MsSql.json" --source "get_book_by_id" --source.type "stored-procedure" --permissions "anonymous:read" --rest true --graphql false
update Publisher --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many
Expand Down Expand Up @@ -107,3 +108,4 @@ update Journal --config "dab-config.MsSql.json" --permissions "authorizationHand
update ArtOfWar --config "dab-config.MsSql.json" --permissions "authenticated:*" --map "DetailAssessmentAndPlanning:始計,WagingWar:作戰,StrategicAttack:謀攻,NoteNum:┬─┬ノ( º _ ºノ)"
update GetBook --config "dab-config.MsSql.json" --permissions "authenticated:*"
update GetBooks --config "dab-config.MsSql.json" --permissions "authenticated:*"
update Sales --config "dab-config.MsSql.json" --permissions "authenticated:*"
2 changes: 2 additions & 0 deletions ConfigGenerators/MySqlCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add Notebook --config "dab-config.MySql.json" --source "notebooks" --permissions
add Journal --config "dab-config.MySql.json" --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete"
add ArtOfWar --config "dab-config.MySql.json" --source "aow" --rest true --permissions "anonymous:*"
add series --config "dab-config.MySql.json" --source "series" --permissions "anonymous:*"
add Sales --config "dab-config.MySql.json" --source "sales" --permissions "anonymous:*" --rest true --graphql true
update Publisher --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many
update Publisher --config "dab-config.MySql.json" --permissions "policy_tester_01:create,delete"
update Publisher --config "dab-config.MySql.json" --permissions "policy_tester_01:update" --fields.include "*"
Expand Down Expand Up @@ -103,3 +104,4 @@ update Journal --config "dab-config.MySql.json" --permissions "policy_tester_upd
update Journal --config "dab-config.MySql.json" --permissions "policy_tester_update_noread:delete" --fields.include "*" --policy-database "@item.id eq 1"
update Journal --config "dab-config.MySql.json" --permissions "authorizationHandlerTester:read"
update ArtOfWar --config "dab-config.MySql.json" --permissions "authenticated:*" --map "DetailAssessmentAndPlanning:始計,WagingWar:作戰,StrategicAttack:謀攻,NoteNum:┬─┬ノ( º _ ºノ)"
update Sales --config "dab-config.MySql.json" --permissions "authenticated:*"
2 changes: 2 additions & 0 deletions ConfigGenerators/PostgreSqlCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add Notebook --config "dab-config.PostgreSql.json" --source "notebooks" --permis
add Journal --config "dab-config.PostgreSql.json" --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete"
add ArtOfWar --config "dab-config.PostgreSql.json" --source "aow" --rest true --permissions "anonymous:*"
add series --config "dab-config.PostgreSql.json" --source "series" --permissions "anonymous:*"
add Sales --config "dab-config.PostgreSql.json" --source "sales" --permissions "anonymous:*" --rest true --graphql true
update Publisher --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many
update Publisher --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:create,delete"
update Publisher --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:update" --fields.include "*"
Expand Down Expand Up @@ -100,3 +101,4 @@ update Journal --config "dab-config.PostgreSql.json" --permissions "policy_teste
update Journal --config "dab-config.PostgreSql.json" --permissions "policy_tester_update_noread:delete" --fields.include "*" --policy-database "@item.id eq 1"
update Journal --config "dab-config.PostgreSql.json" --permissions "authorizationHandlerTester:read"
update ArtOfWar --config "dab-config.PostgreSql.json" --permissions "authenticated:*" --map "DetailAssessmentAndPlanning:始計,WagingWar:作戰,StrategicAttack:謀攻,NoteNum:┬─┬ノ( º _ ºノ)"
update Sales --config "dab-config.PostgreSql.json" --permissions "authenticated:*"
23 changes: 23 additions & 0 deletions ConfigGenerators/dab-config.sql.reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,29 @@
"actions": [ "*" ]
}
]
},
"Sales": {
"source": {
"type": "table",
"object": "sales",
"key-fields": []
},
"rest": true,
"graphql": true,
"permissions": [
{
"role": "anonymous",
"actions": [
"*"
]
},
{
"role": "authenticated",
"actions": [
"*"
]
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ public async Task InsertMutationWithVariables(string dbQuery)
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
}

/// <summary>
/// <code>Do: </code> Inserts new sale item into sales table that automatically calculates the total price
/// based on subtotal and tax.
/// <code>Check: Calculated column is persisted successfully with correct calculated result. </code>
/// </summary>
public async Task InsertMutationForComputedColumns(string dbQuery)
{
string graphQLMutationName = "createSales";
string graphQLMutation = @"
mutation{
createSales(item: {item_name: ""headphones"", subtotal: 195.00, tax: 10.33}) {
id
item_name
subtotal
tax
total
}
}
";

JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLMutation, graphQLMutationName, isAuthenticated: true);
string expected = await GetDatabaseResultAsync(dbQuery);

SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
}

/// <summary>
/// <code>Do: </code> Inserts new review with default content for a Review and return its id and content
/// <code>Check: </code> If book with the given id is present in the database then
Expand Down Expand Up @@ -129,6 +155,31 @@ public async Task UpdateMutation(string dbQuery)
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
}

/// <summary>
/// <code>Do: </code>Update Sales in database and return its updated fields
/// <code>Check: The calculated column has successfully been updated after updating the other fields </code>
/// </summary>
public async Task UpdateMutationForComputedColumns(string dbQuery)
{
string graphQLMutationName = "updateSales";
string graphQLMutation = @"
mutation{
updateSales(id: 2, item: {item_name: ""phone"", subtotal: 495.00, tax: 30.33}) {
id
item_name
subtotal
tax
total
}
}
";

JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLMutation, graphQLMutationName, isAuthenticated: true);
string expected = await GetDatabaseResultAsync(dbQuery);

SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.ToString());
}

/// <summary>
/// <code>Do: </code>Delete book by id
/// <code>Check: </code>if the mutation returned result is as expected and if book by that id has been deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ ORDER BY [id] asc
await InsertMutationWithVariables(msSqlQuery);
}

/// <summary>
/// <code>Do: </code> Inserts new sale item into sales table that automatically calculates the total price
/// based on subtotal and tax.
/// <code>Check: Calculated column is persisted successfully with correct calculated result. </code>
/// </summary>
[TestMethod]
public async Task InsertMutationForComputedColumns()
{
string msSqlQuery = @"
SELECT TOP 1 [table0].[id] AS [id],
[table0].[item_name] AS [item_name],
[table0].[subtotal] AS [subtotal],
[table0].[tax] AS [tax],
[table0].[total] AS [total]
FROM [sales] AS [table0]
WHERE [table0].[id] = 5001
AND [table0].[item_name] = 'headphones'
AND [table0].[subtotal] = 195.00
AND [table0].[tax] = 10.33
AND [table0].[total] = 205.33
ORDER BY [id] asc
FOR JSON PATH,
INCLUDE_NULL_VALUES,
WITHOUT_ARRAY_WRAPPER
";

await InsertMutationForComputedColumns(msSqlQuery);
}

/// <summary>
/// <code>Do: </code> Inserts new review with default content for a Review and return its id and content
/// <code>Check: </code> If book with the given id is present in the database then
Expand Down Expand Up @@ -146,6 +175,34 @@ ORDER BY [books].[id] asc
await UpdateMutation(msSqlQuery);
}

/// <summary>
/// <code>Do: </code>Update Sales in database and return its updated fields
/// <code>Check: The calculated column has successfully been updated after updating the other fields </code>
/// </summary>
[TestMethod]
public async Task UpdateMutationForComputedColumns()
{
string msSqlQuery = @"
SELECT TOP 1 [table0].[id] AS [id],
[table0].[item_name] AS [item_name],
[table0].[subtotal] AS [subtotal],
[table0].[tax] AS [tax],
[table0].[total] AS [total]
FROM [sales] AS [table0]
WHERE [table0].[id] = 2
AND [table0].[item_name] = 'phone'
AND [table0].[subtotal] = 495.00
AND [table0].[tax] = 30.33
AND [table0].[total] = 525.33
ORDER BY [id] asc
FOR JSON PATH,
INCLUDE_NULL_VALUES,
WITHOUT_ARRAY_WRAPPER
";

await UpdateMutationForComputedColumns(msSqlQuery);
}

/// <summary>
/// <code>Do: </code>Delete book by id
/// <code>Check: </code>if the mutation returned result is as expected and if book by that id has been deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ ORDER BY `id` asc LIMIT 1
await InsertMutation(mySqlQuery);
}

/// <summary>
/// <code>Do: </code> Inserts a new sale item into the sales table that automatically calculates the total price
/// based on subtotal and tax.
/// <code>Check: </code> Calculated column is persisted successfully with correct calculated result.
/// </summary>
[TestMethod]
public async Task InsertMutationForComputedColumns()
{
string mySqlQuery = @"
SELECT JSON_OBJECT(
'id', `subq`.`id`, 'item_name', `subq`.`item_name`,
'subtotal', `subq`.`subtotal`, 'tax', `subq`.`tax`,
'total', `subq`.`total`
) AS `data`
FROM (
SELECT `table0`.`id` AS `id`,
`table0`.`item_name` AS `item_name`,
`table0`.`subtotal` AS `subtotal`,
`table0`.`tax` AS `tax`,
`table0`.`total` AS `total`
FROM `sales` AS `table0`
WHERE `id` = 5001
AND `item_name` = 'headphones'
AND `subtotal` = 195.00
AND `tax` = 10.33
AND `total` = 205.33
ORDER BY `id` asc LIMIT 1
) AS `subq`
";

await InsertMutationForComputedColumns(mySqlQuery);
}

/// <summary>
/// <code>Do: </code> Inserts new book using variables to set its title and publisher_id
/// <code>Check: </code> If book with the expected values of the new book is present in the database and
Expand Down Expand Up @@ -149,6 +182,36 @@ ORDER BY `table0`.`id` asc LIMIT 1
await UpdateMutation(mySqlQuery);
}

/// <summary>
/// <code>Do: </code>Update Sales in database and return its updated fields
/// <code>Check: The calculated column has successfully been updated after updating the other fields </code>
/// </summary>
[TestMethod]
// IGNORE FOR NOW, SEE: Issue #1001
[Ignore]
public async Task UpdateMutationForComputedColumns()
{
string mySqlQuery = @"
SELECT JSON_OBJECT(
'id', `subq2`.`id`, 'item_name', `subq2`.`item_name`,
'subtotal', `subq2`.`subtotal`, 'tax', `subq2`.`tax`,
'total', `subq2`.`total`
) AS `data`
FROM (
SELECT `table0`.`id` AS `id`,
`table0`.`item_name` AS `item_name`,
`table0`.`subtotal` AS `subtotal`,
`table0`.`tax` AS `tax`,
`table0`.`total` AS `total`
FROM `sales` AS `table0`
WHERE `id` = 2
ORDER BY `id` asc LIMIT 1
) AS `subq2`
";

await UpdateMutationForComputedColumns(mySqlQuery);
}

/// <summary>
/// <code>Do: </code>Delete book by id
/// <code>Check: </code>if the mutation returned result is as expected and if book by that id has been deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,35 @@ ORDER BY id asc
await InsertMutation(postgresQuery);
}

/// <summary>
/// <code>Do: </code> Inserts new sale item into sales table that automatically calculates the total price
/// based on subtotal and tax.
/// <code>Check: Calculated column is persisted successfully with correct calculated result. </code>
/// </summary>
[TestMethod]
public async Task InsertMutationForComputedColumns()
{
string postgresQuery = @"
SELECT to_jsonb(subq) AS DATA
FROM
(SELECT table0.id AS id,
table0.item_name AS item_name,
table0.subtotal AS subtotal,
table0.tax AS tax,
table0.total AS total
FROM sales AS table0
WHERE id = 5001
AND item_name = 'headphones'
AND subtotal = 195.00
AND tax = 10.33
AND total = 205.33
ORDER BY id asc
LIMIT 1) AS subq
";

await InsertMutationForComputedColumns(postgresQuery);
}

/// <summary>
/// <code>Do: </code> Inserts new book using variables to set its title and publisher_id
/// <code>Check: </code> If book with the expected values of the new book is present in the database and
Expand Down Expand Up @@ -152,6 +181,34 @@ ORDER BY id asc
await UpdateMutation(postgresQuery);
}

/// <summary>
/// <code>Do: </code>Update Sales in database and return its updated fields
/// <code>Check: The calculated column has successfully been updated after updating the other fields </code>
/// </summary>
[TestMethod]
public async Task UpdateMutationForComputedColumns()
{
string postgresQuery = @"
SELECT to_jsonb(subq) AS DATA
FROM
(SELECT table0.id AS id,
table0.item_name AS item_name,
table0.subtotal AS subtotal,
table0.tax AS tax,
table0.total AS total
FROM sales AS table0
WHERE id = 2
AND item_name = 'phone'
AND subtotal = 495.00
AND tax = 30.33
AND total = 525.33
ORDER BY id asc
LIMIT 1) AS subq
";

await UpdateMutationForComputedColumns(postgresQuery);
}

/// <summary>
/// <code>Do: </code>Delete book by id
/// <code>Check: </code>if the mutation returned result is as expected and if book by that id has been deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ public async Task MultipleResultQueryWithVariables(string dbQuery)
SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("items").ToString());
}

/// <summary>
/// Gets array of results for querying a table containing computed columns.
/// </summary>
/// <returns>rows from sales table</returns>
public async Task MultipleResultQueryContainingComputedColumns(string dbQuery)
{
string graphQLQueryName = "sales";
string graphQLQuery = @"{
sales(first: 10) {
items {
id
item_name
subtotal
tax
total
}
}
}";

JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQuery, graphQLQueryName, isAuthenticated: false);
string expected = await GetDatabaseResultAsync(dbQuery);

SqlTestHelper.PerformTestEqualJsonStrings(expected, actual.GetProperty("items").ToString());
}

/// <summary>
/// Gets array of results for querying more than one item.
/// </summary>
Expand Down
Loading