Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F13522564
device-ops-test.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
device-ops-test.cpp
View Options
/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include
<libkazv-config.hpp>
#include
<catch2/catch_test_macros.hpp>
#include
<catch2/matchers/catch_matchers_predicate.hpp>
#include
<catch2/matchers/catch_matchers_contains.hpp>
#include
<boost/asio.hpp>
#include
<asio-promise-handler.hpp>
#include
<cursorutil.hpp>
#include
<sdk-model.hpp>
#include
<client/client.hpp>
#include
"client-test-util.hpp"
static
auto
addDeviceToModel
(
ClientModel
&
model
,
std
::
string
userId
,
std
::
string
deviceId
,
std
::
string
displayName
)
{
DeviceKeyInfo
info
{
deviceId
,
deviceId
+
"ed25519"
,
deviceId
+
"curve25519"
,
displayName
,
};
model
.
deviceLists
.
deviceLists
=
std
::
move
(
model
.
deviceLists
.
deviceLists
)
.
update
(
userId
,
[
=
](
auto
deviceMap
)
{
return
std
::
move
(
deviceMap
).
set
(
deviceId
,
info
);
});
return
model
;
}
static
auto
getModel
()
{
auto
model
=
createTestClientModel
();
addDeviceToModel
(
model
,
"@test1:test1.org"
,
"device1"
,
"test1-device1"
);
addDeviceToModel
(
model
,
"@test1:test1.org"
,
"device2"
,
"test1-device2"
);
return
model
;
}
using
namespace
Kazv
::
CursorOp
;
using
namespace
Catch
::
Matchers
;
TEST_CASE
(
"devicesOfUser()"
,
"[client][device-list-tracker]"
)
{
boost
::
asio
::
io_context
io
;
AsioPromiseHandler
ph
{
io
.
get_executor
()};
auto
model
=
getModel
();
auto
store
=
createTestClientStoreFrom
(
model
,
ph
);
auto
client
=
Client
(
store
.
reader
().
map
([](
auto
c
)
{
return
SdkModel
{
c
};
}),
store
,
std
::
nullopt
);
auto
devices
=
+
client
.
devicesOfUser
(
"@test1:test1.org"
);
REQUIRE
(
devices
.
size
()
==
2
);
REQUIRE_THAT
(
devices
,
Contains
(
Predicate
<
DeviceKeyInfo
>
([](
auto
d
)
{
return
d
.
deviceId
==
"device1"
;
})));
REQUIRE_THAT
(
devices
,
Contains
(
Predicate
<
DeviceKeyInfo
>
([](
auto
d
)
{
return
d
.
deviceId
==
"device2"
;
})));
}
TEST_CASE
(
"setTrustLevel()"
,
"[client][device-list-tracker]"
)
{
boost
::
asio
::
io_context
io
;
AsioPromiseHandler
ph
{
io
.
get_executor
()};
auto
model
=
getModel
();
auto
store
=
createTestClientStoreFrom
(
model
,
ph
);
auto
client
=
Client
(
store
.
reader
().
map
([](
auto
c
)
{
return
SdkModel
{
c
};
}),
store
,
std
::
nullopt
);
client
.
setDeviceTrustLevel
(
"@test1:test1.org"
,
"device1"
,
Seen
)
.
then
([
client
](
auto
s
)
{
REQUIRE
(
s
.
success
());
REQUIRE_THAT
((
+
client
.
devicesOfUser
(
"@test1:test1.org"
)),
Contains
(
Predicate
<
DeviceKeyInfo
>
([](
auto
d
)
{
return
d
.
deviceId
==
"device1"
&&
d
.
trustLevel
==
Seen
;
})));
});
io
.
run
();
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Dec 7, 9:09 PM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
700299
Default Alt Text
device-ops-test.cpp (2 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment