From 9332f60a4370cc5ec9a000ef505e613f84b17d2f Mon Sep 17 00:00:00 2001 From: Derf Null Date: Wed, 31 May 2023 22:16:27 +0200 Subject: prepare for follow relations and follow-only checkins --- t/21-relations.t | 375 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 375 insertions(+) create mode 100644 t/21-relations.t (limited to 't/21-relations.t') diff --git a/t/21-relations.t b/t/21-relations.t new file mode 100644 index 0000000..d34e3ea --- /dev/null +++ b/t/21-relations.t @@ -0,0 +1,375 @@ +#!/usr/bin/env perl + +# Copyright (C) 2023 Birthe Friesel +# +# SPDX-License-Identifier: MIT + +use Mojo::Base -strict; + +# Tests journey entry and statistics + +use Test::More; +use Test::Mojo; + +# Include application +use FindBin; +require "$FindBin::Bin/../index.pl"; + +my $t = Test::Mojo->new('Travelynx'); + +if ( not $t->app->config->{db} ) { + plan( skip_all => 'No database configured' ); +} + +$t->app->pg->db->query('drop schema if exists travelynx_test_21 cascade'); +$t->app->pg->db->query('create schema travelynx_test_21'); +$t->app->pg->db->query('set search_path to travelynx_test_21'); +$t->app->pg->on( + connection => sub { + my ( $pg, $dbh ) = @_; + $dbh->do('set search_path to travelynx_test_21'); + } +); + +$t->app->config->{mail}->{disabled} = 1; + +$t->app->start( 'database', 'migrate' ); + +my $u = $t->app->users; + +my $uid1 = $u->add( + name => 'test1', + email => 'test1@example.org', + token => 'abcd', + password => q{}, +); + +my $uid2 = $u->add( + name => 'test2', + email => 'test2@example.org', + token => 'efgh', + password => q{}, +); + +$u->verify_registration_token( + uid => $uid1, + token => 'abcd' +); +$u->verify_registration_token( + uid => $uid2, + token => 'efgh' +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + undef +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); + +$u->request_follow( + uid => $uid1, + target => $uid2 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + 'requests_follow' +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 1 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is_deeply( + [ $u->get_follow_requests( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); + +$u->reject_follow_request( + uid => $uid2, + applicant => $uid1 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + undef +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); + +$u->request_follow( + uid => $uid1, + target => $uid2 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + 'requests_follow' +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 1 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is_deeply( + [ $u->get_follow_requests( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); + +$u->accept_follow_request( + uid => $uid2, + applicant => $uid1 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + 'follows' +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 1 ); +is( scalar $u->get_followees( uid => $uid1 ), 1 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); +is_deeply( + [ $u->get_followers( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); +is_deeply( + [ $u->get_followees( uid => $uid1 ) ], + [ { id => $uid2, name => 'test2' } ] +); + +$u->remove_follower( + uid => $uid2, + follower => $uid1 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + undef +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); + +$u->request_follow( + uid => $uid1, + target => $uid2 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + 'requests_follow' +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); + +$u->block( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + 'is_blocked_by' +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 1 ); +is_deeply( + [ $u->get_blocked_users( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); + +$u->unblock( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + undef +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 0 ); + +$u->block( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + 'is_blocked_by' +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); +is( scalar $u->get_followers( uid => $uid1 ), 0 ); +is( scalar $u->get_followers( uid => $uid2 ), 0 ); +is( scalar $u->get_followees( uid => $uid1 ), 0 ); +is( scalar $u->get_followees( uid => $uid2 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid1 ), 0 ); +is( scalar $u->get_follow_requests( uid => $uid2 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid1 ), 0 ); +is( scalar $u->get_blocked_users( uid => $uid2 ), 1 ); +is_deeply( + [ $u->get_blocked_users( uid => $uid2 ) ], + [ { id => $uid1, name => 'test1' } ] +); + +$u->unblock( + uid => $uid2, + target => $uid1 +); + +is( + $u->get_relation( + uid => $uid1, + target => $uid2 + ), + undef +); +is( + $u->get_relation( + uid => $uid2, + target => $uid1 + ), + undef +); + +$t->app->pg->db->query('drop schema travelynx_test_21 cascade'); +done_testing(); -- cgit v1.2.3