Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests for Gratibot #302

Open
JGuzman4 opened this issue Jan 17, 2023 · 1 comment
Open

Add integration tests for Gratibot #302

JGuzman4 opened this issue Jan 17, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@JGuzman4
Copy link

We would like to add test cases to make sure that Gratibot can interact with external services successfully. Integration points include CosmosDB, Slack

@JGuzman4
Copy link
Author

JGuzman4 commented Feb 23, 2023

Did some digging to see how we can automate the creation of a new app and install it into the workspace for integration testing:

Creating the slack app

  1. First, you need to obtain an OAuth access token that you will use to authenticate your API requests. You can do this by creating a new Slack app in the Slack App Directory and then generating an OAuth access token for the app.

Next, you can use the apps.create API method to create a new Slack app. Here's an example API request:

POST https://slack.com/api/apps.create
Content-type: application/json
Authorization: Bearer <your-bot-token>

{
  "name": "My New App",
  "description": "This is a new Slack app",
  "privacy_policy_url": "https://www.example.com/privacy_policy",
  "redirect_uris": ["https://www.example.com/oauth_redirect"],
  "scopes": {
    "bot": {
      "channels:history": true,
      "channels:join": true,
      "chat:write": true
    }
  }
}

Once you have submitted the API request, the apps.create method will return a JSON response that contains information about the newly created app, including its app ID and client ID. You can use these IDs to configure and interact with the app in the Slack API.
2. request permission scopes from users in the workspace. You can do this by calling the apps.permissions.request API method and passing in the necessary parameters. For example, to request the app_mentions:read scope, you can use the following API request:

POST https://slack.com/api/apps.permissions.request
Content-type: application/json
Authorization: Bearer <your-bot-token>

{
  "user": "<user-id>",
  "scopes": ["app_mentions:read"]
}
  1. Once you have received permission from the necessary users, you can use the Slack API's apps.installations.create method to install the app in the workspace. This API method will return an installation object that you can use to interact with the app in the workspace.
POST https://slack.com/api/apps.installations.create
Content-type: application/json
Authorization: Bearer <your-bot-token>

{
  "app_id": "<your-app-id>",
  "metadata": {
    "name": "<your-app-name>",
    "description": "<your-app-description>"
  },
  "scopes": {
    "bot": {
      "app_mentions:read": true
    }
  }
}

Once we have the automation in place for creating the new app and installing it in the workspace, we can run integration tests using the web app version of Slack and cypress.io. See https://medium.com/coveryourads/slack-bot-testing-e7ba6f91a98e

@JGuzman4 JGuzman4 added the enhancement New feature or request label Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant