blob: d1f41a5b44b7cb056db3e55479d05204e96458f3 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <httplib.h>
#include <memory>
#include <iostream>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <mw/test_utils.hpp>
#include <mw/http_client.hpp>
#include <mw/auth_mock.hpp>
#include "app.hpp"
#include "config.hpp"
#include "data.hpp"
#include "data_mock.hpp"
using ::testing::_;
using ::testing::Return;
using ::testing::HasSubstr;
using ::testing::FieldsAre;
using ::testing::ContainsRegex;
class UserAppTest : public testing::Test
{
protected:
UserAppTest()
{
config.base_url = "http://localhost:8080/";
config.listen_address = "localhost";
config.listen_port = 8080;
config.data_dir = ".";
auto auth = std::make_unique<mw::AuthMock>();
mw::UserInfo expected_user;
expected_user.name = "mw";
expected_user.id = "mw";
mw::Tokens token;
token.access_token = "aaa";
EXPECT_CALL(*auth, getUser(std::move(token)))
.Times(::testing::AtLeast(0))
.WillRepeatedly(Return(expected_user));
auto data = std::make_unique<DataSourceMock>();
data_source = data.get();
app = std::make_unique<App>(config, std::move(data), std::move(auth));
}
Configuration config;
std::unique_ptr<App> app;
const DataSourceMock* data_source;
};
TEST_F(UserAppTest, CanShowItemsOfDefaultUser)
{
EXPECT_TRUE(mw::isExpected(app->start()));
{
mw::HTTPSession client;
ASSIGN_OR_FAIL(const mw::HTTPResponse* res, client.get(
mw::HTTPRequest("http://localhost:8080/")));
EXPECT_EQ(res->status, 301);
EXPECT_EQ(res->header.at("Location"), "http://localhost:8080/mw");
}
app->stop();
app->wait();
}
|