Skip to content

Commit

Permalink
update UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan Phat VO authored and Tan Phat VO committed Dec 10, 2024
1 parent f4e8ca4 commit 45268db
Showing 1 changed file with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class RestDataSourceFixture
new object[] { new List<string> { "Authorization: Bearer token", "Content-Type: application/json" } },
new object[] { null }
};

[Fact]
public void Constructor_SetsProviderToREST_WhenConstructed()
{
Expand Down Expand Up @@ -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<IField>
{
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<IField>
{
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);
}
}
}

0 comments on commit 45268db

Please sign in to comment.