Skip to content

Commit

Permalink
Adding tests for AppVersionEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuraraujo-msft committed Mar 7, 2024
1 parent 4d9c4c9 commit db2522c
Showing 1 changed file with 144 additions and 3 deletions.
147 changes: 144 additions & 3 deletions client/tests/unit/details/ContentUtilTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ TEST("Testing ParseJsonToVersionEntity()")
REQUIRE_NOTHROW(entity = ParseJsonToVersionEntity(versionEntity, handler));
REQUIRE(entity != nullptr);
REQUIRE(entity->GetContentType() == ContentType::Generic);
REQUIRE(entity->contentId.nameSpace == "namespace");
REQUIRE(entity->contentId.name == "name");
REQUIRE(entity->contentId.version == "version");
REQUIRE(entity->contentId.nameSpace == ns);
REQUIRE(entity->contentId.name == name);
REQUIRE(entity->contentId.version == version);
}

SECTION("Missing fields")
Expand Down Expand Up @@ -109,4 +109,145 @@ TEST("Testing ParseJsonToVersionEntity()")
}
}
}

SECTION("App Version Entity")
{
const std::string updateId = "updateId";
std::unique_ptr<VersionEntity> entity;
const json contentId = {{"Namespace", ns}, {"Name", name}, {"Version", version}};

SECTION("Correct")
{
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", json::array({contentId})}};

REQUIRE_NOTHROW(entity = ParseJsonToVersionEntity(versionEntity, handler));
REQUIRE(entity != nullptr);
REQUIRE(entity->GetContentType() == ContentType::App);
REQUIRE(entity->contentId.nameSpace == ns);
REQUIRE(entity->contentId.name == name);
REQUIRE(entity->contentId.version == version);

AppVersionEntity* appEntity = dynamic_cast<AppVersionEntity*>(entity.get());
REQUIRE(appEntity->updateId == updateId);
REQUIRE(appEntity->prerequisites.size() == 1);
REQUIRE(appEntity->prerequisites[0].contentId.nameSpace == ns);
REQUIRE(appEntity->prerequisites[0].contentId.name == name);
REQUIRE(appEntity->prerequisites[0].contentId.version == version);
}

SECTION("Missing fields")
{
SECTION("Missing Prerequisites")
{
const json versionEntity = {{"ContentId", contentId}, {"UpdateId", updateId}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Missing Prerequisites in response");
}

SECTION("Missing Prerequisite.Namespace")
{
const json wrongPrerequisite = {{"Name", name}, {"Version", version}};
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", json::array({wrongPrerequisite})}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Missing Prerequisite.Namespace in response");
}

SECTION("Missing Prerequisite.Name")
{
const json wrongPrerequisite = {{"Namespace", ns}, {"Version", version}};
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", json::array({wrongPrerequisite})}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Missing Prerequisite.Name in response");
}

SECTION("Missing Prerequisite.Version")
{
const json wrongPrerequisite = {{"Namespace", ns}, {"Name", name}};
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", json::array({wrongPrerequisite})}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Missing Prerequisite.Version in response");
}
}

SECTION("Wrong types")
{
SECTION("UpdateId")
{
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", 1},
{"Prerequisites", json::array({contentId})}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"UpdateId is not a string");
}

SECTION("Prerequisites")
{
SECTION("Not an array")
{
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", contentId}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Prerequisites is not an array");
}

SECTION("Element is not an object")
{
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", json::array({1})}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Prerequisite element is not a JSON object");
}

SECTION("Prerequisite.Namespace")
{
const json wrongPrerequisite = {{"Namespace", 1}, {"Name", name}, {"Version", version}};
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", json::array({wrongPrerequisite})}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Prerequisite.Namespace is not a string");
}

SECTION("Prerequisite.Name")
{
const json wrongPrerequisite = {{"Namespace", ns}, {"Name", 1}, {"Version", version}};
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", json::array({wrongPrerequisite})}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Prerequisite.Name is not a string");
}

SECTION("Prerequisite.Version")
{
const json wrongPrerequisite = {{"Namespace", ns}, {"Name", name}, {"Version", 1}};
const json versionEntity = {{"ContentId", contentId},
{"UpdateId", updateId},
{"Prerequisites", json::array({wrongPrerequisite})}};
REQUIRE_THROWS_CODE_MSG(ParseJsonToVersionEntity(versionEntity, handler),
ServiceInvalidResponse,
"Prerequisite.Version is not a string");
}
}
}
}
}

0 comments on commit db2522c

Please sign in to comment.