59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
#include <Void/ShortUrl/ShortUrl.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace
|
|
{
|
|
class Shortener final : public Void::ShortUrl::IShortener
|
|
{
|
|
public:
|
|
|
|
[[nodiscard]] std::string_view provider_id() const noexcept override
|
|
{
|
|
return "test";
|
|
}
|
|
|
|
[[nodiscard]] Void::ShortUrl::Health health() const override
|
|
{
|
|
return {.status = Void::ShortUrl::HealthStatus::healthy};
|
|
}
|
|
|
|
[[nodiscard]] Void::ShortUrl::ShortenResult
|
|
shorten(const Void::ShortUrl::ShortenRequest& request) override
|
|
{
|
|
return {
|
|
.short_url = "https://sho.rt/s/Ab3dE5fG7h",
|
|
.key = "Ab3dE5fG7h",
|
|
.expires_at_unix_seconds = request.expires_at_unix_seconds,
|
|
};
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
Void::Testing::Test short_url_service_contract()
|
|
{
|
|
Shortener shortener;
|
|
Void::Testing::expect_eq(shortener.service_name(),
|
|
Void::ShortUrl::kServiceId);
|
|
Void::Testing::expect_eq(shortener.service_version(), std::uint32_t{1});
|
|
Void::Testing::expect_eq(shortener.provider_id(), std::string_view{"test"});
|
|
Void::Testing::expect_eq(shortener.health().status,
|
|
Void::ShortUrl::HealthStatus::healthy);
|
|
|
|
auto result = shortener.shorten({.target_url = "https://example.com/a"});
|
|
Void::Testing::expect(result.ok());
|
|
Void::Testing::expect_eq(result.key, std::string{"Ab3dE5fG7h"});
|
|
}
|
|
|
|
Void::Testing::Test short_url_resolution_is_optional()
|
|
{
|
|
Shortener shortener;
|
|
auto result = shortener.resolve({.key = "Ab3dE5fG7h"});
|
|
Void::Testing::expect(!result.ok());
|
|
Void::Testing::expect_eq(result.error.code,
|
|
Void::ShortUrl::ErrorCode::unsupported);
|
|
}
|