From 7678db6c5ff7089f2944ea1ec381071ce3fbf06f Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Wed, 3 Jul 2024 00:26:56 +0530 Subject: [PATCH 1/2] Fix test file name --- ballerina/tests/{test.bal => tests.bal} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ballerina/tests/{test.bal => tests.bal} (100%) diff --git a/ballerina/tests/test.bal b/ballerina/tests/tests.bal similarity index 100% rename from ballerina/tests/test.bal rename to ballerina/tests/tests.bal From 66dd0bc8528420dbe1a63254dad10694608b9c6b Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Wed, 3 Jul 2024 00:29:29 +0530 Subject: [PATCH 2/2] Fix formatting issues in test sources --- ballerina/tests/mock_service.bal | 60 ++++++++++++++++---------------- ballerina/tests/tests.bal | 38 ++++++++++---------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 01184f3..806262f 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -20,17 +20,17 @@ import ballerina/log; listener http:Listener httpListener = new (9090); http:Service mockService = service object { - + # Remove a bookmarked Post # # + id - The ID of the authenticated source User whose bookmark is to be removed. # + tweet_id - The ID of the Post that the source User is removing from bookmarks. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function delete users/[UserIdMatchesAuthenticatedUser id]/bookmarks/[TweetId tweet_id]() returns BookmarkMutationResponse|http:Response { return { - "data":{"bookmarked":false} + "data": {"bookmarked": false} }; } @@ -38,12 +38,12 @@ http:Service mockService = service object { # # + id - The ID of the authenticated source User that is requesting to unlike the Post. # + tweet_id - The ID of the Post that the User is requesting to unlike. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function delete users/[UserIdMatchesAuthenticatedUser id]/likes/[TweetId tweet_id]() returns UsersLikesDeleteResponse|http:Response { return { - "data":{"liked":false} + "data": {"liked": false} }; } @@ -51,12 +51,12 @@ http:Service mockService = service object { # # + id - The ID of the authenticated source User that is requesting to repost the Post. # + source_tweet_id - The ID of the Post that the User is requesting to unretweet. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function delete users/[UserIdMatchesAuthenticatedUser id]/retweets/[TweetId source_tweet_id]() returns UsersRetweetsDeleteResponse|http:Response { return { - "data":{"retweeted":false} + "data": {"retweeted": false} }; } @@ -64,12 +64,12 @@ http:Service mockService = service object { # # + source_user_id - The ID of the authenticated source User that is requesting to unfollow the target User. # + target_user_id - The ID of the User that the source User is requesting to unfollow. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function delete users/[UserIdMatchesAuthenticatedUser source_user_id]/following/[UserId target_user_id]() returns UsersFollowingDeleteResponse|http:Response { return { - "data":{"following":false} + "data": {"following": false} }; } @@ -77,12 +77,12 @@ http:Service mockService = service object { # # + source_user_id - The ID of the authenticated source User that is requesting to unmute the target User. # + target_user_id - The ID of the User that the source User is requesting to unmute. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function delete users/[UserIdMatchesAuthenticatedUser source_user_id]/muting/[UserId target_user_id]() returns MuteUserMutationResponse|http:Response { return { - "data":{"muting":false} + "data": {"muting": false} }; } @@ -95,104 +95,104 @@ http:Service mockService = service object { # + poll\.fields - A comma separated list of Poll fields to display. # + user\.fields - A comma separated list of User fields to display. # + place\.fields - A comma separated list of Place fields to display. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function get tweets/[TweetId id](("attachments"|"author_id"|"card_uri"|"context_annotations"|"conversation_id"|"created_at"|"edit_controls"|"edit_history_tweet_ids"|"entities"|"geo"|"id"|"in_reply_to_user_id"|"lang"|"non_public_metrics"|"note_tweet"|"organic_metrics"|"possibly_sensitive"|"promoted_metrics"|"public_metrics"|"referenced_tweets"|"reply_settings"|"scopes"|"source"|"text"|"username"|"withheld")[]? tweet\.fields, ("attachments.media_keys"|"attachments.media_source_tweet"|"attachments.poll_ids"|"author_id"|"edit_history_tweet_ids"|"entities.mentions.username"|"geo.place_id"|"in_reply_to_user_id"|"entities.note.mentions.username"|"referenced_tweets.id"|"referenced_tweets.id.author_id"|"author_screen_name")[]? expansions, ("alt_text"|"duration_ms"|"height"|"media_key"|"non_public_metrics"|"organic_metrics"|"preview_image_url"|"promoted_metrics"|"public_metrics"|"type"|"url"|"variants"|"width")[]? media\.fields, ("duration_minutes"|"end_datetime"|"id"|"options"|"voting_status")[]? poll\.fields, ("connection_status"|"created_at"|"description"|"entities"|"id"|"location"|"most_recent_tweet_id"|"name"|"pinned_tweet_id"|"profile_image_url"|"protected"|"public_metrics"|"receives_your_dm"|"subscription_type"|"url"|"username"|"verified"|"verified_type"|"withheld")[]? user\.fields, ("contained_within"|"country"|"country_code"|"full_name"|"geo"|"id"|"name"|"place_type")[]? place\.fields) returns Get2TweetsIdResponse|http:Response { return { - "data":{"edit_history_tweet_ids":["1806286701704462623"],"id":"1806286701704462623","text":"aasbcascbasjbc"} + "data": {"edit_history_tweet_ids": ["1806286701704462623"], "id": "1806286701704462623", "text": "aasbcascbasjbc"} }; } resource function get users/'by/username/[string username](("connection_status"|"created_at"|"description"|"entities"|"id"|"location"|"most_recent_tweet_id"|"name"|"pinned_tweet_id"|"profile_image_url"|"protected"|"public_metrics"|"receives_your_dm"|"subscription_type"|"url"|"username"|"verified"|"verified_type"|"withheld")[]? user\.fields, ("most_recent_tweet_id"|"pinned_tweet_id")[]? expansions, ("attachments"|"author_id"|"card_uri"|"context_annotations"|"conversation_id"|"created_at"|"edit_controls"|"edit_history_tweet_ids"|"entities"|"geo"|"id"|"in_reply_to_user_id"|"lang"|"non_public_metrics"|"note_tweet"|"organic_metrics"|"possibly_sensitive"|"promoted_metrics"|"public_metrics"|"referenced_tweets"|"reply_settings"|"scopes"|"source"|"text"|"username"|"withheld")[]? tweet\.fields) returns Get2UsersByUsernameUsernameResponse|http:Response { return { - "data":{"id":"350224247","name":"Kumar Sangakkara","username":"KumarSanga2"} + "data": {"id": "350224247", "name": "Kumar Sangakkara", "username": "KumarSanga2"} }; } # Creation of a Post # - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Created (The request has succeeded.) # http:Response (The request has failed.) resource function post tweets(@http:Payload TweetCreateRequest payload) returns TweetCreateResponse|http:Response { return { - "data":{"id":"1807808193139204482","text":"Twitter Test at[1719850035,0.227505100]","edit_history_tweet_ids":["1807808193139204482"]} + "data": {"id": "1807808193139204482", "text": "Twitter Test at[1719850035,0.227505100]", "edit_history_tweet_ids": ["1807808193139204482"]} }; } # Add Post to Bookmarks # # + id - The ID of the authenticated source User for whom to add bookmarks. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function post users/[UserIdMatchesAuthenticatedUser id]/bookmarks(@http:Payload BookmarkAddRequest payload) returns BookmarkMutationResponse|http:Response { return { - "data":{"bookmarked":true} + "data": {"bookmarked": true} }; } # Follow User # # + id - The ID of the authenticated source User that is requesting to follow the target User. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function post users/[UserIdMatchesAuthenticatedUser id]/following(@http:Payload UsersFollowingCreateRequest payload) returns UsersFollowingCreateResponse|http:Response { return { - "data":{"following":true,"pending_follow":false} + "data": {"following": true, "pending_follow": false} }; } # Causes the User (in the path) to like the specified Post # # + id - The ID of the authenticated source User that is requesting to like the Post. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function post users/[UserIdMatchesAuthenticatedUser id]/likes(@http:Payload UsersLikesCreateRequest payload) returns UsersLikesCreateResponse|http:Response { return { - "data":{"liked":true} + "data": {"liked": true} }; } # Mute User by User ID. # # + id - The ID of the authenticated source User that is requesting to mute the target User. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function post users/[UserIdMatchesAuthenticatedUser id]/muting(@http:Payload MuteUserRequest payload) returns MuteUserMutationResponse|http:Response { return { - "data":{"muting":true} + "data": {"muting": true} }; } # Causes the User (in the path) to repost the specified Post. # # + id - The ID of the authenticated source User that is requesting to repost the Post. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function post users/[UserIdMatchesAuthenticatedUser id]/retweets(@http:Payload UsersRetweetsCreateRequest payload) returns UsersRetweetsCreateResponse|http:Response { return { - "data":{"retweeted":true,"rest_id":"1807808194787590411"} + "data": {"retweeted": true, "rest_id": "1807808194787590411"} }; } - # User lookup by IDs + # User lookup by IDs # # + ids - A list of User IDs, comma-separated. You can specify up to 100 IDs. # + user\.fields - A comma separated list of User fields to display. # + expansions - A comma separated list of fields to expand. # + tweet\.fields - A comma separated list of Tweet fields to display. - # + return - returns can be any of following types + # + return - returns can be any of following types # http:Ok (The request has succeeded.) # http:Response (The request has failed.) resource function get users(UserId[] ids, ("connection_status"|"created_at"|"description"|"entities"|"id"|"location"|"most_recent_tweet_id"|"name"|"pinned_tweet_id"|"profile_image_url"|"protected"|"public_metrics"|"receives_your_dm"|"subscription_type"|"url"|"username"|"verified"|"verified_type"|"withheld")[]? user\.fields, ("most_recent_tweet_id"|"pinned_tweet_id")[]? expansions, ("attachments"|"author_id"|"card_uri"|"context_annotations"|"conversation_id"|"created_at"|"edit_controls"|"edit_history_tweet_ids"|"entities"|"geo"|"id"|"in_reply_to_user_id"|"lang"|"non_public_metrics"|"note_tweet"|"organic_metrics"|"possibly_sensitive"|"promoted_metrics"|"public_metrics"|"referenced_tweets"|"reply_settings"|"scopes"|"source"|"text"|"username"|"withheld")[]? tweet\.fields) returns Get2UsersResponse|http:Response { return { - "data":[{"id":"350224247","name":"Kumar Sangakkara","username":"KumarSanga2"}] + "data": [{"id": "350224247", "name": "Kumar Sangakkara", "username": "KumarSanga2"}] }; } }; @@ -205,4 +205,4 @@ function init() returns error? { log:printInfo("Initiating mock server"); check httpListener.attach(mockService, "/"); check httpListener.'start(); -} \ No newline at end of file +} diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index 52a01d7..d609233 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -14,9 +14,9 @@ // specific language governing permissions and limitations // under the License. +import ballerina/os; import ballerina/test; import ballerina/time; -import ballerina/os; configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; configurable string userId = isLiveServer ? os:getEnv("TWITTER_USER_ID") : "test"; @@ -54,11 +54,11 @@ isolated function testgetUserIdByUseName() returns error? { isolated function testUserLikeAPost() returns error? { UsersLikesCreateResponse response = check twitter->/users/[userId]/likes.post( payload = { - tweet_id:"1806286701704462623" + tweet_id: "1806286701704462623" } ); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -67,7 +67,7 @@ isolated function testUserLikeAPost() returns error? { isolated function testUserUnlikeAPost() returns error? { UsersLikesDeleteResponse response = check twitter->/users/[userId]/likes/["1806286701704462623"].delete(); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -76,7 +76,7 @@ isolated function testUserUnlikeAPost() returns error? { isolated function testPostLookup() returns error? { Get2TweetsIdResponse response = check twitter->/tweets/["1806286701704462623"](); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -87,7 +87,7 @@ isolated function testBookmarkPost() returns error? { payload = {tweet_id: "1806286701704462623"} ); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -96,7 +96,7 @@ isolated function testBookmarkPost() returns error? { isolated function testBookmarkDelete() returns error? { BookmarkMutationResponse response = check twitter->/users/[userId]/bookmarks/["1806286701704462623"].delete(); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -107,7 +107,7 @@ isolated function testRetweet() returns error? { payload = {tweet_id: "1806286701704462623"} ); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -116,7 +116,7 @@ isolated function testRetweet() returns error? { isolated function testDeleteRetweet() returns error? { UsersRetweetsDeleteResponse response = check twitter->/users/[userId]/retweets/["1806286701704462623"].delete(); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -124,12 +124,12 @@ isolated function testDeleteRetweet() returns error? { } isolated function testFollowSpecificUser() returns error? { UsersFollowingCreateResponse response = check twitter->/users/[userId]/following.post( - payload={ - target_user_id:"1803011651249278976" + payload = { + target_user_id: "1803011651249278976" } ); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -138,7 +138,7 @@ isolated function testFollowSpecificUser() returns error? { isolated function testUnfollowSpecificUser() returns error? { UsersFollowingDeleteResponse response = check twitter->/users/[userId]/following/["1803011651249278976"].delete(); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -146,12 +146,12 @@ isolated function testUnfollowSpecificUser() returns error? { } isolated function muteSpecificUser() returns error? { MuteUserMutationResponse response = check twitter->/users/[userId]/muting.post( - payload={ - target_user_id:"1803011651249278976" + payload = { + target_user_id: "1803011651249278976" } ); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -161,7 +161,7 @@ isolated function muteSpecificUser() returns error? { isolated function unmuteSpecificUser() returns error? { MuteUserMutationResponse response = check twitter->/users/[userId]/muting/["1803011651249278976"].delete(); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); + test:assertTrue(response?.errors is ()); } @test:Config { @@ -170,5 +170,5 @@ isolated function unmuteSpecificUser() returns error? { isolated function findSpecificUser() returns error? { Get2UsersResponse response = check twitter->/users(ids = ["1803011651249278976"]); test:assertTrue(response?.data !is ()); - test:assertTrue(response?.errors is ()); -} \ No newline at end of file + test:assertTrue(response?.errors is ()); +}