From e7a0d300e691b4aafe9a9f1363bfb02bd364c295 Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Tue, 2 Jul 2024 13:51:42 +0530 Subject: [PATCH 01/14] Create Test cases along with correcting values passed in variables --- ballerina/tests/tests.bal | 96 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 ballerina/tests/tests.bal diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal new file mode 100644 index 0000000..a4bc87b --- /dev/null +++ b/ballerina/tests/tests.bal @@ -0,0 +1,96 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +configurable string clientId = "Client ID"; +configurable string clientSecret = "Client Secret"; +configurable string[] scopes = ?; + +// Test case for the endpoint for exchanging authorization code for tokens +@test:Config{} +function testGetToken() returns error? { + Client discord =check new({ + auth: { + clientId: clientId, + clientSecret: clientSecret, + scopes: ["identify"] + } + }); + + OAuth2GetKeys getToken = check discord->/oauth2/keys(); +} + +// Test case for the endpoint to retrieve details about a specific user +@test:Config{} +function testGetUser() returns error? { + string user_id = "User ID"; + Client discord =check new({ + auth: { + clientId: clientId, + clientSecret: clientSecret, + scopes: ["identify", "email"] + } + }); + + UserResponse getUserInfo = check discord->/users/[user_id](); +} + +// Test case for the endpoint to retrieve details about a specific guild +@test:Config{} +function testGetGuild() returns error? { + string guild_id = "Guild ID"; + Client discord =check new({ + auth: { + clientId: clientId, + clientSecret: clientSecret, + scopes: ["guilds"] + } + }); + + PrivateGuildMemberResponse getGuildInfo = check discord->/users/\@me/guilds/[guild_id]/member(); +} + +// Test case for the endpoint to edit a message +@test:Config{} +function testGetChannel() returns error? { + string channel_id = "Text Channel ID"; + string message_id = "Message ID"; + Client discord =check new({ + auth: { + clientId: clientId, + clientSecret: clientSecret, + scopes: ["guilds"] + } + }); + + MessageResponse getGuildChannel = check discord->/channels/[channel_id]/messages/[message_id](); +} + +// Test case for the endpoint to create a voice channel invite +@test:Config{} +function testGetVoiceChannel() returns error? { + string channel_id = "Voice Channel ID"; + Client discord =check new({ + auth: { + clientId: clientId, + clientSecret: clientSecret, + scopes: ["voice"] + } + }); + + var getVoiceChannelInfo = check discord->/channels/[channel_id]/invites(); +} \ No newline at end of file From 32e4023418f3ad12abb244f47ee77f8eb491cbfa Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Wed, 3 Jul 2024 16:21:40 +0530 Subject: [PATCH 02/14] remove unnessacary comments and corrected data types of the returned data type --- ballerina/tests/tests.bal | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index a4bc87b..7055b81 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -19,8 +19,6 @@ import ballerina/test; configurable string clientId = "Client ID"; configurable string clientSecret = "Client Secret"; configurable string[] scopes = ?; - -// Test case for the endpoint for exchanging authorization code for tokens @test:Config{} function testGetToken() returns error? { Client discord =check new({ @@ -34,11 +32,10 @@ function testGetToken() returns error? { OAuth2GetKeys getToken = check discord->/oauth2/keys(); } -// Test case for the endpoint to retrieve details about a specific user @test:Config{} function testGetUser() returns error? { string user_id = "User ID"; - Client discord =check new({ + Client discord = check new({ auth: { clientId: clientId, clientSecret: clientSecret, @@ -53,7 +50,7 @@ function testGetUser() returns error? { @test:Config{} function testGetGuild() returns error? { string guild_id = "Guild ID"; - Client discord =check new({ + Client discord = check new({ auth: { clientId: clientId, clientSecret: clientSecret, @@ -69,7 +66,7 @@ function testGetGuild() returns error? { function testGetChannel() returns error? { string channel_id = "Text Channel ID"; string message_id = "Message ID"; - Client discord =check new({ + Client discord = check new({ auth: { clientId: clientId, clientSecret: clientSecret, @@ -84,7 +81,7 @@ function testGetChannel() returns error? { @test:Config{} function testGetVoiceChannel() returns error? { string channel_id = "Voice Channel ID"; - Client discord =check new({ + Client discord = check new({ auth: { clientId: clientId, clientSecret: clientSecret, @@ -92,5 +89,5 @@ function testGetVoiceChannel() returns error? { } }); - var getVoiceChannelInfo = check discord->/channels/[channel_id]/invites(); + anydata getVoiceChannelInfo = check discord->/channels/[channel_id]/invites(); } \ No newline at end of file From 657f635c47676f0b69b27152ce71efc36d9b4160 Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Thu, 4 Jul 2024 15:28:53 +0530 Subject: [PATCH 03/14] Fix Issue in the types.bal incorrect range given in the constraint for UserResponse Data type --- ballerina/types.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/types.bal b/ballerina/types.bal index 9fd4cf6..fbf978e 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -1800,7 +1800,7 @@ public type UserResponse record { string? avatar?; string discriminator; int:Signed32 public_flags; - @constraint:Int {minValue: 1, maxValue: -1} + @constraint:Int {minValue: -1, maxValue: 1} int flags; boolean? bot?; boolean? system?; From a88c1e604bd76026a9b8735f4f72a66f3d323208 Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Thu, 4 Jul 2024 15:30:56 +0530 Subject: [PATCH 04/14] Add mock server along with updated test methods --- ballerina/Dependencies.toml | 34 +++++++++++++- ballerina/tests/mock_server.bal | 61 ++++++++++++++++++++++++ ballerina/tests/tests.bal | 83 ++++++++------------------------- 3 files changed, 113 insertions(+), 65 deletions(-) create mode 100644 ballerina/tests/mock_server.bal diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index d905f28..241180e 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.1" +distribution-version = "2201.9.0" [[package]] org = "ballerina" @@ -147,6 +147,15 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "lang.int" @@ -205,6 +214,9 @@ dependencies = [ {org = "ballerina", name = "lang.value"}, {org = "ballerina", name = "observe"} ] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] [[package]] org = "ballerina" @@ -248,6 +260,9 @@ dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"} ] +modules = [ + {org = "ballerina", packageName = "os", moduleName = "os"} +] [[package]] org = "ballerina" @@ -258,6 +273,20 @@ dependencies = [ {org = "ballerina", name = "time"} ] +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + [[package]] org = "ballerina" name = "time" @@ -296,7 +325,10 @@ version = "0.1.0" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, + {org = "ballerina", name = "log"}, {org = "ballerina", name = "mime"}, + {org = "ballerina", name = "os"}, + {org = "ballerina", name = "test"}, {org = "ballerina", name = "url"}, {org = "ballerinai", name = "observe"} ] diff --git a/ballerina/tests/mock_server.bal b/ballerina/tests/mock_server.bal new file mode 100644 index 0000000..83775ac --- /dev/null +++ b/ballerina/tests/mock_server.bal @@ -0,0 +1,61 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/http; +import ballerina/log; + +listener http:Listener httpServer = new(9090); + + +http:Service mockService = service object { + +resource function get users/[string user_id]() returns UserResponse|http:Response { + UserResponse response = { + id: "688069266636800112", + username: "exampleUser", + discriminator: "1234", + public_flags: 0, + flags: 1, + bot: false, + system: false, + avatar: "avatar_url", + banner: "banner_url", + accent_color: 16777215, + global_name: "globalExampleUser" + }; + return response; +} +resource function get channels/[string channel_id]/invites() returns anydata { + anydata response = [1, "string", true]; + return response; + } + +resource function get channels/[string channel_id]/webhooks() returns anydata { + anydata response = [1, "string", true]; + return response; + } + +}; + + function init() returns error? { + if isLiveServer { + log:printInfo("Skiping mock server initialization as the tests are running on live server"); + return; + } + log:printInfo("Initiating mock server"); + check httpServer.attach(mockService, "/"); + check httpServer.'start(); +} \ No newline at end of file diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index 7055b81..5adee66 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -15,79 +15,34 @@ // under the License. import ballerina/test; +import ballerina/os; -configurable string clientId = "Client ID"; -configurable string clientSecret = "Client Secret"; -configurable string[] scopes = ?; -@test:Config{} -function testGetToken() returns error? { - Client discord =check new({ - auth: { - clientId: clientId, - clientSecret: clientSecret, - scopes: ["identify"] - } - }); - - OAuth2GetKeys getToken = check discord->/oauth2/keys(); -} +configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; +configurable string CliId = isLiveServer ? os:getEnv("Client_ID") : "test"; +configurable string CliScre = isLiveServer ? os:getEnv("Client_Secret") : "test"; +configurable string serviceUrl = isLiveServer ? os:getEnv("DISCORD_URL") : "http://localhost:9090/"; +ConnectionConfig config = {auth:{ + token: "BearerToken" +}}; +final Client discord = check new Client(config, serviceUrl); @test:Config{} function testGetUser() returns error? { - string user_id = "User ID"; - Client discord = check new({ - auth: { - clientId: clientId, - clientSecret: clientSecret, - scopes: ["identify", "email"] - } - }); - + string user_id = "User Id"; UserResponse getUserInfo = check discord->/users/[user_id](); + test:assertTrue((getUserInfo.length()> 0)); } -// Test case for the endpoint to retrieve details about a specific guild @test:Config{} -function testGetGuild() returns error? { - string guild_id = "Guild ID"; - Client discord = check new({ - auth: { - clientId: clientId, - clientSecret: clientSecret, - scopes: ["guilds"] - } - }); - - PrivateGuildMemberResponse getGuildInfo = check discord->/users/\@me/guilds/[guild_id]/member(); +function testGetVoiceChannel() returns error? { + string channel_id = "Voice Channel ID"; + anydata getVoiceChannelInfo = check discord->/channels/[channel_id]/invites(); + test:assertTrue((getVoiceChannelInfo.count()> 0)); } -// Test case for the endpoint to edit a message @test:Config{} -function testGetChannel() returns error? { - string channel_id = "Text Channel ID"; - string message_id = "Message ID"; - Client discord = check new({ - auth: { - clientId: clientId, - clientSecret: clientSecret, - scopes: ["guilds"] - } - }); - - MessageResponse getGuildChannel = check discord->/channels/[channel_id]/messages/[message_id](); +function testGetWebhook() returns error? { + string channel_id = "Channel ID"; + anydata getWebhookInfo = check discord->/channels/[channel_id]/webhooks(); + test:assertTrue((getWebhookInfo.count()> 0)); } - -// Test case for the endpoint to create a voice channel invite -@test:Config{} -function testGetVoiceChannel() returns error? { - string channel_id = "Voice Channel ID"; - Client discord = check new({ - auth: { - clientId: clientId, - clientSecret: clientSecret, - scopes: ["voice"] - } - }); - - anydata getVoiceChannelInfo = check discord->/channels/[channel_id]/invites(); -} \ No newline at end of file From 713021874b431f51c8da247c5a7b24d17c8e2418 Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Thu, 4 Jul 2024 23:01:43 +0530 Subject: [PATCH 05/14] Reformat tests --- ballerina/tests/tests.bal | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index 5adee66..a20c75d 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -14,35 +14,39 @@ // specific language governing permissions and limitations // under the License. -import ballerina/test; import ballerina/os; +import ballerina/test; configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; -configurable string CliId = isLiveServer ? os:getEnv("Client_ID") : "test"; -configurable string CliScre = isLiveServer ? os:getEnv("Client_Secret") : "test"; +configurable string clientId = isLiveServer ? os:getEnv("Client_ID") : "test"; +configurable string clientSecret = isLiveServer ? os:getEnv("Client_Secret") : "test"; configurable string serviceUrl = isLiveServer ? os:getEnv("DISCORD_URL") : "http://localhost:9090/"; -ConnectionConfig config = {auth:{ - token: "BearerToken" -}}; + +ConnectionConfig config = { + auth: { + token: "BearerToken" + } +}; + final Client discord = check new Client(config, serviceUrl); -@test:Config{} +@test:Config {} function testGetUser() returns error? { - string user_id = "User Id"; + string user_id = "User Id"; UserResponse getUserInfo = check discord->/users/[user_id](); - test:assertTrue((getUserInfo.length()> 0)); + test:assertTrue((getUserInfo.length() > 0)); } -@test:Config{} +@test:Config {} function testGetVoiceChannel() returns error? { - string channel_id = "Voice Channel ID"; + string channel_id = "Voice Channel ID"; anydata getVoiceChannelInfo = check discord->/channels/[channel_id]/invites(); - test:assertTrue((getVoiceChannelInfo.count()> 0)); + test:assertTrue((getVoiceChannelInfo.count() > 0)); } -@test:Config{} +@test:Config {} function testGetWebhook() returns error? { - string channel_id = "Channel ID"; + string channel_id = "Channel ID"; anydata getWebhookInfo = check discord->/channels/[channel_id]/webhooks(); - test:assertTrue((getWebhookInfo.count()> 0)); + test:assertTrue((getWebhookInfo.count() > 0)); } From 26dc8cbd43005f01f2f31ab83b06acd891c587dd Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Thu, 4 Jul 2024 23:17:29 +0530 Subject: [PATCH 06/14] Reformat and optimize mock server --- ballerina/tests/mock_server.bal | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/ballerina/tests/mock_server.bal b/ballerina/tests/mock_server.bal index 83775ac..a7cef73 100644 --- a/ballerina/tests/mock_server.bal +++ b/ballerina/tests/mock_server.bal @@ -17,14 +17,12 @@ import ballerina/http; import ballerina/log; -listener http:Listener httpServer = new(9090); +listener http:Listener httpServer = new (9090); +http:Service mockService = service object { -http:Service mockService = service object { - -resource function get users/[string user_id]() returns UserResponse|http:Response { - UserResponse response = { - id: "688069266636800112", + resource function get users/[string userId]() returns UserResponse|http:Response => { + id: userId, username: "exampleUser", discriminator: "1234", public_flags: 0, @@ -36,26 +34,19 @@ resource function get users/[string user_id]() returns UserResponse|http:Respons accent_color: 16777215, global_name: "globalExampleUser" }; - return response; -} -resource function get channels/[string channel_id]/invites() returns anydata { - anydata response = [1, "string", true]; - return response; - } -resource function get channels/[string channel_id]/webhooks() returns anydata { - anydata response = [1, "string", true]; - return response; - } + resource function get channels/[string channelId]/invites() returns anydata => ["Invite1", "Invite2"]; + resource function get channels/[string channelId]/webhooks() returns anydata => ["Webhook1", "Webhook2"]; }; - function init() returns error? { +function init() returns error? { if isLiveServer { log:printInfo("Skiping mock server initialization as the tests are running on live server"); return; } + log:printInfo("Initiating mock server"); check httpServer.attach(mockService, "/"); check httpServer.'start(); -} \ No newline at end of file +} From 14ab31aa5f3ce9348d25ae6ce05e1d6fe4137149 Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Thu, 4 Jul 2024 23:17:57 +0530 Subject: [PATCH 07/14] Fix variable naming and anti-patterns --- ballerina/tests/tests.bal | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index a20c75d..cdda29c 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -18,9 +18,14 @@ import ballerina/os; import ballerina/test; configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; -configurable string clientId = isLiveServer ? os:getEnv("Client_ID") : "test"; -configurable string clientSecret = isLiveServer ? os:getEnv("Client_Secret") : "test"; -configurable string serviceUrl = isLiveServer ? os:getEnv("DISCORD_URL") : "http://localhost:9090/"; +configurable string token = isLiveServer ? os:getEnv("TOKEN") : "token"; +configurable string clientId = isLiveServer ? os:getEnv("CLIENT_ID") : "test"; +configurable string clientSecret = isLiveServer ? os:getEnv("CLIENT_SECRET") : "test"; +configurable string serviceUrl = isLiveServer ? os:getEnv("DISCORD_URL") : "http://localhost:9090"; + +string userId = "User Id"; +string voiceChannelId = "Voice Channel ID"; +string channelId = "Channel ID"; ConnectionConfig config = { auth: { @@ -30,23 +35,26 @@ ConnectionConfig config = { final Client discord = check new Client(config, serviceUrl); -@test:Config {} +@test:Config { + groups: ["live_tests", "mock_tests"] +} function testGetUser() returns error? { - string user_id = "User Id"; - UserResponse getUserInfo = check discord->/users/[user_id](); - test:assertTrue((getUserInfo.length() > 0)); + UserResponse user = check discord->/users/[userId](); + test:assertEquals(user.id, userId); } -@test:Config {} +@test:Config { + groups: ["live_tests", "mock_tests"] +} function testGetVoiceChannel() returns error? { - string channel_id = "Voice Channel ID"; - anydata getVoiceChannelInfo = check discord->/channels/[channel_id]/invites(); - test:assertTrue((getVoiceChannelInfo.count() > 0)); + anydata[] voiceChannels = check discord->/channels/[voiceChannelId]/invites(); + test:assertTrue(voiceChannels.length() > 0); } -@test:Config {} +@test:Config { + groups: ["live_tests", "mock_tests"] +} function testGetWebhook() returns error? { - string channel_id = "Channel ID"; - anydata getWebhookInfo = check discord->/channels/[channel_id]/webhooks(); - test:assertTrue((getWebhookInfo.count() > 0)); + anydata[] channelWebhooks = check discord->/channels/[channelId]/webhooks(); + test:assertTrue(channelWebhooks.length() > 0); } From 0c568655766eb7aee3fd921e903091ae105ab7db Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Fri, 5 Jul 2024 09:40:57 +0530 Subject: [PATCH 08/14] Add example IDs in the variables --- ballerina/tests/tests.bal | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index cdda29c..f2f0baa 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -18,18 +18,16 @@ import ballerina/os; import ballerina/test; configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; -configurable string token = isLiveServer ? os:getEnv("TOKEN") : "token"; -configurable string clientId = isLiveServer ? os:getEnv("CLIENT_ID") : "test"; -configurable string clientSecret = isLiveServer ? os:getEnv("CLIENT_SECRET") : "test"; +configurable string token = isLiveServer ? os:getEnv("TOKEN") : "z4HhmDy5ghijpIRL1YFzhCeVFabcdef"; configurable string serviceUrl = isLiveServer ? os:getEnv("DISCORD_URL") : "http://localhost:9090"; -string userId = "User Id"; -string voiceChannelId = "Voice Channel ID"; -string channelId = "Channel ID"; +configurable string userId = "688069266636800112"; +string voiceChannelId = "1160951610135019725"; +string channelId = "893493941398294611"; ConnectionConfig config = { auth: { - token: "BearerToken" + token } }; From 4711566d660ebe94d3bd3f46d1fd8390ba347ce2 Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Fri, 5 Jul 2024 09:56:06 +0530 Subject: [PATCH 09/14] Add README along with corrected the userid as a configurable variable --- ballerina/tests/READMEmd | 68 +++++++++++++++++++++++++++++++++++++++ ballerina/tests/tests.bal | 2 +- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 ballerina/tests/READMEmd diff --git a/ballerina/tests/READMEmd b/ballerina/tests/READMEmd new file mode 100644 index 0000000..1bc542e --- /dev/null +++ b/ballerina/tests/READMEmd @@ -0,0 +1,68 @@ +# Running Tests + +There are two test environments for running the Discord connector tests. The default test environment is the mock server for Discord API. The other test environment is the actual Discord API. + +You can run the tests in either of these environments and each has its own compatible set of tests. + + Test Groups | Environment +-------------|--------------------------------------------------- + mock_tests | Mock server for Discord API (Defualt Environment) + live_tests | Discord API + +## Running Tests in the Mock Server + +To execute the tests on the mock server, ensure that the `IS_LIVE_SERVER` environment variable is either set to `false` or unset before initiating the tests. + +This environment variable can be configured within the `Config.toml` file located in the tests directory or specified as an environmental variable. + +#### Using a Config.toml File + +Create a `Config.toml` file in the tests directory and the following content: + +```toml +isLiveServer = false +``` + +#### Using Environment Variables + +Alternatively, you can set your authentication credentials as environment variables: + +```bash +export IS_LIVE_SERVER=false +``` + +Then, run the following command to run the tests: + +```bash + ./gradlew clean test +``` + +## Running Tests Against Discord Live API + +#### Using a Config.toml File + +Create a `Config.toml` file in the tests directory and add your authentication credentials a + +```toml +isTestOnLiveServer = true +token = "" +userId = "" +serviceUrl = "" +``` + +#### Using Environment Variables + +Alternatively, you can set your authentication credentials as environment variables: + +```bash +export IS_LIVE_SERVER=true +export TOKEN="" +export DISCORD_USER_ID="" +export DISCORD_URL="" +``` + +Then, run the following command to run the tests: + +```bash + ./gradlew clean test -Pgroups="live_tests" +``` \ No newline at end of file diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index f2f0baa..1368b2e 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -20,8 +20,8 @@ import ballerina/test; configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; configurable string token = isLiveServer ? os:getEnv("TOKEN") : "z4HhmDy5ghijpIRL1YFzhCeVFabcdef"; configurable string serviceUrl = isLiveServer ? os:getEnv("DISCORD_URL") : "http://localhost:9090"; +configurable string userId = isLiveServer ? os:getEnv("DISCORD_USER_ID") :"688069266636800112"; -configurable string userId = "688069266636800112"; string voiceChannelId = "1160951610135019725"; string channelId = "893493941398294611"; From 628571253f6975fb2e376e20a826f731f092a83b Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Fri, 5 Jul 2024 09:58:51 +0530 Subject: [PATCH 10/14] Fix READMEmd to README.md --- ballerina/tests/README.md | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 ballerina/tests/README.md diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md new file mode 100644 index 0000000..1bc542e --- /dev/null +++ b/ballerina/tests/README.md @@ -0,0 +1,68 @@ +# Running Tests + +There are two test environments for running the Discord connector tests. The default test environment is the mock server for Discord API. The other test environment is the actual Discord API. + +You can run the tests in either of these environments and each has its own compatible set of tests. + + Test Groups | Environment +-------------|--------------------------------------------------- + mock_tests | Mock server for Discord API (Defualt Environment) + live_tests | Discord API + +## Running Tests in the Mock Server + +To execute the tests on the mock server, ensure that the `IS_LIVE_SERVER` environment variable is either set to `false` or unset before initiating the tests. + +This environment variable can be configured within the `Config.toml` file located in the tests directory or specified as an environmental variable. + +#### Using a Config.toml File + +Create a `Config.toml` file in the tests directory and the following content: + +```toml +isLiveServer = false +``` + +#### Using Environment Variables + +Alternatively, you can set your authentication credentials as environment variables: + +```bash +export IS_LIVE_SERVER=false +``` + +Then, run the following command to run the tests: + +```bash + ./gradlew clean test +``` + +## Running Tests Against Discord Live API + +#### Using a Config.toml File + +Create a `Config.toml` file in the tests directory and add your authentication credentials a + +```toml +isTestOnLiveServer = true +token = "" +userId = "" +serviceUrl = "" +``` + +#### Using Environment Variables + +Alternatively, you can set your authentication credentials as environment variables: + +```bash +export IS_LIVE_SERVER=true +export TOKEN="" +export DISCORD_USER_ID="" +export DISCORD_URL="" +``` + +Then, run the following command to run the tests: + +```bash + ./gradlew clean test -Pgroups="live_tests" +``` \ No newline at end of file From b3d4b6de8aefdea326cc06bbac35775851481293 Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Fri, 5 Jul 2024 09:59:56 +0530 Subject: [PATCH 11/14] Remove unnecessary file --- ballerina/tests/READMEmd | 68 ---------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 ballerina/tests/READMEmd diff --git a/ballerina/tests/READMEmd b/ballerina/tests/READMEmd deleted file mode 100644 index 1bc542e..0000000 --- a/ballerina/tests/READMEmd +++ /dev/null @@ -1,68 +0,0 @@ -# Running Tests - -There are two test environments for running the Discord connector tests. The default test environment is the mock server for Discord API. The other test environment is the actual Discord API. - -You can run the tests in either of these environments and each has its own compatible set of tests. - - Test Groups | Environment --------------|--------------------------------------------------- - mock_tests | Mock server for Discord API (Defualt Environment) - live_tests | Discord API - -## Running Tests in the Mock Server - -To execute the tests on the mock server, ensure that the `IS_LIVE_SERVER` environment variable is either set to `false` or unset before initiating the tests. - -This environment variable can be configured within the `Config.toml` file located in the tests directory or specified as an environmental variable. - -#### Using a Config.toml File - -Create a `Config.toml` file in the tests directory and the following content: - -```toml -isLiveServer = false -``` - -#### Using Environment Variables - -Alternatively, you can set your authentication credentials as environment variables: - -```bash -export IS_LIVE_SERVER=false -``` - -Then, run the following command to run the tests: - -```bash - ./gradlew clean test -``` - -## Running Tests Against Discord Live API - -#### Using a Config.toml File - -Create a `Config.toml` file in the tests directory and add your authentication credentials a - -```toml -isTestOnLiveServer = true -token = "" -userId = "" -serviceUrl = "" -``` - -#### Using Environment Variables - -Alternatively, you can set your authentication credentials as environment variables: - -```bash -export IS_LIVE_SERVER=true -export TOKEN="" -export DISCORD_USER_ID="" -export DISCORD_URL="" -``` - -Then, run the following command to run the tests: - -```bash - ./gradlew clean test -Pgroups="live_tests" -``` \ No newline at end of file From 9ace83758ec080e7257e32280b2f08c3ae320775 Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Fri, 5 Jul 2024 10:28:21 +0530 Subject: [PATCH 12/14] Update Images Links and also links to documentation for bearer token guide --- README.md | 10 +++++----- ballerina/Module.md | 10 +++++----- ballerina/tests/README.md | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2fbf1ec..33c6660 100644 --- a/README.md +++ b/README.md @@ -10,25 +10,25 @@ Follow these steps to create a Discord developer account. ### Step 1: Login to Discord developer page - +Discord Dev Page Visit [Discord developer portal](https://discord.com/login?redirect_to=%2Fdevelopers) by logging into your Discord account. If you do not have a Discord account already, [create a new discord account](https://discord.com/login) by clicking on the `Register` hyperlink below the `Log In` button when opening the Discord developer page. - +Create Discord Account Complete the account creation process by including the relavant information in the given fields. ### Step 2: Make a new Discord application - +Make New Application Once in the Discord developer portal is open, click on the `New Application` button as displayed above to start the process. ### Step 3: Name the Discord Application - +Name and Create the App 1. Proceed by giving the Discord Application a name and click on the terms of service. @@ -36,7 +36,7 @@ Once in the Discord developer portal is open, click on the `New Application` but ### Step 4: Obtain the Client ID and Client Secret - +Obtain Client ID and Secret Under the `OAuth2` section found on the left-sided list, locate the Client's Information as shown on the screen. To implement the functionalities provided by Discord's API, you will need the Client ID and Client Secret. diff --git a/ballerina/Module.md b/ballerina/Module.md index 6722000..0805781 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -10,25 +10,25 @@ Follow these steps to create a Discord developer account. ### Step 1: Login to Discord developer page - +Discord Dev Page Visit [Discord developer portal](https://discord.com/login?redirect_to=%2Fdevelopers) by logging into your Discord account. If you do not have a Discord account already, [create a new discord account](https://discord.com/login) by clicking on the `Register` hyperlink below the `Log In` button when opening the Discord developer page. - +Create Discord Account Complete the account creation process by including the relavant information in the given fields. ### Step 2: Make a new Discord application - +Make New Application Once in the Discord developer portal is open, click on the `New Application` button as displayed above to start the process. ### Step 3: Name the Discord Application - +Name and Create the App 1. Proceed by giving the Discord Application a name and click on the terms of service. @@ -36,7 +36,7 @@ Once in the Discord developer portal is open, click on the `New Application` but ### Step 4: Obtain the Client ID and Client Secret - +Obtain Client ID and Secret Under the `OAuth2` section found on the left-sided list, locate the Client's Information as shown on the screen. To implement the functionalities provided by Discord's API, you will need the Client ID and Client Secret. diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 1bc542e..0cc45bb 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -41,7 +41,7 @@ Then, run the following command to run the tests: #### Using a Config.toml File -Create a `Config.toml` file in the tests directory and add your authentication credentials a +Create a `Config.toml` file in the tests directory and add your authentication credentials, to create a [Discord bearer token use this guide](https://github.com/discord-net/Discord.Net/blob/dev/docs/guides/bearer_token/bearer_token_guide.md). ```toml isTestOnLiveServer = true From eab40694b31dd02ab6210b9e1f59ae5e0b936586 Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Fri, 5 Jul 2024 10:32:02 +0530 Subject: [PATCH 13/14] Update Links to the ballerina-platform main repo --- ballerina/Ballerina.toml | 2 +- build-config/resources/Ballerina.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 3d874d4..9ac9143 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -7,7 +7,7 @@ license = ["Apache-2.0"] authors = ["Ballerina"] keywords = ["Communication/discord", "Cost/Free"] icon = "icon.png" -repository = "https://github.com/HussainLatiff/module-ballerinax-discord" +repository = "https://github.com/ballerina-platform/module-ballerinax-discord" [build-options] observabilityIncluded = true diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index d54d9d0..185261e 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -7,7 +7,7 @@ license = ["Apache-2.0"] authors = ["Ballerina"] keywords = ["Communication/discord", "Cost/Free"] icon = "icon.png" -repository = "https://github.com/HussainLatiff/module-ballerinax-discord" +repository = "https://github.com/ballerina-platform/module-ballerinax-discord" [build-options] observabilityIncluded = true From 7497e555ccdf5b64b29192a818f4daddd8496fde Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Fri, 5 Jul 2024 11:11:45 +0530 Subject: [PATCH 14/14] Remove redunadant serviceurl --- ballerina/tests/README.md | 2 -- ballerina/tests/tests.bal | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 0cc45bb..9974934 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -47,7 +47,6 @@ Create a `Config.toml` file in the tests directory and add your authentication c isTestOnLiveServer = true token = "" userId = "" -serviceUrl = "" ``` #### Using Environment Variables @@ -58,7 +57,6 @@ Alternatively, you can set your authentication credentials as environment variab export IS_LIVE_SERVER=true export TOKEN="" export DISCORD_USER_ID="" -export DISCORD_URL="" ``` Then, run the following command to run the tests: diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index 1368b2e..ff237e3 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -19,7 +19,7 @@ import ballerina/test; configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true"; configurable string token = isLiveServer ? os:getEnv("TOKEN") : "z4HhmDy5ghijpIRL1YFzhCeVFabcdef"; -configurable string serviceUrl = isLiveServer ? os:getEnv("DISCORD_URL") : "http://localhost:9090"; +configurable string serviceUrl = isLiveServer ? "https://discord.com/api/v10" : "http://localhost:9090"; configurable string userId = isLiveServer ? os:getEnv("DISCORD_USER_ID") :"688069266636800112"; string voiceChannelId = "1160951610135019725";