{"action":"created","comment":{"url":"https://api.github.com/repos/matrix-org/sytest/pulls/comments/43759199","id":43759199,"diff_hunk":"@@ -0,0 +1,355 @@\n+push our @EXPORT, qw( matrix_add_tag );\n+\n+=head2 matrix_add_tag\n+\n+   matrix_add_tag($user, $room_id, $tag)->get;\n+\n+Add a tag to the room for the user.\n+\n+=cut\n+\n+sub matrix_add_tag\n+{\n+   my ( $user, $room_id, $tag, $content ) = @_;\n+\n+   do_request_json_for( $user,\n+      method  => \"PUT\",\n+      uri     => \"/v2_alpha/user/:user_id/rooms/$room_id/tags/$tag\",\n+      content => $content\n+   );\n+}\n+\n+\n+=head2 matrix_remove_tag\n+\n+    matrix_remove_tag( $user, $room_id, $tag )->get;\n+\n+Remove a tag from the room for the user.\n+\n+=cut\n+\n+sub matrix_remove_tag\n+{\n+   my ( $user, $room_id, $tag ) = @_;\n+\n+   do_request_json_for( $user,\n+      method  => \"DELETE\",\n+      uri     => \"/v2_alpha/user/:user_id/rooms/$room_id/tags/$tag\",\n+      content => {}\n+   );\n+}\n+\n+\n+=head2 matrix_list_tags\n+\n+    my $tags = matrix_list_tags( $user, $room_id )->get;\n+\n+List the tags on the room for the user.\n+\n+=cut\n+\n+sub matrix_list_tags\n+{\n+   my ( $user, $room_id, $content) = @_;\n+\n+   do_request_json_for( $user,\n+      method  => \"GET\",\n+      uri     => \"/v2_alpha/user/:user_id/rooms/$room_id/tags\",\n+   )->then( sub {\n+      my ( $body ) = @_;\n+\n+      require_json_keys( $body, qw( tags ) );\n+\n+      Future->done( $body->{tags} );\n+   });\n+}\n+\n+\n+test \"Can add tag\",\n+   requires => [qw( first_api_client )],\n+\n+   provides => [qw( can_add_tag )],\n+\n+   do => sub {\n+      my ( $http ) = @_;\n+\n+      my ( $user, $room_id );\n+\n+      matrix_register_user( $http, undef, with_events => 0 )->then( sub {\n+         ( $user ) = @_;\n+\n+         matrix_create_room( $user );\n+      })->then( sub {\n+         ( $room_id ) = @_;\n+\n+         matrix_add_tag( $user, $room_id, \"test_tag\", {} );\n+      })->on_done( sub {\n+         provide can_add_tag => 1\n+      });\n+   };\n+\n+\n+test \"Can remove tag\",\n+   requires => [qw( first_api_client )],\n+\n+   provides => [qw( can_remove_tag )],\n+\n+   do => sub {\n+      my ( $http ) = @_;\n+\n+      my ( $user, $room_id );\n+\n+      matrix_register_user( $http, undef, with_events => 0 )->then( sub {\n+         ( $user ) = @_;\n+\n+         matrix_create_room( $user );\n+      })->then( sub {\n+         ( $room_id ) = @_;\n+\n+         matrix_remove_tag( $user, $room_id, \"test_tag\" );\n+      })->on_done( sub {\n+         provide can_remove_tag => 1\n+      });\n+   };\n+\n+\n+test \"Can list tags for a room\",\n+   requires => [qw( first_api_client can_add_tag can_remove_tag )],\n+\n+   do => sub {\n+      my ( $http ) = @_;\n+\n+      my ( $user, $room_id );\n+\n+      matrix_register_user( $http, undef, with_events => 0 )->then( sub {\n+         ( $user ) = @_;\n+\n+         matrix_create_room( $user );\n+      })->then( sub {\n+         ( $room_id ) = @_;\n+\n+         matrix_add_tag( $user, $room_id, \"test_tag\", {} );\n+      })->then( sub {\n+         matrix_list_tags( $user, $room_id );\n+      })->then( sub {\n+         my ( $tags ) = @_;\n+\n+         keys %{ $tags } == 1 or die \"Expected one tag for the room\";\n+         defined $tags->{test_tag} or die \"Unexpected tag\";\n+\n+         matrix_remove_tag( $user, $room_id, \"test_tag\" );\n+      })->then( sub {\n+         matrix_list_tags( $user, $room_id );\n+      })->then( sub {\n+         my ( $tags ) = @_;\n+\n+         keys %{ $tags } == 0 or die \"Expected no tags for the room\";\n+\n+         Future->done(1);\n+      });\n+   };\n+\n+\n+test \"Tags appear in the v1 /events stream\",\n+   requires => [qw( first_api_client can_add_tag can_remove_tag )],\n+\n+   do => sub {\n+      my ( $http ) = @_;\n+\n+      my ( $user, $room_id );\n+\n+      matrix_register_user( $http, undef )->then( sub {\n+         ( $user ) = @_;\n+\n+         matrix_create_room( $user );\n+      })->then( sub {\n+         ( $room_id ) = @_;\n+\n+         matrix_add_tag( $user, $room_id, \"test_tag\", { order => 1 } );\n+      })->then( sub {\n+         await_event_for( $user, sub {\n+            my ( $event ) = @_;\n+            return unless $event->{type} eq \"m.tag\"\n+               and $event->{room_id} eq $room_id;\n+\n+            my %tags = %{ $event->{content}{tags} };\n+            keys %tags == 1 or die \"Expected exactly one tag\";\n+            defined $tags{test_tag} or die \"Unexpected tag\";\n+            $tags{test_tag}{order} == 1 or die \"Expected order == 1\";\n+\n+            return 1;\n+         });\n+      });\n+   };\n+\n+\n+test \"Tags appear in the v1 /initalSync\",\n+   requires => [qw( first_api_client can_add_tag can_remove_tag )],\n+\n+   do => sub {\n+      my ( $http ) = @_;\n+\n+      my ( $user, $room_id );\n+\n+      matrix_register_user( $http, undef, with_events => 0 )->then( sub {\n+         ( $user ) = @_;\n+\n+         matrix_create_room( $user );\n+      })->then( sub {\n+         ( $room_id ) = @_;\n+\n+         matrix_add_tag( $user, $room_id, \"test_tag\", { order => 1 } );\n+      })->then( sub {\n+         do_request_json_for( $user,\n+            method => \"GET\",\n+            uri    => \"/api/v1/initialSync\"\n+        );\n+      })->then( sub {\n+         my ( $body ) = @_;\n+","path":"tests/42tags.pl","position":252,"original_position":209,"commit_id":"6e04b07b917047dc72bb4bf9527cbeb7e830da2b","original_commit_id":"7823c53a6038089b20b2af232982c5ecc01f6564","user":{"login":"illicitonion","id":1131704,"avatar_url":"https://avatars.githubusercontent.com/u/1131704?v=3","gravatar_id":"","url":"https://api.github.com/users/illicitonion","html_url":"https://github.com/illicitonion","followers_url":"https://api.github.com/users/illicitonion/followers","following_url":"https://api.github.com/users/illicitonion/following{/other_user}","gists_url":"https://api.github.com/users/illicitonion/gists{/gist_id}","starred_url":"https://api.github.com/users/illicitonion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/illicitonion/subscriptions","organizations_url":"https://api.github.com/users/illicitonion/orgs","repos_url":"https://api.github.com/users/illicitonion/repos","events_url":"https://api.github.com/users/illicitonion/events{/privacy}","received_events_url":"https://api.github.com/users/illicitonion/received_events","type":"User","site_admin":false},"body":"Yes please!","created_at":"2015-11-03T15:15:28Z","updated_at":"2015-11-03T15:15:28Z","html_url":"https://github.com/matrix-org/sytest/pull/34#discussion_r43759199","pull_request_url":"https://api.github.com/repos/matrix-org/sytest/pulls/34","_links":{"self":{"href":"https://api.github.com/repos/matrix-org/sytest/pulls/comments/43759199"},"html":{"href":"https://github.com/matrix-org/sytest/pull/34#discussion_r43759199"},"pull_request":{"href":"https://api.github.com/repos/matrix-org/sytest/pulls/34"}}},"pull_request":{"url":"https://api.github.com/repos/matrix-org/sytest/pulls/34","id":49030982,"html_url":"https://github.com/matrix-org/sytest/pull/34","diff_url":"https://github.com/matrix-org/sytest/pull/34.diff","patch_url":"https://github.com/matrix-org/sytest/pull/34.patch","issue_url":"https://api.github.com/repos/matrix-org/sytest/issues/34","number":34,"state":"open","locked":false,"title":"Test API for adding and removing tags","user":{"login":"NegativeMjark","id":904009,"avatar_url":"https://avatars.githubusercontent.com/u/904009?v=3","gravatar_id":"","url":"https://api.github.com/users/NegativeMjark","html_url":"https://github.com/NegativeMjark","followers_url":"https://api.github.com/users/NegativeMjark/followers","following_url":"https://api.github.com/users/NegativeMjark/following{/other_user}","gists_url":"https://api.github.com/users/NegativeMjark/gists{/gist_id}","starred_url":"https://api.github.com/users/NegativeMjark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NegativeMjark/subscriptions","organizations_url":"https://api.github.com/users/NegativeMjark/orgs","repos_url":"https://api.github.com/users/NegativeMjark/repos","events_url":"https://api.github.com/users/NegativeMjark/events{/privacy}","received_events_url":"https://api.github.com/users/NegativeMjark/received_events","type":"User","site_admin":false},"body":"Test changes made in matrix-org/synapse#335\r\n\r\nTODO:\r\n\r\n * [x] Add tests for getting tags in v1 /initialSync\r\n * [x] Add tests for getting tags in v1 /events\r\n * [x] Add tests for getting tags in v2 /sync","created_at":"2015-10-28T16:29:23Z","updated_at":"2015-11-03T15:15:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b463cffd7c89236c7e05caadead8732235a31342","assignee":{"login":"illicitonion","id":1131704,"avatar_url":"https://avatars.githubusercontent.com/u/1131704?v=3","gravatar_id":"","url":"https://api.github.com/users/illicitonion","html_url":"https://github.com/illicitonion","followers_url":"https://api.github.com/users/illicitonion/followers","following_url":"https://api.github.com/users/illicitonion/following{/other_user}","gists_url":"https://api.github.com/users/illicitonion/gists{/gist_id}","starred_url":"https://api.github.com/users/illicitonion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/illicitonion/subscriptions","organizations_url":"https://api.github.com/users/illicitonion/orgs","repos_url":"https://api.github.com/users/illicitonion/repos","events_url":"https://api.github.com/users/illicitonion/events{/privacy}","received_events_url":"https://api.github.com/users/illicitonion/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/matrix-org/sytest/pulls/34/commits","review_comments_url":"https://api.github.com/repos/matrix-org/sytest/pulls/34/comments","review_comment_url":"https://api.github.com/repos/matrix-org/sytest/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matrix-org/sytest/issues/34/comments","statuses_url":"https://api.github.com/repos/matrix-org/sytest/statuses/6e04b07b917047dc72bb4bf9527cbeb7e830da2b","head":{"label":"matrix-org:markjh/room_tags","ref":"markjh/room_tags","sha":"6e04b07b917047dc72bb4bf9527cbeb7e830da2b","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":23436169,"name":"sytest","full_name":"matrix-org/sytest","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/sytest","description":"Black-box integration testing for Matrix homeservers","fork":false,"url":"https://api.github.com/repos/matrix-org/sytest","forks_url":"https://api.github.com/repos/matrix-org/sytest/forks","keys_url":"https://api.github.com/repos/matrix-org/sytest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/sytest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/sytest/teams","hooks_url":"https://api.github.com/repos/matrix-org/sytest/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/sytest/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/sytest/events","assignees_url":"https://api.github.com/repos/matrix-org/sytest/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/sytest/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/sytest/tags","blobs_url":"https://api.github.com/repos/matrix-org/sytest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/sytest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/sytest/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/sytest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/sytest/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/sytest/languages","stargazers_url":"https://api.github.com/repos/matrix-org/sytest/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/sytest/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/sytest/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/sytest/subscription","commits_url":"https://api.github.com/repos/matrix-org/sytest/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/sytest/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/sytest/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/sytest/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/sytest/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/sytest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/sytest/merges","archive_url":"https://api.github.com/repos/matrix-org/sytest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/sytest/downloads","issues_url":"https://api.github.com/repos/matrix-org/sytest/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/sytest/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/sytest/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/sytest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/sytest/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/sytest/releases{/id}","created_at":"2014-08-28T17:05:43Z","updated_at":"2015-05-26T09:36:45Z","pushed_at":"2015-11-03T15:05:54Z","git_url":"git://github.com/matrix-org/sytest.git","ssh_url":"git@github.com:matrix-org/sytest.git","clone_url":"https://github.com/matrix-org/sytest.git","svn_url":"https://github.com/matrix-org/sytest","homepage":"","size":3103,"stargazers_count":2,"watchers_count":2,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":2,"default_branch":"develop"}},"base":{"label":"matrix-org:develop","ref":"develop","sha":"fbf71bcb4a94c539eda257179366261ac918bd71","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":23436169,"name":"sytest","full_name":"matrix-org/sytest","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/sytest","description":"Black-box integration testing for Matrix homeservers","fork":false,"url":"https://api.github.com/repos/matrix-org/sytest","forks_url":"https://api.github.com/repos/matrix-org/sytest/forks","keys_url":"https://api.github.com/repos/matrix-org/sytest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/sytest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/sytest/teams","hooks_url":"https://api.github.com/repos/matrix-org/sytest/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/sytest/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/sytest/events","assignees_url":"https://api.github.com/repos/matrix-org/sytest/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/sytest/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/sytest/tags","blobs_url":"https://api.github.com/repos/matrix-org/sytest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/sytest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/sytest/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/sytest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/sytest/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/sytest/languages","stargazers_url":"https://api.github.com/repos/matrix-org/sytest/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/sytest/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/sytest/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/sytest/subscription","commits_url":"https://api.github.com/repos/matrix-org/sytest/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/sytest/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/sytest/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/sytest/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/sytest/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/sytest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/sytest/merges","archive_url":"https://api.github.com/repos/matrix-org/sytest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/sytest/downloads","issues_url":"https://api.github.com/repos/matrix-org/sytest/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/sytest/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/sytest/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/sytest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/sytest/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/sytest/releases{/id}","created_at":"2014-08-28T17:05:43Z","updated_at":"2015-05-26T09:36:45Z","pushed_at":"2015-11-03T15:05:54Z","git_url":"git://github.com/matrix-org/sytest.git","ssh_url":"git@github.com:matrix-org/sytest.git","clone_url":"https://github.com/matrix-org/sytest.git","svn_url":"https://github.com/matrix-org/sytest","homepage":"","size":3103,"stargazers_count":2,"watchers_count":2,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":2,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/matrix-org/sytest/pulls/34"},"html":{"href":"https://github.com/matrix-org/sytest/pull/34"},"issue":{"href":"https://api.github.com/repos/matrix-org/sytest/issues/34"},"comments":{"href":"https://api.github.com/repos/matrix-org/sytest/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/matrix-org/sytest/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/matrix-org/sytest/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matrix-org/sytest/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/matrix-org/sytest/statuses/6e04b07b917047dc72bb4bf9527cbeb7e830da2b"}}}}