From 71c9583cd7d37b8d9fd888ba92c4d408b8e9b2be Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 09:57:22 -0700 Subject: [PATCH 01/34] EXCEPTIONS: ODBC.Storage.Exceptions() ReturnsListContainingTable.InvalidException <- FAIL" --- tests/testthat/test-ODBC.Storage.Exceptions.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Exceptions.R b/tests/testthat/test-ODBC.Storage.Exceptions.R index e6cf1d8..69b0a9f 100644 --- a/tests/testthat/test-ODBC.Storage.Exceptions.R +++ b/tests/testthat/test-ODBC.Storage.Exceptions.R @@ -110,6 +110,13 @@ describe('When exceptions <- ODBC.Storage.Exceptions()',{ # Then exceptions[['Query.NULL']] |> expect.exist() }) + it('then exceptions contains Table.Invalid exception',{ + # Given + exceptions <- ODBC.Storage.Exceptions() + + # Then + exceptions[['Table.Invalid']] |> expect.exist() + }) }) describe("when input |> exception[['Config.NULL']]()",{ From d7ff31b8587a9b6af9e772765c82380117354e8d Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 09:57:32 -0700 Subject: [PATCH 02/34] EXCEPTIONS: ODBC.Storage.Exceptions() ReturnsListContainingTable.InvalidException <- PASS --- R/ODBC.Storage.Exceptions.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/ODBC.Storage.Exceptions.R b/R/ODBC.Storage.Exceptions.R index 5cff2c5..3b26178 100644 --- a/R/ODBC.Storage.Exceptions.R +++ b/R/ODBC.Storage.Exceptions.R @@ -79,5 +79,6 @@ ODBC.Storage.Exceptions <- \() { stop('Query is null. Provide a Query.', call. = FALSE) } } + exceptions[['Table.Invalid']] <- \() {} return(exceptions) } \ No newline at end of file From 776460493d1d65f1b25ae3706eab0c3df487c0be Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:00:59 -0700 Subject: [PATCH 03/34] EXCEPTIONS: input |> exception[['Table.Invalid']]() ThrowsExceptionIfInputTrue -> FAIL --- tests/testthat/test-ODBC.Storage.Exceptions.R | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Exceptions.R b/tests/testthat/test-ODBC.Storage.Exceptions.R index 69b0a9f..844ac6d 100644 --- a/tests/testthat/test-ODBC.Storage.Exceptions.R +++ b/tests/testthat/test-ODBC.Storage.Exceptions.R @@ -506,3 +506,29 @@ describe("when input |> exception[['Query.NULL']]()",{ input |> exception[["Query.NULL"]]() |> expect_error(expected.error) }) }) + +describe("When input |> exception[['Table.Invalid']]()", { + it("then no exception is thrown if input is FALSE", { + # Given + exception <- ODBC.Storage.Exceptions() + + # When + input <- FALSE + + # Then + input |> exception[['Table.Invalid']]() |> expect.no.error() + }) + it("then an exception is thrown if input is TRUE", { + # Given + exception <- ODBC.Storage.Exceptions() + + invalid.table <- "Invalid Table" + expected.error <- paste0("ODBC.Storage: Table.Invalid: ", invalid.table, " is not a valid table.") + + # When + input <- TRUE + + # Then + input |> exception[['Table.Invalid']](invalid.table) |> expect.error(expected.error) + }) +}) \ No newline at end of file From 262b8acac43c5dc98807f784a2c4c9c905e5a099 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:01:06 -0700 Subject: [PATCH 04/34] EXCEPTIONS: input |> exception[['Table.Invalid']]() ThrowsExceptionIfInputTrue -> PASS --- R/ODBC.Storage.Exceptions.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/ODBC.Storage.Exceptions.R b/R/ODBC.Storage.Exceptions.R index 3b26178..3fc3ce5 100644 --- a/R/ODBC.Storage.Exceptions.R +++ b/R/ODBC.Storage.Exceptions.R @@ -79,6 +79,10 @@ ODBC.Storage.Exceptions <- \() { stop('Query is null. Provide a Query.', call. = FALSE) } } - exceptions[['Table.Invalid']] <- \() {} + exceptions[['Table.Invalid']] <- \(invoke, table) { + if(invoke) { + stop('ODBC.Storage: Table.Invalid: ', table, ' is not a valid table.', call. = FALSE) + } + } return(exceptions) } \ No newline at end of file From 9eee104ba36755e9438b8682258505b89f103ab1 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:21:22 -0700 Subject: [PATCH 05/34] EXCEPTIONS: input |> exception[['Query']]() ThrowsExceptionIfInputContainsInvalidObject -> FAIL --- tests/testthat/test-ODBC.Storage.Exceptions.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Exceptions.R b/tests/testthat/test-ODBC.Storage.Exceptions.R index 844ac6d..83c41fb 100644 --- a/tests/testthat/test-ODBC.Storage.Exceptions.R +++ b/tests/testthat/test-ODBC.Storage.Exceptions.R @@ -402,6 +402,18 @@ describe("When input |> exception[['Query']]()",{ # When input <- 'Conversion failed when converting from a character string to uniqueidentifier' + # Then + input |> exception[["Query"]]() |> expect_error(expected.error) + }) + it('then an exception is thrown if input contains Invalid object name',{ + # Given + exception <- ODBC.Storage.Exceptions() + + expected.error <- "ODBC.Storage: Table.Invalid: Invalid is not a valid table." + + # When + input <- "Invalid object name 'dbo.Invalid'." + # Then input |> exception[["Query"]]() |> expect_error(expected.error) }) From 4d38e6a408e601b956b198ea55d0c1589c4764cc Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:21:29 -0700 Subject: [PATCH 06/34] EXCEPTIONS: input |> exception[['Query']]() ThrowsExceptionIfInputContainsInvalidObject -> PASS --- R/ODBC.Storage.Exceptions.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/ODBC.Storage.Exceptions.R b/R/ODBC.Storage.Exceptions.R index 3fc3ce5..6792ab7 100644 --- a/R/ODBC.Storage.Exceptions.R +++ b/R/ODBC.Storage.Exceptions.R @@ -56,6 +56,10 @@ ODBC.Storage.Exceptions <- \() { 'Conversion failed when converting from a character string to uniqueidentifier' |> grepl(error) |> exceptions[["Conversion.Failed"]]() + + table <- sub(".*Invalid object name '[^\\.]+\\.([^']+)'.*", "\\1", error) + "Invalid object name 'dbo.Invalid'." |> + grepl(error) |> exceptions[["Table.Invalid"]](table) stop(error, call. = FALSE) } From ab7a1a7f732f17d591dfa9baa3dff82f94b7e89a Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:24:46 -0700 Subject: [PATCH 07/34] BROKER: ODBC.Storage.Broker() ReturnsListContainingGet.TablesOperation -> FAIL --- tests/testthat/test-ODBC.Storage.Broker.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Broker.R b/tests/testthat/test-ODBC.Storage.Broker.R index 5fc2e3e..9288705 100644 --- a/tests/testthat/test-ODBC.Storage.Broker.R +++ b/tests/testthat/test-ODBC.Storage.Broker.R @@ -26,6 +26,13 @@ describe("When operations <- configuration |> ODBC.Storage.Broker()",{ # Then operations[['Execute.Query']] |> expect.exist() }) + it('then operations contains Get.Tables operation',{ + # When + operations <- ODBC.Storage.Broker() + + # Then + operations[['Get.Tables']] |> expect.exist() + }) }) describe("when connection <- operate[['Create.Connection']]()",{ From e325e392aa525e564d9ea01861c8def2e8253095 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:24:53 -0700 Subject: [PATCH 08/34] BROKER: ODBC.Storage.Broker() ReturnsListContainingGet.TablesOperation -> PASS --- R/ODBC.Storage.Broker.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/ODBC.Storage.Broker.R b/R/ODBC.Storage.Broker.R index e28f35e..4dbb905 100644 --- a/R/ODBC.Storage.Broker.R +++ b/R/ODBC.Storage.Broker.R @@ -20,6 +20,7 @@ ODBC.Storage.Broker <- \(configuration, sql = Query::SQL()) { return(output) } + operations[['Get.Tables']] <- \() {} operations[['Insert']] <- \(entity, table) { table |> sql[['INSERT']](entity) |> From 975e6c2657cd902e6d6d9d4b2dad25b1a944d24c Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:44:41 -0700 Subject: [PATCH 09/34] BROKER: operate[['Get.Tables']]() ReturnsVectorWithTablesNames -> FAIL --- tests/testthat/test-ODBC.Storage.Broker.R | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Broker.R b/tests/testthat/test-ODBC.Storage.Broker.R index 9288705..4faeb9c 100644 --- a/tests/testthat/test-ODBC.Storage.Broker.R +++ b/tests/testthat/test-ODBC.Storage.Broker.R @@ -76,6 +76,20 @@ describe("when query |> operate[['Execute.Query']]()",{ }) }) +describe("when operate[['Get.Tables']]()",{ + it('then a vector containing tables names is returned',{ + skip_if_not(environment == 'local') + # Given + operate <- configuration |> ODBC.Storage.Broker() + + # When + tables <- operate[['Get.Tables']]() + + # Then + tables |> expect.vector() + }) +}) + describe("When table |> operate[['Select']]()",{ it('then a data.frame is returned if table exist in storage',{ skip_if_not(environment == 'local') From 4c80e85bbd3e8c684d02a4d179619975e32b0583 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:44:47 -0700 Subject: [PATCH 10/34] BROKER: operate[['Get.Tables']]() ReturnsVectorWithTablesNames -> PASS --- R/ODBC.Storage.Broker.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/ODBC.Storage.Broker.R b/R/ODBC.Storage.Broker.R index 4dbb905..6e5817e 100644 --- a/R/ODBC.Storage.Broker.R +++ b/R/ODBC.Storage.Broker.R @@ -20,7 +20,11 @@ ODBC.Storage.Broker <- \(configuration, sql = Query::SQL()) { return(output) } - operations[['Get.Tables']] <- \() {} + operations[['Get.Tables']] <- \() { + query <- "SELECT TABLE_NAME as Name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" + tables <- query |> operations[['Execute.Query']]() + tables[['Name']] + } operations[['Insert']] <- \(entity, table) { table |> sql[['INSERT']](entity) |> From 225cc8f42e2b5ff151ee783bb0dec29b5bac0ba8 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:47:12 -0700 Subject: [PATCH 11/34] VALIDATION: ODBC.Storage.Validator() ReturnsListContainingIs.Existing.TableValidator -> FAIL --- tests/testthat/test-ODBC.Storage.Validator.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Validator.R b/tests/testthat/test-ODBC.Storage.Validator.R index 21f629e..8a428e9 100644 --- a/tests/testthat/test-ODBC.Storage.Validator.R +++ b/tests/testthat/test-ODBC.Storage.Validator.R @@ -47,6 +47,13 @@ describe('When validators <- ODBC.Storage.Validator()',{ # Then validators[["Id"]] |> expect.exist() }) + it('then validators contains Is.Existing.Table validator',{ + # Given + validators <- ODBC.Storage.Validator() + + # Then + validators[["Is.Existing.Table"]] |> expect.exist() + }) }) describe('When query |> validate[["Query"]]()',{ From 0a72a31aae0be1785d34de20d356d69a55cb8016 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:47:21 -0700 Subject: [PATCH 12/34] VALIDATION: ODBC.Storage.Validator() ReturnsListContainingIs.Existing.TableValidator -> PASS --- R/ODBC.Storage.Validator.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/ODBC.Storage.Validator.R b/R/ODBC.Storage.Validator.R index d4b0c2c..bf5446f 100644 --- a/R/ODBC.Storage.Validator.R +++ b/R/ODBC.Storage.Validator.R @@ -24,5 +24,6 @@ ODBC.Storage.Validator <- \() { validators[['Is.Character']]() |> validators[['Is.UUID']]('id') } + validators[['Is.Existing.Table']] <- \() {} return(validators) } \ No newline at end of file From e7f62d535d0e1243fcb520dea1c28d5721d58ab7 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:55:17 -0700 Subject: [PATCH 13/34] BROKER: operate[['Get.Tables']]() ReturnsDataFrame -> FAIL --- tests/testthat/test-ODBC.Storage.Broker.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-ODBC.Storage.Broker.R b/tests/testthat/test-ODBC.Storage.Broker.R index 4faeb9c..8eee9bf 100644 --- a/tests/testthat/test-ODBC.Storage.Broker.R +++ b/tests/testthat/test-ODBC.Storage.Broker.R @@ -77,7 +77,7 @@ describe("when query |> operate[['Execute.Query']]()",{ }) describe("when operate[['Get.Tables']]()",{ - it('then a vector containing tables names is returned',{ + it('then a data.frame containing tables names is returned',{ skip_if_not(environment == 'local') # Given operate <- configuration |> ODBC.Storage.Broker() @@ -86,7 +86,7 @@ describe("when operate[['Get.Tables']]()",{ tables <- operate[['Get.Tables']]() # Then - tables |> expect.vector() + tables |> expect.data.frame() }) }) From 326a06cacb026b9c6c67c1c654dcb0b8726b9b3f Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:55:28 -0700 Subject: [PATCH 14/34] BROKER: operate[['Get.Tables']]() ReturnsDataFrame -> PASS --- R/ODBC.Storage.Broker.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/ODBC.Storage.Broker.R b/R/ODBC.Storage.Broker.R index 6e5817e..3658ff6 100644 --- a/R/ODBC.Storage.Broker.R +++ b/R/ODBC.Storage.Broker.R @@ -21,9 +21,8 @@ ODBC.Storage.Broker <- \(configuration, sql = Query::SQL()) { return(output) } operations[['Get.Tables']] <- \() { - query <- "SELECT TABLE_NAME as Name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" - tables <- query |> operations[['Execute.Query']]() - tables[['Name']] + query <- "SELECT TABLE_NAME as Tables FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" + query |> operations[['Execute.Query']]() } operations[['Insert']] <- \(entity, table) { table |> From ba14893e03e8affd07f050aca6ee9746969acf2b Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:56:56 -0700 Subject: [PATCH 15/34] CODE RUB: Update SQL Query --- R/ODBC.Storage.Broker.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ODBC.Storage.Broker.R b/R/ODBC.Storage.Broker.R index 3658ff6..e3a85e9 100644 --- a/R/ODBC.Storage.Broker.R +++ b/R/ODBC.Storage.Broker.R @@ -21,7 +21,7 @@ ODBC.Storage.Broker <- \(configuration, sql = Query::SQL()) { return(output) } operations[['Get.Tables']] <- \() { - query <- "SELECT TABLE_NAME as Tables FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" + query <- "SELECT TABLE_NAME as Table FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" query |> operations[['Execute.Query']]() } operations[['Insert']] <- \(entity, table) { From ed073a7bc786b1c143baff5127929bf43e0a2b27 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 10:58:26 -0700 Subject: [PATCH 16/34] CODE RUB: Update SQL Query --- R/ODBC.Storage.Broker.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ODBC.Storage.Broker.R b/R/ODBC.Storage.Broker.R index e3a85e9..e82716e 100644 --- a/R/ODBC.Storage.Broker.R +++ b/R/ODBC.Storage.Broker.R @@ -21,7 +21,7 @@ ODBC.Storage.Broker <- \(configuration, sql = Query::SQL()) { return(output) } operations[['Get.Tables']] <- \() { - query <- "SELECT TABLE_NAME as Table FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" + query <- "SELECT TABLE_NAME as name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" query |> operations[['Execute.Query']]() } operations[['Insert']] <- \(entity, table) { From 0ffaf069baa168020073c76640de99f4c29949a6 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:09:25 -0700 Subject: [PATCH 17/34] VALIDATION: table |> validate[['Is.Existing.Table']]() ThrowsExceptionIfInvalidTable -> FAIL --- tests/testthat/test-ODBC.Storage.Validator.R | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Validator.R b/tests/testthat/test-ODBC.Storage.Validator.R index 8a428e9..b36c90c 100644 --- a/tests/testthat/test-ODBC.Storage.Validator.R +++ b/tests/testthat/test-ODBC.Storage.Validator.R @@ -224,4 +224,33 @@ describe("When id |> validate[['Id']]()",{ # Then input |> validate[['Id']]() |> expect.no.error() }) +}) + +describe("When table |> validate[['Is.Existing.Table']]()",{ + it('then no exception is thrown if table is a valid table',{ + # Given + table <- 'Todo' + + broker <- configuration |> ODBC.Storage.Broker() + + validator <- broker |> ODBC.Storage.Validator() + + valid.table <- table + + # Then + valid.table |> validator[['Is.Existing.Table']]() |> expect.no.error() + }) + it('then an exception is thrown if table is not a valid table',{ + # Given + broker <- configuration |> ODBC.Storage.Broker() + + validator <- broker |> ODBC.Storage.Validator() + + invalid.table <- 'Invalid' + + expected.error <- 'ODBC.Storage: Table.Invalid: Invalid is not a valid table.' + + # Then + invalid.table |> validator[['Is.Existing.Table']]() |> expect.error(expected.error) + }) }) \ No newline at end of file From 0e25eed8c96ab92c67d835798afa5ac049a2b901 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:09:31 -0700 Subject: [PATCH 18/34] VALIDATION: table |> validate[['Is.Existing.Table']]() ThrowsExceptionIfInvalidTable -> PASS --- tests/testthat/test-ODBC.Storage.Service.R | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Service.R b/tests/testthat/test-ODBC.Storage.Service.R index 4cc3825..c69484a 100644 --- a/tests/testthat/test-ODBC.Storage.Service.R +++ b/tests/testthat/test-ODBC.Storage.Service.R @@ -214,6 +214,27 @@ describe("When entity |> service[['Add']](table)",{ # When entity <- entities |> tail(1) + # Then + entity |> services[['Add']](table) |> expect.error(expected.error) + }) + it('then an exception is thrown if table is invalid',{ + skip_if_not(environment == 'local') + # Given + broker <- configuration |> ODBC.Storage.Broker() + + services <- broker |> ODBC.Storage.Service() + + expected.error <- "ODBC.Storage: Key.Violation: Duplicate Primary Key not allowed." + + entity <- data.frame( + Id = uuid::UUIDgenerate(), + Task = 'Task', + Status = 'New' + ) + + # When + table <- 'Invalid' + # Then entity |> services[['Add']](table) |> expect.error(expected.error) }) From 1c90bff134ba0ca33233bd9fa0e69eaabb64c1c5 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:11:06 -0700 Subject: [PATCH 19/34] VALIDATION: table |> validate[['Is.Existing.Table']]() ThrowsExceptionIfTableIsInvalid -> PASS --- R/ODBC.Storage.Validator.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/ODBC.Storage.Validator.R b/R/ODBC.Storage.Validator.R index bf5446f..405afd8 100644 --- a/R/ODBC.Storage.Validator.R +++ b/R/ODBC.Storage.Validator.R @@ -1,4 +1,4 @@ -ODBC.Storage.Validator <- \() { +ODBC.Storage.Validator <- \(broker = NULL) { exception <- ODBC.Storage.Exceptions() validators <- Validate::Validator() @@ -24,6 +24,10 @@ ODBC.Storage.Validator <- \() { validators[['Is.Character']]() |> validators[['Is.UUID']]('id') } - validators[['Is.Existing.Table']] <- \() {} + validators[['Is.Existing.Table']] <- \(table) { + tables <- broker[['Get.Tables']]() + any(tables[['name']] == table) |> isFALSE() |> exception[['Table.Invalid']](table) + return(table) + } return(validators) } \ No newline at end of file From 468c1686d1b12b710260a94d83c450aa572b4431 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:13:34 -0700 Subject: [PATCH 20/34] SERVICE: entity |> service[['Add']](table) ThrowsExceptionIfTableIsInvalid -> FAIL --- tests/testthat/test-ODBC.Storage.Service.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-ODBC.Storage.Service.R b/tests/testthat/test-ODBC.Storage.Service.R index c69484a..a959cf0 100644 --- a/tests/testthat/test-ODBC.Storage.Service.R +++ b/tests/testthat/test-ODBC.Storage.Service.R @@ -224,7 +224,7 @@ describe("When entity |> service[['Add']](table)",{ services <- broker |> ODBC.Storage.Service() - expected.error <- "ODBC.Storage: Key.Violation: Duplicate Primary Key not allowed." + expected.error <- "ODBC.Storage: Table.Invalid: Invalid is not a valid table." entity <- data.frame( Id = uuid::UUIDgenerate(), From 8196c3e43074404192a389f5a023218b06deb038 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:13:40 -0700 Subject: [PATCH 21/34] SERVICE: entity |> service[['Add']](table) ThrowsExceptionIfTableIsInvalid -> PASS --- R/ODBC.Storage.Service.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/ODBC.Storage.Service.R b/R/ODBC.Storage.Service.R index 91325c0..389e86d 100644 --- a/R/ODBC.Storage.Service.R +++ b/R/ODBC.Storage.Service.R @@ -1,5 +1,5 @@ ODBC.Storage.Service <- \(broker) { - validate <- ODBC.Storage.Validator() + validate <- ODBC.Storage.Validator(broker) services <- list() services[['Execute.Query']] <- \(query) { @@ -11,7 +11,8 @@ ODBC.Storage.Service <- \(broker) { services[['Add']] <- \(entity, table) { entity |> validate[['Entity']]() table |> validate[['Table']]() - + + table |> validate[['Is.Existing.Table']]() entity |> broker[['Insert']](table) } services[['Retrieve']] <- \(table, fields) { From 4b812e015154a1848010bd92d01cb6650d48e701 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:17:41 -0700 Subject: [PATCH 22/34] SERVICE: table |> service[['Retrieve']]() ThrowsExceptionIfTableIsInvalid -> FAIL --- tests/testthat/test-ODBC.Storage.Service.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Service.R b/tests/testthat/test-ODBC.Storage.Service.R index a959cf0..02373c5 100644 --- a/tests/testthat/test-ODBC.Storage.Service.R +++ b/tests/testthat/test-ODBC.Storage.Service.R @@ -298,6 +298,19 @@ describe("When table |> service[['Retrieve']](fields)",{ table |> services[['Retrieve']](list()) |> expect.error(expected.error) }) + it('then an exception is thrown if table is invalid',{ + skip_if_not(environment == 'local') + # Given + broker <- configuration |> ODBC.Storage.Broker() + + services <- broker |> ODBC.Storage.Service() + + invalid.table <- 'Invalid' + expected.error <- "ODBC.Storage: Table.Invalid: Invalid is not a valid table." + + # Then + invalid.table |> services[['Retrieve']]() |> expect.error(expected.error) + }) }) describe("When id |> service[['RetrieveWhereId']](table, fields)",{ From ca6631abb12639515d9dc04e8eb28b8b1c7dbd04 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:17:47 -0700 Subject: [PATCH 23/34] SERVICE: table |> service[['Retrieve']]() ThrowsExceptionIfTableIsInvalid -> PASS --- R/ODBC.Storage.Service.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/ODBC.Storage.Service.R b/R/ODBC.Storage.Service.R index 389e86d..1210334 100644 --- a/R/ODBC.Storage.Service.R +++ b/R/ODBC.Storage.Service.R @@ -11,13 +11,15 @@ ODBC.Storage.Service <- \(broker) { services[['Add']] <- \(entity, table) { entity |> validate[['Entity']]() table |> validate[['Table']]() - + table |> validate[['Is.Existing.Table']]() entity |> broker[['Insert']](table) } - services[['Retrieve']] <- \(table, fields) { + services[['Retrieve']] <- \(table, fields = '*') { table |> validate[['Table']]() + table |> validate[['Is.Existing.Table']]() + table |> broker[['Select']](fields) } services[['RetrieveWhereId']] <- \(id, table, fields) { From 251af771c40420b08b8880b9999a47a210efb45d Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:20:20 -0700 Subject: [PATCH 24/34] SERVICE: id |> service[['RetrieveWhereId']](table) ThrowsExceptionIfTableIsInvalid -> FAIL --- tests/testthat/test-ODBC.Storage.Service.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Service.R b/tests/testthat/test-ODBC.Storage.Service.R index 02373c5..fc7882f 100644 --- a/tests/testthat/test-ODBC.Storage.Service.R +++ b/tests/testthat/test-ODBC.Storage.Service.R @@ -424,6 +424,21 @@ describe("When id |> service[['RetrieveWhereId']](table, fields)",{ # Then id |> services[['RetrieveWhereId']](table, list()) |> expect.error(expected.error) }) + it('then an exception is thrown if table is invalid',{ + skip_if_not(environment == 'local') + # Given + broker <- configuration |> ODBC.Storage.Broker() + + services <- broker |> ODBC.Storage.Service() + + invalid.table <- 'Invalid' + expected.error <- "ODBC.Storage: Table.Invalid: Invalid is not a valid table." + + id <- uuid::UUIDgenerate() + + # Then + id |> services[['RetrieveWhereId']](invalid.table) |> expect.error(expected.error) + }) }) describe("When entity |> service[['Modify']](table)",{ From dba92396f065741a517abe75b5666f703ae50653 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:20:26 -0700 Subject: [PATCH 25/34] SERVICE: id |> service[['RetrieveWhereId']](table) ThrowsExceptionIfTableIsInvalid -> PASS --- R/ODBC.Storage.Service.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/ODBC.Storage.Service.R b/R/ODBC.Storage.Service.R index 1210334..5b1d493 100644 --- a/R/ODBC.Storage.Service.R +++ b/R/ODBC.Storage.Service.R @@ -22,10 +22,12 @@ ODBC.Storage.Service <- \(broker) { table |> broker[['Select']](fields) } - services[['RetrieveWhereId']] <- \(id, table, fields) { + services[['RetrieveWhereId']] <- \(id, table, fields = '*') { id |> validate[['Id']]() table |> validate[['Table']]() + table |> validate[['Is.Existing.Table']]() + id |> broker[['SelectWhereId']](table, fields) } services[['Modify']] <- \(entity, table) { From 9a79c308df74783cc59265eaeb15b1c9a39b5553 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:22:17 -0700 Subject: [PATCH 26/34] SERVICE: entity |> service[['Modify']](table) ThrowsExceptionIfTableIsInvalid -> FAIL --- tests/testthat/test-ODBC.Storage.Service.R | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Service.R b/tests/testthat/test-ODBC.Storage.Service.R index fc7882f..073c5d4 100644 --- a/tests/testthat/test-ODBC.Storage.Service.R +++ b/tests/testthat/test-ODBC.Storage.Service.R @@ -544,6 +544,27 @@ describe("When entity |> service[['Modify']](table)",{ # When table <- list() + # Then + entity |> services[['Modify']](table) |> expect.error(expected.error) + }) + it('then an exception is thrown if table is invalid',{ + skip_if_not(environment == 'local') + # Given + broker <- configuration |> ODBC.Storage.Broker() + + services <- broker |> ODBC.Storage.Service() + + expected.error <- "ODBC.Storage: Table.Invalid: Invalid is not a valid table." + + entity <- data.frame( + Id = uuid::UUIDgenerate(), + Task = 'Task', + Status = 'New' + ) + + # When + table <- 'Invalid' + # Then entity |> services[['Modify']](table) |> expect.error(expected.error) }) From af1594d05da15d9936a7abdc9fea8688f38223cb Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:22:23 -0700 Subject: [PATCH 27/34] SERVICE: entity |> service[['Modify']](table) ThrowsExceptionIfTableIsInvalid -> PASS --- R/ODBC.Storage.Service.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/ODBC.Storage.Service.R b/R/ODBC.Storage.Service.R index 5b1d493..26c6b1a 100644 --- a/R/ODBC.Storage.Service.R +++ b/R/ODBC.Storage.Service.R @@ -33,6 +33,8 @@ ODBC.Storage.Service <- \(broker) { services[['Modify']] <- \(entity, table) { entity |> validate[['Entity']]() table |> validate[['Table']]() + + table |> validate[['Is.Existing.Table']]() entity |> broker[['Update']](table) } From bb2c1bb2228e5aa1692aa2f80419ed80dd0ec75f Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:24:33 -0700 Subject: [PATCH 28/34] SERVICE: id |> service[['Remove']](table) ThrowsExceptionIfTableIsInvalid -> FAIL --- tests/testthat/test-ODBC.Storage.Service.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Service.R b/tests/testthat/test-ODBC.Storage.Service.R index 073c5d4..8a1a4fd 100644 --- a/tests/testthat/test-ODBC.Storage.Service.R +++ b/tests/testthat/test-ODBC.Storage.Service.R @@ -673,6 +673,23 @@ describe("When id |> service[['Remove']](table)",{ # When table <- list() + # Then + id |> services[['Remove']](table) |> expect.error(expected.error) + }) + it('then an exception is thrown if table is invalid',{ + skip_if_not(environment == 'local') + # Given + broker <- configuration |> ODBC.Storage.Broker() + + services <- broker |> ODBC.Storage.Service() + + expected.error <- "ODBC.Storage: Table.Invalid: Invalid is not a valid table." + + id <- uuid::UUIDgenerate() + + # When + table <- 'Invalid' + # Then id |> services[['Remove']](table) |> expect.error(expected.error) }) From 857f768128a79d3c1c9645688d18fbaec42730b7 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:24:39 -0700 Subject: [PATCH 29/34] SERVICE: id |> service[['Remove']](table) ThrowsExceptionIfTableIsInvalid -> PASS --- R/ODBC.Storage.Service.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/ODBC.Storage.Service.R b/R/ODBC.Storage.Service.R index 26c6b1a..569ce31 100644 --- a/R/ODBC.Storage.Service.R +++ b/R/ODBC.Storage.Service.R @@ -42,6 +42,8 @@ ODBC.Storage.Service <- \(broker) { id |> validate[['Id']]() table |> validate[['Table']]() + table |> validate[['Is.Existing.Table']]() + id |> broker[['Delete']](table) } return(services) From 14527e4d700c54b876c49387b084897bdfbb15f3 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Tue, 3 Oct 2023 11:29:23 -0700 Subject: [PATCH 30/34] CODE RUB: Add Todo Notes --- R/Memory.Storage.Broker.R | 1 + R/Memory.Storage.Validator.R | 1 + R/ODBC.Storage.Service.R | 3 +++ 3 files changed, 5 insertions(+) diff --git a/R/Memory.Storage.Broker.R b/R/Memory.Storage.Broker.R index 2b64aa7..730ac39 100644 --- a/R/Memory.Storage.Broker.R +++ b/R/Memory.Storage.Broker.R @@ -10,6 +10,7 @@ Memory.Storage.Broker <- \(configuration = NULL) { tables[[table]] <<- tables[[table]] |> rbind(data) return(NULL) } + # TODO: Return as data.frame with name column operations[['Get.Tables']] <- \() { tables |> names() } diff --git a/R/Memory.Storage.Validator.R b/R/Memory.Storage.Validator.R index 709d188..e191f68 100644 --- a/R/Memory.Storage.Validator.R +++ b/R/Memory.Storage.Validator.R @@ -48,6 +48,7 @@ Memory.Storage.Validator <- \(broker = NULL) { ) return(entity) } + # TODO: align with ODBC.Storage.Validator validators[['Is.Existing.Table']] <- \(table) { broker[['Get.Tables']]() |> is.element(table) |> diff --git a/R/ODBC.Storage.Service.R b/R/ODBC.Storage.Service.R index 569ce31..f35cec0 100644 --- a/R/ODBC.Storage.Service.R +++ b/R/ODBC.Storage.Service.R @@ -13,6 +13,8 @@ ODBC.Storage.Service <- \(broker) { table |> validate[['Table']]() table |> validate[['Is.Existing.Table']]() + # TODO: entity |> validate[['Is.New.Entity']](table) + entity |> broker[['Insert']](table) } services[['Retrieve']] <- \(table, fields = '*') { @@ -35,6 +37,7 @@ ODBC.Storage.Service <- \(broker) { table |> validate[['Table']]() table |> validate[['Is.Existing.Table']]() + # TODO: entity |> validate[['Is.Existing.Entity']](table) entity |> broker[['Update']](table) } From 106e741da3ad66d38936462d99682308a4f8ba8c Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Thu, 5 Oct 2023 09:29:38 -0700 Subject: [PATCH 31/34] TESTING: Update Unit Test --- .../testthat/test-ODBC.Configuration.Broker.R | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/testthat/test-ODBC.Configuration.Broker.R b/tests/testthat/test-ODBC.Configuration.Broker.R index 2cadf39..7dbc897 100644 --- a/tests/testthat/test-ODBC.Configuration.Broker.R +++ b/tests/testthat/test-ODBC.Configuration.Broker.R @@ -37,6 +37,7 @@ describe('When operations <- ODBC.Configuration.Broker()',{ describe("When configuration <- operation[['Get.Preset.Config']]()",{ it('then configuration is a list',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -47,6 +48,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ configuration |> expect.list() }) it('then configuration contains drv parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -57,6 +59,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ configuration[['drv']] |> expect.exist() }) it('then configuration contains dsn parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -67,6 +70,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ configuration[['dsn']] |> expect.exist() }) it('then configuration contains uid parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -77,6 +81,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ configuration[['uid']] |> expect.exist() }) it('then configuration contains pwd parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -87,6 +92,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ configuration[['pwd']] |> expect.exist() }) it('then an exception is thrown is no DSN found in .Renviron',{ + skip_if_not(environment == 'local') # Given environment <- Environment::Environment() operation <- ODBC.Configuration.Broker() @@ -103,6 +109,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ 'DSN' |> environment[['Cache.Env.Variable']]('DSN') }) it('then an exception is thrown is no UID found in .Renviron',{ + skip_if_not(environment == 'local') # Given environment <- Environment::Environment() operation <- ODBC.Configuration.Broker() @@ -119,6 +126,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ 'UID' |> environment[['Cache.Env.Variable']]('UID') }) it('then an exception is thrown is no PWD found in .Renviron',{ + skip_if_not(environment == 'local') # Given environment <- Environment::Environment() operation <- ODBC.Configuration.Broker() @@ -138,6 +146,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ describe("When configuration <- operation[['Get.Manual.Config']]()",{ it('then configuration is a list',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -148,6 +157,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ configuration |> expect.list() }) it('then configuration contains drv parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -158,6 +168,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ configuration[['drv']] |> expect.exist() }) it('then configuration contains driver parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -168,6 +179,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ configuration[['driver']] |> expect.exist() }) it('then configuration contains server parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -178,6 +190,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ configuration[['server']] |> expect.exist() }) it('then configuration contains database parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -188,6 +201,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ configuration[['database']] |> expect.exist() }) it('then configuration contains uid parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -198,6 +212,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ configuration[['uid']] |> expect.exist() }) it('then configuration contains pwd parameter',{ + skip_if_not(environment == 'local') # Given operations <- ODBC.Configuration.Broker() @@ -208,6 +223,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ configuration[['pwd']] |> expect.exist() }) it('then an exception is thrown is no DRIVER found in .Renviron',{ + skip_if_not(environment == 'local') # Given environment <- Environment::Environment() operation <- ODBC.Configuration.Broker() @@ -224,6 +240,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ 'DRIVER' |> environment[['Cache.Env.Variable']]('DRIVER') }) it('then an exception is thrown is no SERVER found in .Renviron',{ + skip_if_not(environment == 'local') # Given environment <- Environment::Environment() operation <- ODBC.Configuration.Broker() @@ -240,6 +257,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ 'SERVER' |> environment[['Cache.Env.Variable']]('SERVER') }) it('then an exception is thrown is no DATABASE found in .Renviron',{ + skip_if_not(environment == 'local') # Given environment <- Environment::Environment() operation <- ODBC.Configuration.Broker() @@ -256,6 +274,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ 'DATABASE' |> environment[['Cache.Env.Variable']]('DATABASE') }) it('then an exception is thrown is no UID found in .Renviron',{ + skip_if_not(environment == 'local') # Given environment <- Environment::Environment() operation <- ODBC.Configuration.Broker() @@ -272,6 +291,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ 'UID' |> environment[['Cache.Env.Variable']]('UID') }) it('then an exception is thrown is no PWD found in .Renviron',{ + skip_if_not(environment == 'local') # Given environment <- Environment::Environment() operation <- ODBC.Configuration.Broker() From 0ba6496705a3f1de2ef11cb96cdd5ecf921cb75e Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Thu, 5 Oct 2023 10:51:14 -0700 Subject: [PATCH 32/34] TESTING: Update Unit Tests --- R/ODBC.Storage.Service.R | 2 +- tests/testthat/helper.sql.R | 2 - .../test-ODBC.Configuration.Service.R | 12 ++ tests/testthat/test-ODBC.Storage.Broker.R | 16 +- tests/testthat/test-ODBC.Storage.Service.R | 167 ++++++++---------- tests/testthat/test-ODBC.Storage.Validator.R | 4 +- tests/testthat/test-Storage.Orchestrator.R | 20 +-- tests/testthat/test-Todo.Broker.R | 10 +- 8 files changed, 111 insertions(+), 122 deletions(-) diff --git a/R/ODBC.Storage.Service.R b/R/ODBC.Storage.Service.R index f35cec0..1e783e8 100644 --- a/R/ODBC.Storage.Service.R +++ b/R/ODBC.Storage.Service.R @@ -36,7 +36,7 @@ ODBC.Storage.Service <- \(broker) { entity |> validate[['Entity']]() table |> validate[['Table']]() - table |> validate[['Is.Existing.Table']]() + table |> validate[['Is.Existing.Table']]() # TODO: entity |> validate[['Is.Existing.Entity']](table) entity |> broker[['Update']](table) diff --git a/tests/testthat/helper.sql.R b/tests/testthat/helper.sql.R index d93eb7a..a98f256 100644 --- a/tests/testthat/helper.sql.R +++ b/tests/testthat/helper.sql.R @@ -3,8 +3,6 @@ configurator <- ODBC.Configuration.Service() |> ODBC.Configuration.Processor() -configuration <- configurator[["Get.Config"]]() - sql <- Query::SQL() sql.utilities <- Query::SQL.Utilities() sql.functions <- Query::SQL.Functions() diff --git a/tests/testthat/test-ODBC.Configuration.Service.R b/tests/testthat/test-ODBC.Configuration.Service.R index 5051e14..ed8a050 100644 --- a/tests/testthat/test-ODBC.Configuration.Service.R +++ b/tests/testthat/test-ODBC.Configuration.Service.R @@ -61,6 +61,7 @@ describe("When service[['Open.Config.File']]()",{ describe("When configuration <- service[['Get.Preset.Config']]()",{ it('then configuration is a list',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -72,6 +73,7 @@ describe("When configuration <- service[['Get.Preset.Config']]()",{ configuration |> expect.list() }) it('then configuration contains drv',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -83,6 +85,7 @@ describe("When configuration <- service[['Get.Preset.Config']]()",{ configuration[['drv']] |> expect.exist() }) it('then configuration contains dsn',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -94,6 +97,7 @@ describe("When configuration <- service[['Get.Preset.Config']]()",{ configuration[['dsn']] |> expect.character() }) it('then configuration contains uid',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -105,6 +109,7 @@ describe("When configuration <- service[['Get.Preset.Config']]()",{ configuration[['uid']] |> expect.character() }) it('then configuration contains pwd',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -119,6 +124,7 @@ describe("When configuration <- service[['Get.Preset.Config']]()",{ describe("When configuration <- service[['Get.Manual.Config']]()",{ it('then configuration is a list',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -130,6 +136,7 @@ describe("When configuration <- service[['Get.Manual.Config']]()",{ configuration |> expect.list() }) it('then configuration contains drv',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -141,6 +148,7 @@ describe("When configuration <- service[['Get.Manual.Config']]()",{ configuration[['drv']] |> expect.exist() }) it('then configuration contains driver',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -152,6 +160,7 @@ describe("When configuration <- service[['Get.Manual.Config']]()",{ configuration[['driver']] |> expect.character() }) it('then configuration contains server',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -163,6 +172,7 @@ describe("When configuration <- service[['Get.Manual.Config']]()",{ configuration[['server']] |> expect.character() }) it('then configuration contains database',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -174,6 +184,7 @@ describe("When configuration <- service[['Get.Manual.Config']]()",{ configuration[['database']] |> expect.character() }) it('then configuration contains uid',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() @@ -185,6 +196,7 @@ describe("When configuration <- service[['Get.Manual.Config']]()",{ configuration[['uid']] |> expect.character() }) it('then configuration contains pwd',{ + skip_if_not(environment == 'local') # Given broker <- ODBC.Configuration.Broker() service <- broker |> ODBC.Configuration.Service() diff --git a/tests/testthat/test-ODBC.Storage.Broker.R b/tests/testthat/test-ODBC.Storage.Broker.R index 8eee9bf..8f4fd05 100644 --- a/tests/testthat/test-ODBC.Storage.Broker.R +++ b/tests/testthat/test-ODBC.Storage.Broker.R @@ -39,7 +39,7 @@ describe("when connection <- operate[['Create.Connection']]()",{ it('then connection is not NA is valid configuration',{ skip_if_not(environment == 'local') # Given - operate <- configuration |> ODBC.Storage.Broker() + operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() # When connection <- operate[['Create.Connection']]() @@ -54,7 +54,7 @@ describe("when query |> operate[['Execute.Query']]()",{ it('then no exception is thrown is query is valid',{ skip_if_not(environment == 'local') # Given - operate <- configuration |> ODBC.Storage.Broker() + operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() query <- "SELECT 1" @@ -64,7 +64,7 @@ describe("when query |> operate[['Execute.Query']]()",{ it('then a data.frame is returned if query is valid',{ skip_if_not(environment == 'local') # Given - operate <- configuration |> ODBC.Storage.Broker() + operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() query <- "SELECT 1" @@ -80,7 +80,7 @@ describe("when operate[['Get.Tables']]()",{ it('then a data.frame containing tables names is returned',{ skip_if_not(environment == 'local') # Given - operate <- configuration |> ODBC.Storage.Broker() + operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() # When tables <- operate[['Get.Tables']]() @@ -94,7 +94,7 @@ describe("When table |> operate[['Select']]()",{ it('then a data.frame is returned if table exist in storage',{ skip_if_not(environment == 'local') # Given - operate <- configuration |> ODBC.Storage.Broker() + operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() # When entities <- table |> operate[['Select']]() @@ -108,7 +108,7 @@ describe("When table |> operate[['Select']](fields)",{ it('then a data.frame is returned if table exist in storage',{ skip_if_not(environment == 'local') # Given - operate <- configuration |> ODBC.Storage.Broker() + operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() # When entities <- table |> operate[['Select']](fields) @@ -122,7 +122,7 @@ describe("When id |> operate[['SelectWhereId']](table)",{ it('then a data.frame is returned if table exist in storage',{ skip_if_not(environment == 'local') # Given - operate <- configuration |> ODBC.Storage.Broker() + operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() existing.entities <- table |> operate[['Select']]() existing.entity <- existing.entities |> tail(1) @@ -141,7 +141,7 @@ describe("When id |> operate[['SelectWhereId']](table, fields)",{ it('then a data.frame is returned if table exist in storage',{ skip_if_not(environment == 'local') # Given - operate <- configuration |> ODBC.Storage.Broker() + operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() existing.entities <- table |> operate[['Select']]() existing.entity <- existing.entities |> tail(1) diff --git a/tests/testthat/test-ODBC.Storage.Service.R b/tests/testthat/test-ODBC.Storage.Service.R index 8a1a4fd..c6e9563 100644 --- a/tests/testthat/test-ODBC.Storage.Service.R +++ b/tests/testthat/test-ODBC.Storage.Service.R @@ -95,31 +95,30 @@ describe('When query |> service[["Execute.Query"]]()',{ }) describe("When entity |> service[['Add']](table)",{ - it("then entity |> broker[['Insert']](table) is called",{ + it("then entity is added to storage",{ + skip_if_not(environment == 'local') # Given - input.entity <- data.frame(Id = 1) - input.table <- 'table' - - actual.entity <- NULL - actual.table <- NULL - - broker <- list() - broker[['Insert']] <- \(entity, table) { - actual.entity <<- entity - actual.table <<- table - } + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() - expected.entity <- input.entity - expected.table <- input.table + entity <- data.frame( + Id = uuid::UUIDgenerate(), + Task = 'Task', + Status = 'New' + ) + + expected.entity <- entity + expected.table <- table # When - input.entity |> services[['Add']](input.table) + entity |> services[['Add']](table) # Then + actual.entity <- entity[['Id']] |> broker[['SelectWhereId']](table, fields) actual.entity |> expect.equal(expected.entity) - actual.table |> expect.equal(expected.table) + + entity[['Id']] |> broker[['Delete']](table) }) it('then an exception is thrown if entity is NULL',{ # Given @@ -203,7 +202,7 @@ describe("When entity |> service[['Add']](table)",{ it('then an exception is thrown if entity is not new',{ skip_if_not(environment == 'local') # Given - broker <- configuration |> ODBC.Storage.Broker() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() @@ -220,7 +219,7 @@ describe("When entity |> service[['Add']](table)",{ it('then an exception is thrown if table is invalid',{ skip_if_not(environment == 'local') # Given - broker <- configuration |> ODBC.Storage.Broker() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() @@ -241,31 +240,19 @@ describe("When entity |> service[['Add']](table)",{ }) describe("When table |> service[['Retrieve']](fields)",{ - it("then table |> broker[['Select']](fields) is called",{ + it("then a data.frame is returned from storage",{ + skip_if_not(environment == 'local') # Given - input.fields <- list() - input.table <- 'table' - - actual.fields <- NULL - actual.table <- NULL - - broker <- list() - broker[['Select']] <- \(table, fields) { - actual.fields <<- fields - actual.table <<- table - } + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() - expected.fields <- input.fields - expected.table <- input.table - # When - input.table |> services[['Retrieve']](input.fields) + retrieved.entities <- table |> services[['Retrieve']](fields) # Then - actual.fields |> expect.equal(expected.fields) - actual.table |> expect.equal(expected.table) + actual.entities <- table |> broker[['Select']](fields) + actual.entities |> expect.equal(retrieved.entities) }) it('then an exception is thrown if table is NULL',{ # Given @@ -301,7 +288,7 @@ describe("When table |> service[['Retrieve']](fields)",{ it('then an exception is thrown if table is invalid',{ skip_if_not(environment == 'local') # Given - broker <- configuration |> ODBC.Storage.Broker() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() @@ -314,36 +301,25 @@ describe("When table |> service[['Retrieve']](fields)",{ }) describe("When id |> service[['RetrieveWhereId']](table, fields)",{ - it("then id |> broker[['SelectWhereId']](table, fields) is called",{ + it("then entity wit id is returned from storage",{ + skip_if_not(environment == 'local') # Given - input.fields <- list() - input.table <- 'table' - input.id <- uuid::UUIDgenerate() - - actual.fields <- NULL - actual.table <- NULL - actual.id <- NULL - - broker <- list() - broker[['SelectWhereId']] <- \(id, table, fields) { - actual.fields <<- fields - actual.table <<- table - actual.id <<- id - } + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() + + existing.entities <- table |> broker[['Select']](fields) + existing.entity <- existing.entities |> tail(1) - expected.fields <- input.fields - expected.table <- input.table - expected.id <- input.id + id <- existing.entity[['Id']] + + expected.entity <- existing.entity # When - input.id |> services[['RetrieveWhereId']](input.table, input.fields) + retrieved.entity <- id |> services[['RetrieveWhereId']](table, fields) # Then - actual.fields |> expect.equal(expected.fields) - actual.table |> expect.equal(expected.table) - actual.id |> expect.equal(expected.id) + retrieved.entity |> expect.equal.data(expected.entity) }) it('then an exception is thrown if id is NULL',{ # Given @@ -427,7 +403,7 @@ describe("When id |> service[['RetrieveWhereId']](table, fields)",{ it('then an exception is thrown if table is invalid',{ skip_if_not(environment == 'local') # Given - broker <- configuration |> ODBC.Storage.Broker() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() @@ -442,31 +418,34 @@ describe("When id |> service[['RetrieveWhereId']](table, fields)",{ }) describe("When entity |> service[['Modify']](table)",{ - it("then entity |> broker[['Update']](table) is called",{ + it("then entity with matching Id is updated in storage",{ + skip_if_not(environment == 'local') # Given - input.entity <- data.frame(Id = '123') - input.table <- 'table' + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() - actual.entity <- NULL - actual.table <- NULL + services <- broker |> ODBC.Storage.Service() - broker <- list() - broker[['Update']] <- \(entity, table) { - actual.entity <<- entity - actual.table <<- table - } + new.entity <- data.frame( + Id = uuid::UUIDgenerate(), + Task = 'Task', + Status = 'New' + ) - services <- broker |> ODBC.Storage.Service() + new.entity |> broker[['Insert']](table) + + updated.entity <- new.entity + updated.entity[['Status']] <- 'Updated' - expected.entity <- input.entity - expected.table <- input.table + expected.entity <- updated.entity # When - input.entity |> services[['Modify']](input.table) + updated.entity |> services[['Modify']](table) # Then - actual.entity |> expect.equal(expected.entity) - actual.table |> expect.equal(expected.table) + retrieved.entity <- updated.entity[['Id']] |> broker[['SelectWhereId']](table, fields) + retrieved.entity |> expect.equal(expected.entity) + + updated.entity[['Id']] |> broker[['Delete']](table) }) it('then an exception is thrown if entity is NULL',{ # Given @@ -550,7 +529,7 @@ describe("When entity |> service[['Modify']](table)",{ it('then an exception is thrown if table is invalid',{ skip_if_not(environment == 'local') # Given - broker <- configuration |> ODBC.Storage.Broker() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() @@ -571,31 +550,31 @@ describe("When entity |> service[['Modify']](table)",{ }) describe("When id |> service[['Remove']](table)",{ - it("then id |> broker[['Delete']](table) is called",{ + it("then entity with matching id is delete from storage",{ + skip_if_not(environment == 'local') # Given - input.table <- 'table' - input.id <- uuid::UUIDgenerate() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() - actual.table <- NULL - actual.id <- NULL + services <- broker |> ODBC.Storage.Service() - broker <- list() - broker[['Delete']] <- \(id, table) { - actual.table <<- table - actual.id <<- id - } + new.entity <- data.frame( + Id = uuid::UUIDgenerate(), + Task = 'Task', + Status = 'New' + ) - services <- broker |> ODBC.Storage.Service() + new.entity |> broker[['Insert']](table) + + existing.entity <- new.entity - expected.table <- input.table - expected.id <- input.id + deleted.entity <- existing.entity # When - input.id |> services[['Remove']](input.table) + existing.entity[['Id']] |> services[['Remove']](table) # Then - actual.table |> expect.equal(expected.table) - actual.id |> expect.equal(expected.id) + retrieved.entity <- deleted.entity[['Id']] |> broker[['SelectWhereId']](table, fields) + retrieved.entity |> expect.rows(0) }) it('then an exception is thrown if id is NULL',{ # Given @@ -679,7 +658,7 @@ describe("When id |> service[['Remove']](table)",{ it('then an exception is thrown if table is invalid',{ skip_if_not(environment == 'local') # Given - broker <- configuration |> ODBC.Storage.Broker() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() services <- broker |> ODBC.Storage.Service() diff --git a/tests/testthat/test-ODBC.Storage.Validator.R b/tests/testthat/test-ODBC.Storage.Validator.R index b36c90c..940fe3e 100644 --- a/tests/testthat/test-ODBC.Storage.Validator.R +++ b/tests/testthat/test-ODBC.Storage.Validator.R @@ -231,7 +231,7 @@ describe("When table |> validate[['Is.Existing.Table']]()",{ # Given table <- 'Todo' - broker <- configuration |> ODBC.Storage.Broker() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() validator <- broker |> ODBC.Storage.Validator() @@ -242,7 +242,7 @@ describe("When table |> validate[['Is.Existing.Table']]()",{ }) it('then an exception is thrown if table is not a valid table',{ # Given - broker <- configuration |> ODBC.Storage.Broker() + broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() validator <- broker |> ODBC.Storage.Validator() diff --git a/tests/testthat/test-Storage.Orchestrator.R b/tests/testthat/test-Storage.Orchestrator.R index 366be91..8a69e31 100644 --- a/tests/testthat/test-Storage.Orchestrator.R +++ b/tests/testthat/test-Storage.Orchestrator.R @@ -7,56 +7,56 @@ describe('Storage.Orchestrator',{ describe('When orchestrations <- configuration |> Storage.Orchestrator()',{ it('then orchestrations is a list',{ # When - orchestrations <- configuration |> Storage.Orchestrator() + orchestrations <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # Then orchestrations |> expect.list() }) it('then orchestrations contains Seed.Table orchestration',{ # When - orchestrations <- configuration |> Storage.Orchestrator() + orchestrations <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # Then orchestrations[['Seed.Table']] |> expect.exist() }) it('then orchestrations contains Execute.Query orchestration',{ # When - orchestrations <- configuration |> Storage.Orchestrator() + orchestrations <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # Then orchestrations[['Execute.Query']] |> expect.exist() }) it('then orchestrations contains Add orchestration',{ # When - orchestrations <- configuration |> Storage.Orchestrator() + orchestrations <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # Then orchestrations[['Add']] |> expect.exist() }) it('then orchestrations contains Retrieve orchestration',{ # When - orchestrations <- configuration |> Storage.Orchestrator() + orchestrations <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # Then orchestrations[['Retrieve']] |> expect.exist() }) it('then orchestrations contains RetrieveWhereId orchestration',{ # When - orchestrations <- configuration |> Storage.Orchestrator() + orchestrations <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # Then orchestrations[['RetrieveWhereId']] |> expect.exist() }) it('then orchestrations contains Modify orchestration',{ # When - orchestrations <- configuration |> Storage.Orchestrator() + orchestrations <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # Then orchestrations[['Modify']] |> expect.exist() }) it('then orchestrations contains Remove orchestration',{ # When - orchestrations <- configuration |> Storage.Orchestrator() + orchestrations <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # Then orchestrations[['Remove']] |> expect.exist() @@ -92,7 +92,7 @@ describe("when query |> orchestrate[['Execute.Query']]()",{ skip_if_not(environment == 'local') # Given type <- 'odbc' - orchestrate <- configuration |> Storage.Orchestrator(type) + orchestrate <- configurator[["Get.Config"]]() |> Storage.Orchestrator(type) # When query <- "SELECT 1" @@ -103,7 +103,7 @@ describe("when query |> orchestrate[['Execute.Query']]()",{ it('then no exception is thrown if orchestration service instantiated with no type provided',{ skip_if_not(environment == 'local') # Given - orchestrate <- configuration |> Storage.Orchestrator() + orchestrate <- configurator[["Get.Config"]]() |> Storage.Orchestrator() # When query <- "SELECT 1" diff --git a/tests/testthat/test-Todo.Broker.R b/tests/testthat/test-Todo.Broker.R index b611222..8b010d4 100644 --- a/tests/testthat/test-Todo.Broker.R +++ b/tests/testthat/test-Todo.Broker.R @@ -53,7 +53,7 @@ describe("When todo |> operations[['Insert']]()",{ it('then todo is inserted into odbc.storage',{ skip_if_not(environment == 'local') # Given - storage <- configuration |> Storage.Orchestrator('odbc') + storage <- configurator[["Get.Config"]]() |> Storage.Orchestrator('odbc') operations <- storage |> Todo.Broker() new.todo <- data.frame( @@ -105,7 +105,7 @@ describe("When operations[['Select']]()",{ it('then all todos in odbc.storage is returned',{ skip_if_not(environment == 'local') # Given - storage <- configuration |> Storage.Orchestrator('odbc') + storage <- configurator[["Get.Config"]]() |> Storage.Orchestrator('odbc') operations <- storage |> Todo.Broker() expected.todos <- 'Todo' |> storage[['Retrieve']](fields) @@ -137,7 +137,7 @@ describe("When id |> operations[['SelectWhereId']]()",{ it('then todo with id equal id is returned from odbc.storage',{ skip_if_not(environment == 'local') # Given - storage <- configuration |> Storage.Orchestrator('odbc') + storage <- configurator[["Get.Config"]]() |> Storage.Orchestrator('odbc') operations <- storage |> Todo.Broker() existing.todos <- 'Todo' |> storage[['Retrieve']](fields) @@ -177,7 +177,7 @@ describe("When todo |> operations[['Update']]()",{ it('then todo in odbc.storage is updated',{ skip_if_not(environment == 'local') # Given - storage <- configuration |> Storage.Orchestrator('odbc') + storage <- configurator[["Get.Config"]]() |> Storage.Orchestrator('odbc') operations <- storage |> Todo.Broker() new.todo <- data.frame( @@ -241,7 +241,7 @@ describe("When id |> operations[['Delete']]()",{ it('then todo with id are removed from odbc.storage',{ skip_if_not(environment == 'local') # Given - storage <- configuration |> Storage.Orchestrator('odbc') + storage <- configurator[["Get.Config"]]() |> Storage.Orchestrator('odbc') operations <- storage |> Todo.Broker() new.todo <- data.frame( From 877c37d21f601bed0d65d58b12d3ebe12e55fca9 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Thu, 5 Oct 2023 11:58:25 -0700 Subject: [PATCH 33/34] TESTING: Update Unit Tests --- .../testthat/test-ODBC.Configuration.Broker.R | 32 ++++++++++++++----- tests/testthat/test-ODBC.Storage.Broker.R | 15 --------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/tests/testthat/test-ODBC.Configuration.Broker.R b/tests/testthat/test-ODBC.Configuration.Broker.R index 7dbc897..135e9ad 100644 --- a/tests/testthat/test-ODBC.Configuration.Broker.R +++ b/tests/testthat/test-ODBC.Configuration.Broker.R @@ -99,6 +99,8 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ expect.error <- "No DSN environment variable not found in .Renviron Configuration file." + cache <- 'DSN' |> environment[['Get.Env.Variable']]() + # When 'DSN' |> environment[['Clear.Env.Variable']]() @@ -106,7 +108,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ operation[['Get.Preset.Config']]() |> expect.error(expect.error) # Then - 'DSN' |> environment[['Cache.Env.Variable']]('DSN') + 'DSN' |> environment[['Cache.Env.Variable']](cache) }) it('then an exception is thrown is no UID found in .Renviron',{ skip_if_not(environment == 'local') @@ -116,6 +118,8 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ expect.error <- "No UID environment variable not found in .Renviron Configuration file." + cache <- 'UID' |> environment[['Get.Env.Variable']]() + # When 'UID' |> environment[['Clear.Env.Variable']]() @@ -123,7 +127,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ operation[['Get.Preset.Config']]() |> expect.error(expect.error) # Then - 'UID' |> environment[['Cache.Env.Variable']]('UID') + 'UID' |> environment[['Cache.Env.Variable']](cache) }) it('then an exception is thrown is no PWD found in .Renviron',{ skip_if_not(environment == 'local') @@ -133,6 +137,8 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ expect.error <- "No PWD environment variable not found in .Renviron Configuration file." + cache <- 'PWD' |> environment[['Get.Env.Variable']]() + # When 'PWD' |> environment[['Clear.Env.Variable']]() @@ -140,7 +146,7 @@ describe("When configuration <- operation[['Get.Preset.Config']]()",{ operation[['Get.Preset.Config']]() |> expect.error(expect.error) # Then - 'PWD' |> environment[['Cache.Env.Variable']]('PWD') + 'PWD' |> environment[['Cache.Env.Variable']](cache) }) }) @@ -230,6 +236,8 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ expect.error <- "No DRIVER environment variable not found in .Renviron Configuration file." + cache <- 'DRIVER' |> environment[['Get.Env.Variable']]() + # When 'DRIVER' |> environment[['Clear.Env.Variable']]() @@ -237,7 +245,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ operation[['Get.Manual.Config']]() |> expect.error(expect.error) # Then - 'DRIVER' |> environment[['Cache.Env.Variable']]('DRIVER') + 'DRIVER' |> environment[['Cache.Env.Variable']](cache) }) it('then an exception is thrown is no SERVER found in .Renviron',{ skip_if_not(environment == 'local') @@ -247,6 +255,8 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ expect.error <- "No SERVER environment variable not found in .Renviron Configuration file." + cache <- 'SERVER' |> environment[['Get.Env.Variable']]() + # When 'SERVER' |> environment[['Clear.Env.Variable']]() @@ -254,7 +264,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ operation[['Get.Manual.Config']]() |> expect.error(expect.error) # Then - 'SERVER' |> environment[['Cache.Env.Variable']]('SERVER') + 'SERVER' |> environment[['Cache.Env.Variable']](cache) }) it('then an exception is thrown is no DATABASE found in .Renviron',{ skip_if_not(environment == 'local') @@ -264,6 +274,8 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ expect.error <- "No DATABASE environment variable not found in .Renviron Configuration file." + cache <- 'DATABASE' |> environment[['Get.Env.Variable']]() + # When 'DATABASE' |> environment[['Clear.Env.Variable']]() @@ -271,7 +283,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ operation[['Get.Manual.Config']]() |> expect.error(expect.error) # Then - 'DATABASE' |> environment[['Cache.Env.Variable']]('DATABASE') + 'DATABASE' |> environment[['Cache.Env.Variable']](cache) }) it('then an exception is thrown is no UID found in .Renviron',{ skip_if_not(environment == 'local') @@ -281,6 +293,8 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ expect.error <- "No UID environment variable not found in .Renviron Configuration file." + cache <- 'UID' |> environment[['Get.Env.Variable']]() + # When 'UID' |> environment[['Clear.Env.Variable']]() @@ -288,7 +302,7 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ operation[['Get.Manual.Config']]() |> expect.error(expect.error) # Then - 'UID' |> environment[['Cache.Env.Variable']]('UID') + 'UID' |> environment[['Cache.Env.Variable']](cache) }) it('then an exception is thrown is no PWD found in .Renviron',{ skip_if_not(environment == 'local') @@ -298,6 +312,8 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ expect.error <- "No PWD environment variable not found in .Renviron Configuration file." + cache <- 'PWD' |> environment[['Get.Env.Variable']]() + # When 'PWD' |> environment[['Clear.Env.Variable']]() @@ -305,6 +321,6 @@ describe("When configuration <- operation[['Get.Manual.Config']]()",{ operation[['Get.Manual.Config']]() |> expect.error(expect.error) # Then - 'PWD' |> environment[['Cache.Env.Variable']]('PWD') + 'PWD' |> environment[['Cache.Env.Variable']](cache) }) }) \ No newline at end of file diff --git a/tests/testthat/test-ODBC.Storage.Broker.R b/tests/testthat/test-ODBC.Storage.Broker.R index 8f4fd05..86f992d 100644 --- a/tests/testthat/test-ODBC.Storage.Broker.R +++ b/tests/testthat/test-ODBC.Storage.Broker.R @@ -35,21 +35,6 @@ describe("When operations <- configuration |> ODBC.Storage.Broker()",{ }) }) -describe("when connection <- operate[['Create.Connection']]()",{ - it('then connection is not NA is valid configuration',{ - skip_if_not(environment == 'local') - # Given - operate <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker() - - # When - connection <- operate[['Create.Connection']]() - - # Then - connection |> expect.not.na() - connection |> DBI::dbDisconnect() - }) -}) - describe("when query |> operate[['Execute.Query']]()",{ it('then no exception is thrown is query is valid',{ skip_if_not(environment == 'local') From 34628393fda77aac2e9faec9ab2580c06e845a86 Mon Sep 17 00:00:00 2001 From: Flippie Coetser Date: Thu, 5 Oct 2023 12:02:48 -0700 Subject: [PATCH 34/34] TESTING : Update Unit Tests --- tests/testthat/test-ODBC.Storage.Validator.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-ODBC.Storage.Validator.R b/tests/testthat/test-ODBC.Storage.Validator.R index 940fe3e..03981c8 100644 --- a/tests/testthat/test-ODBC.Storage.Validator.R +++ b/tests/testthat/test-ODBC.Storage.Validator.R @@ -228,6 +228,7 @@ describe("When id |> validate[['Id']]()",{ describe("When table |> validate[['Is.Existing.Table']]()",{ it('then no exception is thrown if table is a valid table',{ + skip_if_not(environment == 'local') # Given table <- 'Todo' @@ -241,6 +242,7 @@ describe("When table |> validate[['Is.Existing.Table']]()",{ valid.table |> validator[['Is.Existing.Table']]() |> expect.no.error() }) it('then an exception is thrown if table is not a valid table',{ + skip_if_not(environment == 'local') # Given broker <- configurator[["Get.Config"]]() |> ODBC.Storage.Broker()