From 45268db292b4939bf849e8e606948ab414aede7d Mon Sep 17 00:00:00 2001 From: Tan Phat VO Date: Tue, 10 Dec 2024 19:12:22 +0700 Subject: [PATCH] update UTs --- .../Data/DataSources/RestDataSourceFixture.cs | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs index 1f453860..09624c3b 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs @@ -19,7 +19,7 @@ public class RestDataSourceFixture new object[] { new List { "Authorization: Bearer token", "Content-Type: application/json" } }, new object[] { null } }; - + [Fact] public void Constructor_SetsProviderToREST_WhenConstructed() { @@ -165,5 +165,91 @@ public void ToJsonString_CreatesFormattedJson_ForRestDataSource() // Assert Assert.Equal(expectedJObject, actualJObject); } + + [Fact] + public void ToJsonString_CreatesFormattedUseCsv_ForRestDataSource() + { + // Arrange + var expectedJson = @" + { + ""_type"": ""DataSourceType"", + ""Id"": ""ecca74a8-2082-4630-ae2b-e59e095bb87f"", + ""Provider"": ""REST"", + ""Description"": ""JSON DS"", + ""Subtitle"": ""JSON DS Subtitle"", + ""Properties"": { + ""Result-Type"": "".csv"" + } + }"; + + var dataSourceItems = new RestDataSourceItem("DB Test", new DataSource { Title = "JSON DS", Subtitle = "JSON DS Subtitle" }) + { + Id = "RestItem", + Title = "Rest DS Item", + Fields = new List + { + new TextField("_id"), + new TextField("name"), + } + }; + + dataSourceItems.UseCsv(); + + var document = new RdashDocument("My Dashboard"); + document.Visualizations.Add(new GridVisualization("Test List", dataSourceItems).SetColumns("name")); + var expectedJObject = JObject.Parse(expectedJson); + + // Act + RdashSerializer.SerializeObject(document); + var json = document.ToJsonString(); + var jObject = JObject.Parse(json); + var actualJObject = jObject["DataSources"].LastOrDefault(); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } + + [Fact] + public void ToJsonString_CreatesFormattedUseExcel_ForRestDataSource() + { + // Arrange + var expectedJson = @" + { + ""_type"": ""DataSourceType"", + ""Id"": ""2ed39a3b-f267-434f-a3ca-319801c1b7b5"", + ""Provider"": ""REST"", + ""Description"": ""JSON DS"", + ""Subtitle"": ""JSON DS Subtitle"", + ""Properties"": { + ""Result-Type"": "".xlsx"" + } + }"; + + var dataSourceItems = new RestDataSourceItem("DB Test", new DataSource { Title = "JSON DS", Subtitle = "JSON DS Subtitle" }) + { + Id = "RestItem", + Title = "Rest DS Item", + Fields = new List + { + new TextField("_id"), + new TextField("name"), + } + }; + + dataSourceItems.UseExcel(); + + var document = new RdashDocument("My Dashboard"); + document.Visualizations.Add(new GridVisualization("Test List", dataSourceItems).SetColumns("name")); + var expectedJObject = JObject.Parse(expectedJson); + + // Act + RdashSerializer.SerializeObject(document); + var json = document.ToJsonString(); + var jObject = JObject.Parse(json); + var actualJObject = jObject["DataSources"].LastOrDefault(); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } } } \ No newline at end of file