From da98be0ebaa95c10163e50a3081e7db5cc518866 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 6 Dec 2024 15:53:41 +0700 Subject: [PATCH] Add ToJson unit tests --- .../SnowflakeDataSourceItemFixture.cs | 50 ++++++++++++++++++- .../DataSources/SnowflakeDataSourceFixture.cs | 49 +++++++++++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/SnowflakeDataSourceItemFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/SnowflakeDataSourceItemFixture.cs index c92e9d98..971d0d0c 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/SnowflakeDataSourceItemFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSourceItems/SnowflakeDataSourceItemFixture.cs @@ -1,4 +1,5 @@ -using Reveal.Sdk.Dom.Core.Constants; +using Newtonsoft.Json.Linq; +using Reveal.Sdk.Dom.Core.Constants; using Reveal.Sdk.Dom.Core.Extensions; using Reveal.Sdk.Dom.Data; using Xunit; @@ -63,5 +64,52 @@ public void GetProcessDataOnServer_ReturnSameValue_AfterSet() Assert.Equal(expectedProcessDataOnServer, item.ProcessDataOnServer); Assert.Equal(expectedProcessDataOnServer, item.Properties.GetValue("ServerAggregation")); } + + [Fact] + public void ToJsonString_CreatesFormattedJson_NoConditions() + { + // Arrange + var expectedJson = @"{ + ""_type"": ""DataSourceItemType"", + ""Id"": ""a60ab508-0ed4-46e4-8d90-c3a9c09c29b8"", + ""Title"": ""SnowFlake DSI"", + ""DataSourceId"": ""snowflake_ds"", + ""HasTabularData"": true, + ""HasAsset"": false, + ""Properties"": { + ""ServerAggregation"": true, + ""Table"": ""CALL_CENTER"", + ""Schema"": ""TPCDS_SF100TCL"" + }, + ""Parameters"": { + ""RPCustomQuery"": ""Select CC_CALL_CENTER_ID, CC_CALL_CENTER_SK from CALL_CENTER"" + } + }"; + + var dataSource = new SnowflakeDataSource() + { + Id = "snowflake_ds", + }; + var dataSourceItem = new SnowflakeDataSourceItem("SnowFlake DSI", dataSource) + { + Id = "a60ab508-0ed4-46e4-8d90-c3a9c09c29b8", + HasTabularData = true, + HasAsset = false, + ProcessDataOnServer = true, + Table = "CALL_CENTER", + Schema = "TPCDS_SF100TCL", + CustomQuery = "Select CC_CALL_CENTER_ID, CC_CALL_CENTER_SK from CALL_CENTER", + }; + + var expectedJObject = JObject.Parse(expectedJson); + + // Act + var json = dataSourceItem.ToJsonString(); + var actualJObject = JObject.Parse(json); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + + } } } diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/SnowflakeDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/SnowflakeDataSourceFixture.cs index 016ad93b..ff934fcd 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/SnowflakeDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/SnowflakeDataSourceFixture.cs @@ -1,4 +1,5 @@ -using Reveal.Sdk.Dom.Core.Extensions; +using Newtonsoft.Json.Linq; +using Reveal.Sdk.Dom.Core.Extensions; using Reveal.Sdk.Dom.Data; using Xunit; @@ -63,5 +64,51 @@ public void SetWarehouse_ReturnSameValue_AfterSetWarehouse(string warehouse) Assert.Equal(warehouse, dataSource.Warehouse); Assert.Equal(warehouse, dataSource.Properties.GetValue("Warehouse")); } + + [Fact] + public void ToJsonString_CreatesFormattedJson_NoConditions() + { + // Arrange + var expectedJson = @"{ + ""_type"": ""DataSourceType"", + ""Id"": ""snowflake_ds"", + ""Provider"": ""SNOWFLAKE"", + ""Description"": ""Snowflake TEST"", + ""Subtitle"": ""Snowflake TEST Subtitle"", + ""Properties"": { + ""ServerAggregationDefault"": true, + ""ServerAggregationReadOnly"": false, + ""Host"": ""gpiskyj-al16914.snowflakecomputing.com"", + ""Database"": ""SNOWFLAKE_SAMPLE_DATA"", + ""Account"": ""pqwkobs-xb90908"", + ""Warehouse"": ""COMPUTE_WH"", + ""Schema"": ""TPCDS_SF100TCL"" + }, + //""Settings"": {} // TODO: Update to check settings fields after Postgresql PR is merged + }"; + + var dataSource = new SnowflakeDataSource() + { + Id = "snowflake_ds", + Title = "Snowflake TEST", + Subtitle = "Snowflake TEST Subtitle", + ProcessDataOnServerDefaultValue = true, + ProcessDataOnServerReadOnly = false, + Host = "gpiskyj-al16914.snowflakecomputing.com", + Database = "SNOWFLAKE_SAMPLE_DATA", + Account = "pqwkobs-xb90908", + Warehouse = "COMPUTE_WH", + Schema = "TPCDS_SF100TCL", + }; + var expectedJObject = JObject.Parse(expectedJson); + + // Act + var json = dataSource.ToJsonString(); + var actualJObject = JObject.Parse(json); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + + } } }