From f851908deb817c50d4b771a471437daa7842d352 Mon Sep 17 00:00:00 2001 From: Phat Vo Date: Wed, 4 Dec 2024 20:44:20 +0700 Subject: [PATCH] rdash unit tests for Rest DS --- .../Dashboards/TestRest.rdash | Bin 0 -> 1783 bytes .../RestDataSourceItemFixture.cs | 22 +++++- .../Data/DataSources/RestDataSourceFixture.cs | 70 ++++++++++++++++++ .../Reveal.Sdk.Dom.Tests.csproj | 7 +- 4 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 src/Reveal.Sdk.Dom.Tests/Dashboards/TestRest.rdash diff --git a/src/Reveal.Sdk.Dom.Tests/Dashboards/TestRest.rdash b/src/Reveal.Sdk.Dom.Tests/Dashboards/TestRest.rdash new file mode 100644 index 0000000000000000000000000000000000000000..1f6d7105917ac35d79f3bd29f2138f3a10884801 GIT binary patch literal 1783 zcmV&GI<6701q7i01f~E07PMPXku?+a%3)Qb8l|k zS#56SNql(Md$zZ2K=9jd?0w($ zCIyv~pb{eSJRZ-RXU3CHzy8u{wP#c@XurS@Ak`HAwV#^xF-TX?P*EOeYO;F5g-_Hq z2pO+;r?z6l5W&GG$+THnf~@PqfR_c zI@mkh?+u{eA@gUX)9<>2&hvTK?GW(x51zTb-e52&Y?|^rCnQ?1{cgTG;wxiLZ}w;^Yyao(Js9y_zi0Hkqw|6=%MXoA-b_fHx^QFRPi^5f*&8asxFP+Pa z3h0c;g7Q_vrjVhOprd6$n5c77sE7vL`M*;me0;4ga&fykVtM~Qd zRF~eD7fSR>sAGO_%r{??ak8AVQYw@$c6Z_41-AE(KY%=3iag1qo!xC3qIgwNEH8 zuh5sof7KgdQ0a|rPR23roXmke1ZXZ4;w~b84x)aw+iUot0pQV@5Vl zi4uLt7%CmRpjP0V6~8-&B?QLMl`ueGAc4^UvPh~px$U6j42JhqzUCfSPe{)$+xHw6 zN^fg$@{}%Do9OBGbG{^ks+CV&+u<3TEjV+Z##DxktP@4rSAgANpvbbU@kHhX+<{4V z9@%e5`*#t^)#YM=ZPz65;2trZUJ-Cb!BObFD=tkmB4F>ZTlLS3E95*0W}GucLyMnA z+{YV(Pt7bAdJVx)NA8(4fl z%vJ*AiZiXn{!Ym!?>P5UkDYNrKXMEPosGNAI2?xQHogJnAO%XSdJUigp9)0#KpW#P zi(V=1tu1zvo=ej&abm)Vj<8O5XRir$Y7pI>{iDuh*qpC{$VkBVG^Ua0!KSnfU>??7 zm0KrUU!(&vA3SCadgNPJZE2w%)`(@-BVlEkJmofv+rb>)`i>QKp4n7-=#5icrHh=2#ekZT{gU$60@TsgCw_iZY`#O{|lO&w-p!8u}!nKK)jS ze#BW`$!c2e;x9<$AKA>Sw>4k4((+k=I?-IEbJ1g?;7e4n(F4VP>k%h>#faT#DN8%D z*=%Xru>`&?gbLAq%J`hH+OsiPzs4F;c?as*Aj+V#Zhq?L{{R30|NjF3P)h*<6aW+e z000O8YN3Q#9("ServerAggregation")); + } } } diff --git a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs index b4476405..76f7de40 100644 --- a/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs +++ b/src/Reveal.Sdk.Dom.Tests/Data/DataSources/RestDataSourceFixture.cs @@ -1,7 +1,12 @@ +using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using Newtonsoft.Json.Linq; using Reveal.Sdk.Dom.Core.Extensions; +using Reveal.Sdk.Dom.Core.Serialization; using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; using Xunit; namespace Reveal.Sdk.Dom.Tests.Data.DataSources @@ -104,5 +109,70 @@ public void Method_SetsAndGetsValue_WithDifferentInputs(string method) Assert.Equal(method, dataSource.Method); Assert.Equal(method, dataSource.Properties.GetValue("Method")); } + + [Fact] + public void RDashDocument_HasCorrectDataSource_WhenLoadFromFile() + { + // Arrange + var filePath = Path.Combine(Environment.CurrentDirectory, "Dashboards", "TestRest.rdash"); + + // Act + var document = RdashDocument.Load(filePath); + var dataSource = document.DataSources.LastOrDefault(); + + // Assert + Assert.Equal(DataSourceProvider.REST, dataSource.Provider); + Assert.NotNull(dataSource.Properties.GetValue("Url")); + Assert.NotNull(dataSource.Properties.GetValue("_rpUseAnonymousAuthentication")); + Assert.NotNull(dataSource.Properties.GetValue("_rpUsePreemptiveAuthentication")); + } + + [Fact] + public void ToJsonString_CreatesFormattedJson_ForRestDataSource() + { + // Arrange + var expectedJson = @" + { + ""_type"": ""DataSourceType"", + ""Id"": ""Rest"", + ""Provider"": ""REST"", + ""Description"": ""Rest DS"", + ""Subtitle"": ""Excel2Json"", + ""Properties"": {} + }"; + + var dataSource = new RestDataSource() + { + Id = "Rest", + Title = "Rest DS", + DefaultRefreshRate = "120", + Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9", + Subtitle = "Excel2Json" + }; + + var dataSourceItems = new RestDataSourceItem("DB Test", dataSource) + { + Id = "RestItem", + Title = "Rest DS Item", + Fields = new List + { + new TextField("_id"), + new TextField("name"), + } + }; + + var document = new RdashDocument("My Dashboard"); + document.Visualizations.Add(new GridVisualization("Test List", dataSourceItems).SetColumns("name")); + + // Act + RdashSerializer.SerializeObject(document); + var json = document.ToJsonString(); + var jObject = JObject.Parse(json); + var actualJObject = jObject["DataSources"].LastOrDefault(); + var expectedJObject = JObject.Parse(expectedJson); + + // Assert + Assert.Equal(expectedJObject, actualJObject); + } } } \ No newline at end of file diff --git a/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj b/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj index f3313f39..fe1efcb3 100644 --- a/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj +++ b/src/Reveal.Sdk.Dom.Tests/Reveal.Sdk.Dom.Tests.csproj @@ -36,10 +36,9 @@ PreserveNewest - - - - + + PreserveNewest +