diff --git a/test/sumo_test_user.erl b/test/sumo_test_user.erl new file mode 100644 index 0000000..76cd23f --- /dev/null +++ b/test/sumo_test_user.erl @@ -0,0 +1,52 @@ +-module(sumo_test_user). + +-behaviour(sumo_doc). + +-type user() :: #{id => binary(), + attributes => list()}. + +%% API +-export([ + new/2, + id/1, + attributes/1 +]). + +%% sumo_doc callbacks +-export([sumo_schema/0, sumo_wakeup/1, sumo_sleep/1]). + +%%%============================================================================= +%%% sumo_doc callbacks +%%%============================================================================= + +-spec sumo_schema() -> sumo:schema(). +sumo_schema() -> + sumo:new_schema(users, [ + sumo:new_field(id, string, [id, not_null]), + sumo:new_field(attributes, custom, [{type, list}]) + ]). + +-spec sumo_sleep(user()) -> sumo:model(). +sumo_sleep(User) -> + User. + +-spec sumo_wakeup(sumo:model()) -> user(). +sumo_wakeup(Doc) -> + Doc. + +%%%============================================================================= +%%% API +%%%============================================================================= + +-spec new(binary(), list()) -> user(). +new(Id, Attributes) -> + #{id => Id, + attributes => Attributes}. + +-spec id(user()) -> string(). +id(#{id := Val}) -> + Val. + +-spec attributes(user()) -> list(). +attributes(#{attributes := Val}) -> + Val. diff --git a/test/test.config b/test/test.config index e1435ff..51662ae 100644 --- a/test/test.config +++ b/test/test.config @@ -25,7 +25,8 @@ ]}, {docs, [ {people, sumo_test_riak, #{module => sumo_test_people_riak}}, - {purchases, sumo_test_riak, #{module => sumo_test_purchase_order}} + {purchases, sumo_test_riak, #{module => sumo_test_purchase_order}}, + {users, sumo_test_riak, #{module => sumo_test_user}} ]}, {events, [ diff --git a/test/users_SUITE.erl b/test/users_SUITE.erl new file mode 100644 index 0000000..5935fa1 --- /dev/null +++ b/test/users_SUITE.erl @@ -0,0 +1,43 @@ +-module(users_SUITE). + +%% CT +-export([ + all/0, + init_per_suite/1, + end_per_suite/1, + find/1 +]). + +-type config() :: [{atom(), term()}]. + +%%%============================================================================= +%%% Common Test +%%%============================================================================= + +-spec all() -> [atom()]. +all() -> + [find]. + +-spec init_per_suite(config()) -> config(). +init_per_suite(Config) -> + {ok, _} = application:ensure_all_started(sumo_db_riak), + Config. + +-spec end_per_suite(config()) -> config(). +end_per_suite(Config) -> + sumo:delete_all(users), + ok = sumo_db_riak:stop(), + Config. + +-spec find(config()) -> ok. +find(_Config) -> + Id1 = <<"first">>, + Id2 = <<"second">>, + User1 = sumo_test_user:new(Id1, [#{this => is_a_map}, #{this => is_another}]), + User2 = sumo_test_user:new(Id2, ["A", "B"]), + sumo:persist(users, User1), + sumo:persist(users, User2), + + User1 = sumo:fetch(users, Id1), + User2 = sumo:fetch(users, Id2), + ok.