Skip to content

Commit

Permalink
test: add test for logout
Browse files Browse the repository at this point in the history
  • Loading branch information
drawbu committed Apr 15, 2024
1 parent faa970f commit f1834f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/server/cmds/cmd_logout.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ void cmd_logout(server_t *server, client_t *client)
char uuid_str[37] = {0};
user_info_t info = {0};

uuid_unparse(client->thread_uuid, uuid_str);
if (client->user == NULL)
return;
uuid_unparse(client->user->uuid, uuid_str);
server_event_user_logged_out(uuid_str);
strcpy(info.user_name, client->user->name);
uuid_copy(info.user_uuid, client->user->uuid);
Expand Down
39 changes: 35 additions & 4 deletions tests/test_login.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from server import run_server
from pprint import pprint


def test_login():
name = "bob"
serv, cli = run_server([f'/login "{name}"\n'])
print(serv, cli)
serv, cli = run_server([
f'/login "{name}"\n',
])
pprint(serv)
pprint(cli)

assert serv[0][0] == "server_event_user_created"
uuid = serv[0][1]
Expand All @@ -15,6 +19,33 @@ def test_login():
assert cli[0][2] == name


def test_logout():
name = "bob"
serv, cli = run_server([
f'/login "{name}"\n',
'/logout\n',
])
pprint(serv)
pprint(cli)

# login
assert serv[0][0] == "server_event_user_created"
uuid = serv[0][1]
assert serv[0][2] == name

assert cli[0][0] == "client_event_logged_in"
assert cli[0][1] == uuid
assert cli[0][2] == name

# logout

assert serv[1][0] == "server_event_user_logged_out"
assert serv[1][1] == uuid

assert cli[1][0] == "client_event_logged_out"
assert cli[1][1] == uuid
assert cli[1][2] == name


if __name__ == "__main__":
serv, cli = run_server(['/login "uwu"\n'])
print(serv, cli)
test_logout()

0 comments on commit f1834f5

Please sign in to comment.