-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8268449
commit 138bd6b
Showing
3 changed files
with
237 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,54 +6,54 @@ | |
using namespace realm; | ||
|
||
TEST_CASE("app", "[sync]") { | ||
// auto app = realm::App(realm::App::configuration({Admin::shared().cached_app_id(), Admin::shared().base_url()})); | ||
// | ||
// SECTION("get_current_user") { | ||
// auto user = app.login(realm::App::credentials::anonymous()).get(); | ||
// | ||
// auto user_from_app = app.get_current_user(); | ||
// CHECK(user_from_app); | ||
// | ||
// CHECK(user.state() == realm::user::state::logged_in); | ||
// CHECK(user_from_app->state() == realm::user::state::logged_in); | ||
// CHECK(user_from_app->is_logged_in()); | ||
// CHECK(user == user_from_app); | ||
// | ||
// app.register_user("[email protected]", "foobar").get(); | ||
// auto user2 = app.login(realm::App::credentials::username_password("[email protected]", "foobar")).get(); | ||
// CHECK(user2 != user_from_app); | ||
// | ||
// user.log_out().get(); | ||
// user = app.login(realm::App::credentials::anonymous()).get(); | ||
// user_from_app = app.get_current_user(); | ||
// CHECK(user == user_from_app); | ||
// } | ||
// | ||
// SECTION("clear_cached_apps") { | ||
// auto temp_app_id = Admin::shared().create_app({"str_col", "_id"}); | ||
// auto temp_app = realm::App(realm::App::configuration({temp_app_id, Admin::shared().base_url()})); | ||
// auto cached_app = temp_app.get_cached_app(temp_app_id, Admin::shared().base_url()); | ||
// CHECK(cached_app.has_value()); | ||
// app.clear_cached_apps(); | ||
// cached_app = temp_app.get_cached_app(temp_app_id, Admin::shared().base_url()); | ||
// CHECK(cached_app.has_value() == false); | ||
// } | ||
|
||
// SECTION("error handling") { | ||
// auto dead_app = realm::App(realm::App::configuration({"NA", Admin::shared().base_url()})); | ||
// REQUIRE_THROWS_AS(dead_app.login(realm::App::credentials::anonymous()).get(), realm::app_error); | ||
// REQUIRE_THROWS_AS(dead_app.register_user("", "").get(), realm::app_error); | ||
// | ||
// std::promise<realm::app_error> error_promise; | ||
// std::future<realm::app_error> future = error_promise.get_future(); | ||
// dead_app.login(realm::App::credentials::anonymous(), [&](realm::user, std::optional<realm::app_error> e) mutable { | ||
// CHECK(e); | ||
// error_promise.set_value(*e); | ||
// }); | ||
// CHECK(future.get().message().find("404 message: cannot find app using Client App ID 'NA'")); | ||
// | ||
// auto user = app.login(realm::App::credentials::anonymous()).get(); | ||
// user.log_out().get(); | ||
// REQUIRE_THROWS(user.log_out().get()); | ||
// } | ||
auto app = realm::App(realm::App::configuration({Admin::shared().cached_app_id(), Admin::shared().base_url()})); | ||
|
||
SECTION("get_current_user") { | ||
auto user = app.login(realm::App::credentials::anonymous()).get(); | ||
|
||
auto user_from_app = app.get_current_user(); | ||
CHECK(user_from_app); | ||
|
||
CHECK(user.state() == realm::user::state::logged_in); | ||
CHECK(user_from_app->state() == realm::user::state::logged_in); | ||
CHECK(user_from_app->is_logged_in()); | ||
CHECK(user == user_from_app); | ||
|
||
app.register_user("[email protected]", "foobar").get(); | ||
auto user2 = app.login(realm::App::credentials::username_password("[email protected]", "foobar")).get(); | ||
CHECK(user2 != user_from_app); | ||
|
||
user.log_out().get(); | ||
user = app.login(realm::App::credentials::anonymous()).get(); | ||
user_from_app = app.get_current_user(); | ||
CHECK(user == user_from_app); | ||
} | ||
|
||
SECTION("clear_cached_apps") { | ||
auto temp_app_id = Admin::shared().create_app({"str_col", "_id"}); | ||
auto temp_app = realm::App(realm::App::configuration({temp_app_id, Admin::shared().base_url()})); | ||
auto cached_app = temp_app.get_cached_app(temp_app_id, Admin::shared().base_url()); | ||
CHECK(cached_app.has_value()); | ||
app.clear_cached_apps(); | ||
cached_app = temp_app.get_cached_app(temp_app_id, Admin::shared().base_url()); | ||
CHECK(cached_app.has_value() == false); | ||
} | ||
|
||
SECTION("error handling") { | ||
auto dead_app = realm::App(realm::App::configuration({"NA", Admin::shared().base_url()})); | ||
REQUIRE_THROWS_AS(dead_app.login(realm::App::credentials::anonymous()).get(), realm::app_error); | ||
REQUIRE_THROWS_AS(dead_app.register_user("", "").get(), realm::app_error); | ||
|
||
std::promise<realm::app_error> error_promise; | ||
std::future<realm::app_error> future = error_promise.get_future(); | ||
dead_app.login(realm::App::credentials::anonymous(), [&](realm::user, std::optional<realm::app_error> e) mutable { | ||
CHECK(e); | ||
error_promise.set_value(*e); | ||
}); | ||
CHECK(future.get().message().find("404 message: cannot find app using Client App ID 'NA'")); | ||
|
||
auto user = app.login(realm::App::credentials::anonymous()).get(); | ||
user.log_out().get(); | ||
REQUIRE_THROWS(user.log_out().get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.