-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add preparation for row permission insert
on create row
- Loading branch information
Showing
8 changed files
with
137 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/test/scala/com/campudus/tableaux/api/permission/CreateRowWithRowPermissionsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.campudus.tableaux.api.permission | ||
|
||
import com.campudus.tableaux.database.DatabaseConnection | ||
import com.campudus.tableaux.database.model.SystemModel | ||
import com.campudus.tableaux.testtools.{RequestCreation, TableauxTestBase} | ||
import com.campudus.tableaux.testtools.RequestCreation.{Identifier, TextCol} | ||
|
||
import io.vertx.ext.unit.TestContext | ||
import io.vertx.ext.unit.junit.VertxUnitRunner | ||
import io.vertx.scala.SQLConnection | ||
import org.vertx.scala.core.json.Json | ||
|
||
import scala.concurrent.Future | ||
|
||
import org.junit.Assert._ | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(classOf[VertxUnitRunner]) | ||
class CreateRowWithRowPermissionsTest extends TableauxTestBase { | ||
|
||
val createTableJson = Json.obj("name" -> "Test Nr. 1") | ||
|
||
def createTextColumnJson(name: String) = RequestCreation.Columns().add(RequestCreation.TextCol(name)).getJson | ||
|
||
def createNumberColumnJson(name: String) = RequestCreation.Columns().add(RequestCreation.NumericCol(name)).getJson | ||
|
||
@Test | ||
def createMultipleFullRowsWithRowPermissions(implicit c: TestContext): Unit = { | ||
okTest { | ||
val sqlConnection = SQLConnection(this.vertxAccess(), databaseConfig) | ||
val dbConnection = DatabaseConnection(this.vertxAccess(), sqlConnection) | ||
|
||
val valuesRow = Json.obj( | ||
"columns" -> Json.arr(Json.obj("id" -> 1), Json.obj("id" -> 2)), | ||
"rows" -> Json.arr( | ||
Json.obj("values" -> Json.arr("Test Field 1", 2)), | ||
Json.obj("values" -> Json.arr("Test Field 2", 5)) | ||
), | ||
"rowPermissions" -> Json.arr( | ||
"perm_group_1", | ||
"perm_group_2" | ||
) | ||
) | ||
val expectedJson = Json.obj( | ||
"status" -> "ok", | ||
"rows" -> Json.arr( | ||
Json.obj("id" -> 1, "values" -> Json.arr("Test Field 1", 2)), | ||
Json.obj("id" -> 2, "values" -> Json.arr("Test Field 2", 5)) | ||
) | ||
) | ||
|
||
for { | ||
_ <- sendRequest("POST", "/tables", createTableJson) | ||
_ <- sendRequest("POST", "/tables/1/columns", createTextColumnJson("Test Column 1")) | ||
_ <- sendRequest("POST", "/tables/1/columns", createNumberColumnJson("Test Column 2")) | ||
test <- sendRequest("POST", "/tables/1/rows", valuesRow) | ||
|
||
rowPermissions <- | ||
dbConnection.query("SELECT row_permissions FROM user_table_1") | ||
.map(_.getJsonArray("results").getJsonArray(0)) | ||
|
||
// rowPermissionsHistory <- | ||
// dbConnection.query( | ||
// "SELECT value FROM user_table_history_1 WHERE event = 'row_permission_changed' AND history_type = 'permission'" | ||
// ) | ||
// .map(_.getJsonArray("results").getJsonArray(0)) | ||
} yield { | ||
assertJSONEquals(expectedJson, test) | ||
println(s"rowPermissions: $rowPermissions") | ||
} | ||
} | ||
} | ||
} |