summaryrefslogtreecommitdiff
path: root/include/ut/http_utility_test.cpp
blob: 1a33fd8648fb3539f7c06f6b8755162bfb20e883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "http_utility.hpp"

#include <gtest/gtest.h> // IWYU pragma: keep

// IWYU pragma: no_include <gtest/gtest-message.h>
// IWYU pragma: no_include <gtest/gtest-test-part.h>
// IWYU pragma: no_include "gtest/gtest_pred_impl.h"

namespace http_helpers
{
namespace
{

TEST(RequestPrefersHtml, ContainsHtmlReturnsTrue)
{
    EXPECT_TRUE(requestPrefersHtml("text/html, application/json"));
}

TEST(RequestPrefersHtml, NoHtmlReturnsFalse)
{
    EXPECT_FALSE(requestPrefersHtml("*/*, application/octet-stream"));
    EXPECT_FALSE(requestPrefersHtml("application/json"));
}

TEST(IsOctetAccepted, ContainsOctetReturnsTrue)
{
    EXPECT_TRUE(isOctetAccepted("*/*, application/octet-stream"));
}

TEST(IsOctetAccepted, ContainsAnyMimeTypeReturnsTrue)
{
    EXPECT_TRUE(http_helpers::isOctetAccepted("text/html, */*"));
}

TEST(IsOctetAccepted, ContainsQFactorWeightingReturnsTrue)
{
    EXPECT_TRUE(http_helpers::isOctetAccepted("text/html, */*;q=0.8"));
}

TEST(IsOctetAccepted, NoOctetReturnsFalse)
{
    EXPECT_FALSE(isOctetAccepted("text/html, application/json"));
    EXPECT_FALSE(isOctetAccepted("application/json"));
}

} // namespace
} // namespace http_helpers