diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 6b2ff12..edb434f 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.0" +distribution-version = "2201.9.3" [[package]] org = "ballerina" name = "auth" -version = "2.11.0" +version = "2.11.2" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -64,7 +64,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.11.2" +version = "2.11.3" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -96,7 +96,7 @@ modules = [ [[package]] org = "ballerina" name = "io" -version = "1.6.0" +version = "1.6.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} diff --git a/ballerina/Package.md b/ballerina/Package.md index 4311e3f..51ac0e9 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -89,4 +89,4 @@ The `Slack` connector provides practical examples illustrating usage in various 1. [Automated Summary Report](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/automated-summary-report) - This use case demonstrates how the Slack API can be utilized to generate a summarized report of daily stand up chats in the general channel. -2. [Survey Feedback Analysis](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/survey-feedback-analysis) - This use case demonstrates how the Slack API can be utilized to perform a company-wide survey by creating a dedicated channel to receive and track feedback replies. \ No newline at end of file +2. [Survey Feedback Analysis](https://github.com/ballerina-platform/module-ballerinax-slack/tree/master/examples/survey-feedback-analysis) - This use case demonstrates how the Slack API can be utilized to perform a company-wide survey by creating a dedicated channel to receive and track feedback replies. diff --git a/ballerina/tests/mock_server.bal b/ballerina/tests/mock_server.bal deleted file mode 100644 index 6e8697c..0000000 --- a/ballerina/tests/mock_server.bal +++ /dev/null @@ -1,234 +0,0 @@ -// 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 httpListener = new (9090); - -http:Service mockAPI = service object { - - # Get Presence - # - # + return - Get Presence - resource isolated function get users\.getPresence() returns json => { - "ok": true, - "presence": "away", - "online": false, - "auto_away": false, - "manual_away": false, - "connection_count": 0 - }; - - # Post Message - # - # + channel - The channel to post the message to - # + return - json - resource isolated function post chat\.postMessage(@http:Payload string channel, string text) returns json => { - "ok": true, - "channel": "C078KJ7SW78", - "ts": "1719830298.784769", - "message": { - "user": "U078KJ7RX1U", - "type": "message", - "ts": "1719830298.784769", - "bot_id": "B07986E3N4E", - "app_id": "A079SKHD00Z", - "text": "This is a Test", - "team": "T078S42MC59", - "bot_profile": { - "id": "B07986E3N4E", - "app_id": "A079SKHD00Z", - "name": "test-app", - "icons": { - "image_36": "https://a.slack-edge.com/80588/img/plugins/app/bot_36.png", - "image_48": "https://a.slack-edge.com/80588/img/plugins/app/bot_48.png", - "image_72": "https://a.slack-edge.com/80588/img/plugins/app/service_72.png" - }, - "deleted": false, - "updated": 1719218992, - "team_id": "T078S42MC59" - }, - "blocks": [ - { - "type": "rich_text", - "block_id": "I/L", - "elements": [ - { - "type": "rich_text_section", - "elements": [ - { - "type": "text", - "text": "This is a Test" - } - ] - } - ] - } - ] - } - }; - - # List Users - # - # + return - List Users - resource isolated function get users\.list() returns json => { - "ok": true, - "members": [ - { - "id": "USLACKBOT", - "team_id": "T078S42MC59", - "name": "slackbot", - "deleted": false, - "color": "757575", - "real_name": "Slackbot", - "tz": "America/Los_Angeles", - "tz_label": "Pacific Daylight Time", - "tz_offset": -25200, - "profile": { - "title": "", - "phone": "", - "skype": "", - "real_name": "Slackbot", - "real_name_normalized": "Slackbot", - "display_name": "Slackbot", - "display_name_normalized": "Slackbot", - "fields": {}, - "status_text": "", - "status_emoji": "", - "status_emoji_display_info": [], - "status_expiration": 0, - "avatar_hash": "sv41d8cd98f0", - "always_active": true, - "first_name": "slackbot", - "last_name": "", - "image_24": "https://a.slack-edge.com/80588/img/slackbot_24.png", - "image_32": "https://a.slack-edge.com/80588/img/slackbot_32.png", - "image_48": "https://a.slack-edge.com/80588/img/slackbot_48.png", - "image_72": "https://a.slack-edge.com/80588/img/slackbot_72.png", - "image_192": "https://a.slack-edge.com/80588/marketing/img/avatars/slackbot/avatar-slackbot.png", - "image_512": "https://a.slack-edge.com/80588/img/slackbot_512.png", - "status_text_canonical": "", - "team": "T078S42MC59" - }, - "is_admin": false, - "is_owner": false, - "is_primary_owner": false, - "is_restricted": false, - "is_ultra_restricted": false, - "is_bot": false, - "is_app_user": false, - "updated": 0, - "is_email_confirmed": false, - "who_can_share_contact_card": "EVERYONE" - }, - { - "id": "U078KJ7RX1U", - "team_id": "T078S42MC59", - "name": "adib", - "deleted": false, - "color": "9f69e7", - "real_name": "Adib Samoon", - "tz": "Asia/Colombo", - "tz_label": "Sri Lanka Standard Time", - "tz_offset": 19800, - "profile": { - "title": "", - "phone": "", - "skype": "", - "real_name": "Adib Samoon", - "real_name_normalized": "Adib Samoon", - "display_name": "Adib Samoon", - "display_name_normalized": "Adib Samoon", - "fields": null, - "status_text": "", - "status_emoji": "", - "status_emoji_display_info": [], - "status_expiration": 0, - "avatar_hash": "g22cb1d82fff", - "email": "adib@wso2.com", - "first_name": "Adib", - "last_name": "Samoon", - "image_24": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-24.png", - "image_32": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-32.png", - "image_48": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-48.png", - "image_72": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-72.png", - "image_192": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-192.png", - "image_512": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-512.png", - "status_text_canonical": "", - "team": "T078S42MC59" - }, - "is_admin": true, - "is_owner": true, - "is_primary_owner": true, - "is_restricted": false, - "is_ultra_restricted": false, - "is_bot": false, - "is_app_user": false, - "updated": 1718859479, - "is_email_confirmed": true, - "has_2fa": false, - "who_can_share_contact_card": "EVERYONE" - } - ], - "cache_ts": 1719830510, - "response_metadata": { - "next_cursor": "" - } - }; - - # Get User Profile - # - # + return - Get User Profile - resource isolated function get users\.profile\.get() returns json => { - "ok": true, - "profile": { - "title": "", - "phone": "", - "skype": "", - "real_name": "Adib Samoon", - "real_name_normalized": "Adib Samoon", - "display_name": "Adib Samoon", - "display_name_normalized": "Adib Samoon", - "fields": {}, - "status_text": "", - "status_emoji": "", - "status_emoji_display_info": [], - "status_expiration": 0, - "avatar_hash": "g22cb1d82fff", - "email": "adib@wso2.com", - "first_name": "Adib", - "last_name": "Samoon", - "image_24": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-24.png", - "image_32": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-32.png", - "image_48": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-48.png", - "image_72": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-72.png", - "image_192": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-192.png", - "image_512": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-512.png", - "status_text_canonical": "" - } - }; -}; - -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 httpListener.attach(mockAPI, "/"); - check httpListener.'start(); -} diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal new file mode 100644 index 0000000..affae7c --- /dev/null +++ b/ballerina/tests/mock_service.bal @@ -0,0 +1,235 @@ +// 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 httpListener = new (9090); + +http:Service mockAPI = service object { + + # Get Presence + # + # + return - Get Presence + resource isolated function get users\.getPresence() returns json => { + "ok": true, + "presence": "away", + "online": false, + "auto_away": false, + "manual_away": false, + "connection_count": 0 + }; + + # Post Message + # + # + return - json + resource isolated function post chat\.postMessage(@http:Payload http:Request request) returns ChatPostMessageResponse => { + ok: true, + channel: "C078KJ7SW78", + ts: "1719830298.784769", + message: { + user: "U078KJ7RX1U", + 'type: "message", + ts: "1719830298.784769", + bot_id: [], + text: "This is a Test", + team: "T078S42MC59", + bot_profile: { + id: "B07986E3N4E", + app_id: "A079SKHD00Z", + name: "test-app", + icons: { + image_36: "https://a.slack-edge.com/80588/img/plugins/app/bot_36.png", + image_48: "https://a.slack-edge.com/80588/img/plugins/app/bot_48.png", + image_72: "https://a.slack-edge.com/80588/img/plugins/app/service_72.png" + }, + deleted: false, + updated: 1719218992, + team_id: "T078S42MC59" + }, + blocks: [ + { + "type": "rich_text", + "block_id": "I/L", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "This is a Test" + } + ] + } + ] + } + ] + } + }; + + # List Users + # + # + return - List Users + resource isolated function get users\.list() returns UsersListResponse => { + ok: true, + members: [ + [ + { + "id": "USLACKBOT", + "team_id": "T078S42MC59", + "name": "slackbot", + "deleted": false, + "color": "757575", + "real_name": "Slackbot", + "tz": "America/Los_Angeles", + "tz_label": "Pacific Daylight Time", + "tz_offset": -25200, + "profile": { + "title": "", + "phone": "", + "skype": "", + "real_name": "Slackbot", + "real_name_normalized": "Slackbot", + "display_name": "Slackbot", + "display_name_normalized": "Slackbot", + "fields": {}, + "status_text": "", + "status_emoji": "", + "status_emoji_display_info": [], + "status_expiration": 0, + "avatar_hash": "sv41d8cd98f0", + "always_active": true, + "first_name": "slackbot", + "last_name": "", + "image_24": "https://a.slack-edge.com/80588/img/slackbot_24.png", + "image_32": "https://a.slack-edge.com/80588/img/slackbot_32.png", + "image_48": "https://a.slack-edge.com/80588/img/slackbot_48.png", + "image_72": "https://a.slack-edge.com/80588/img/slackbot_72.png", + "image_192": "https://a.slack-edge.com/80588/marketing/img/avatars/slackbot/avatar-slackbot.png", + "image_512": "https://a.slack-edge.com/80588/img/slackbot_512.png", + "status_text_canonical": "", + "team": "T078S42MC59" + }, + "is_admin": false, + "is_owner": false, + "is_primary_owner": false, + "is_restricted": false, + "is_ultra_restricted": false, + "is_bot": false, + "is_app_user": false, + "updated": 0, + "is_email_confirmed": false, + "who_can_share_contact_card": "EVERYONE" + }, + { + "id": "U078KJ7RX1U", + "team_id": "T078S42MC59", + "name": "adib", + "deleted": false, + "color": "9f69e7", + "real_name": "Adib Samoon", + "tz": "Asia/Colombo", + "tz_label": "Sri Lanka Standard Time", + "tz_offset": 19800, + "profile": { + "title": "", + "phone": "", + "skype": "", + "real_name": "Adib Samoon", + "real_name_normalized": "Adib Samoon", + "display_name": "Adib Samoon", + "display_name_normalized": "Adib Samoon", + "fields": null, + "status_text": "", + "status_emoji": "", + "status_emoji_display_info": [], + "status_expiration": 0, + "avatar_hash": "g22cb1d82fff", + "email": "adib@wso2.com", + "first_name": "Adib", + "last_name": "Samoon", + "image_24": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-24.png", + "image_32": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-32.png", + "image_48": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-48.png", + "image_72": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-72.png", + "image_192": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-192.png", + "image_512": "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-512.png", + "status_text_canonical": "", + "team": "T078S42MC59" + }, + "is_admin": true, + "is_owner": true, + "is_primary_owner": true, + "is_restricted": false, + "is_ultra_restricted": false, + "is_bot": false, + "is_app_user": false, + "updated": 1718859479, + "is_email_confirmed": true, + "has_2fa": false, + "who_can_share_contact_card": "EVERYONE" + } + ] + ], + cache_ts: 1719830510, + response_metadata: [ + { + next_cursor: "" + } + ] + }; + + # Get User Profile + # + # + return - Get User Profile + resource isolated function get users\.profile\.get() returns UsersProfileGetResponse => { + ok: true, + profile: { + title: "", + phone: "", + skype: "", + real_name: "Adib Samoon", + real_name_normalized: "Adib Samoon", + display_name: "Adib Samoon", + display_name_normalized: "Adib Samoon", + fields: [], + status_text: "", + status_emoji: "", + status_expiration: 0, + avatar_hash: "g22cb1d82fff", + email: "adib@wso2.com", + first_name: "Adib", + last_name: "Samoon", + image_24: "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-24.png", + image_32: "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-32.png", + image_48: "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-48.png", + image_72: "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-72.png", + image_192: "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-192.png", + image_512: "https://secure.gravatar.com/avatar/22cb1d82fffbdffa0fb80651f9afbb5a.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0025-512.png", + status_text_canonical: "" + } + }; +}; + +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 httpListener.attach(mockAPI, "/"); + check httpListener.'start(); +} diff --git a/ballerina/tests/test_cases.bal b/ballerina/tests/tests.bal similarity index 92% rename from ballerina/tests/test_cases.bal rename to ballerina/tests/tests.bal index 5c6fd65..13899e8 100644 --- a/ballerina/tests/test_cases.bal +++ b/ballerina/tests/tests.bal @@ -52,8 +52,8 @@ function testGetPresence() returns error? { @test:Config { groups: ["live_tests", "mock_tests"] } -function testPostMessage_1() returns error? { - ChatPostMessageResponse response = check slack->/chat\.postMessage.post({channel: "general", text: "This is a Test"}); +function testPostMessage() returns error? { + ChatPostMessageResponse response = check slack->/chat\.postMessage.post({channel: "general"}); test:assertTrue(response.ok, "The ok attribute should be true"); test:assertEquals(response.message.text, "This is a Test", "The message text is not equal to the expected value"); } @@ -61,7 +61,7 @@ function testPostMessage_1() returns error? { @test:Config { groups: ["live_tests", "mock_tests"] } -function testUsersList() returns error? { +function testGetUsersList() returns error? { UsersListResponse response = check slack->/users\.list(); test:assertTrue(response.ok, "The ok attribute should be true"); } @@ -69,7 +69,7 @@ function testUsersList() returns error? { @test:Config { groups: ["live_tests", "mock_tests"] } -function testUsersProfileGet() returns error? { +function testGetUserProfiles() returns error? { UsersProfileGetResponse response = check slack->/users\.profile\.get(); test:assertTrue(response.ok, "The ok attribute should be true"); } diff --git a/gradle.properties b/gradle.properties index c20a9ad..fb6842f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,4 @@ releasePluginVersion=2.8.0 testngVersion=7.6.1 eclipseLsp4jVersion=0.12.0 ballerinaGradlePluginVersion=2.2.4 -ballerinaLangVersion=2201.9.0 +ballerinaLangVersion=2201.9.3