Skip to content

test: Improve Slack integration mapping test (box/box-codegen#710) #286

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

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "0e509a3", "specHash": "f737b7b", "version": "0.6.1" }
{ "engineHash": "90eaba8", "specHash": "f737b7b", "version": "0.6.1" }
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
APP_ITEM_ASSOCIATION_FOLDER_ID: ${{ secrets.APP_ITEM_ASSOCIATION_FOLDER_ID }}
WORKFLOW_FOLDER_ID: ${{ secrets.WORKFLOW_FOLDER_ID }}
APP_ITEM_SHARED_LINK: ${{ secrets.APP_ITEM_SHARED_LINK }}
SLACK_AUTOMATION_USER_ID: ${{ secrets.SLACK_AUTOMATION_USER_ID }}
SLACK_ORG_ID: ${{ secrets.SLACK_ORG_ID }}
SLACK_PARTNER_ITEM_ID: ${{ secrets.SLACK_PARTNER_ITEM_ID }}
run: ./gradlew check --stacktrace

- name: Coverage
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Now select `Authorization` and submit application to be reviewed by account admi
5. Set environment variable: `WORKFLOW_FOLDER_ID` with the ID of the Relay workflow that deletes the file that triggered the workflow. The workflow should have a manual start to be able to start it from the API.
6. Set environment variable: `APP_ITEM_ASSOCIATION_FILE_ID` to the ID of the file with associated app item and `APP_ITEM_ASSOCIATION_FOLDER_ID` to the ID of the folder with associated app item.
7. Set environment variable: `APP_ITEM_SHARED_LINK` to the shared link associated with app item.
8. Set environment variable: `SLACK_AUTOMATION_USER_ID` to the ID of the user responsible for the Slack automation, `SLACK_ORG_ID` to the ID of the Slack organization and `SLACK_PARTNER_ITEM_ID` to the ID of the Slack partner item.

### Start integration tests

Expand Down
6 changes: 3 additions & 3 deletions docs/integrationmappings.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See the endpoint docs at

<!-- sample post_integration_mappings_slack -->
```
userClient.getIntegrationMappings().createSlackIntegrationMapping(new IntegrationMappingSlackCreateRequest(new IntegrationMappingPartnerItemSlack.IntegrationMappingPartnerItemSlackBuilder(partnerItemId).slackOrgId(slackOrgId).build(), new IntegrationMappingBoxItemSlack(folder.getId())))
userClient.getIntegrationMappings().createSlackIntegrationMapping(new IntegrationMappingSlackCreateRequest(new IntegrationMappingPartnerItemSlack.IntegrationMappingPartnerItemSlackBuilder(slackPartnerItemId).slackOrgId(slackOrgId).build(), new IntegrationMappingBoxItemSlack(folder.getId())))
```

### Arguments
Expand Down Expand Up @@ -90,7 +90,7 @@ See the endpoint docs at

<!-- sample put_integration_mappings_slack_id -->
```
userClient.getIntegrationMappings().updateSlackIntegrationMappingById(integrationMappingId, new UpdateSlackIntegrationMappingByIdRequestBody.UpdateSlackIntegrationMappingByIdRequestBodyBuilder().boxItem(new IntegrationMappingBoxItemSlack("1234567")).build())
userClient.getIntegrationMappings().updateSlackIntegrationMappingById(slackIntegrationMapping.getId(), new UpdateSlackIntegrationMappingByIdRequestBody.UpdateSlackIntegrationMappingByIdRequestBodyBuilder().boxItem(new IntegrationMappingBoxItemSlack(folder.getId())).build())
```

### Arguments
Expand Down Expand Up @@ -125,7 +125,7 @@ See the endpoint docs at

<!-- sample delete_integration_mappings_slack_id -->
```
userClient.getIntegrationMappings().deleteSlackIntegrationMappingById(integrationMappingId)
userClient.getIntegrationMappings().deleteSlackIntegrationMappingById(slackIntegrationMapping.getId())
```

### Arguments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.box.sdkgen.test.integrationmappings;

import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
import static com.box.sdkgen.internal.utils.UtilsManager.getEnvVar;
import static com.box.sdkgen.internal.utils.UtilsManager.getUuid;
import static com.box.sdkgen.test.commons.CommonsManager.getDefaultClient;
Expand All @@ -11,8 +12,15 @@
import com.box.sdkgen.managers.folders.CreateFolderRequestBodyParentField;
import com.box.sdkgen.managers.integrationmappings.UpdateSlackIntegrationMappingByIdRequestBody;
import com.box.sdkgen.managers.integrationmappings.UpdateTeamsIntegrationMappingByIdRequestBody;
import com.box.sdkgen.managers.usercollaborations.CreateCollaborationRequestBody;
import com.box.sdkgen.managers.usercollaborations.CreateCollaborationRequestBodyAccessibleByField;
import com.box.sdkgen.managers.usercollaborations.CreateCollaborationRequestBodyAccessibleByTypeField;
import com.box.sdkgen.managers.usercollaborations.CreateCollaborationRequestBodyItemField;
import com.box.sdkgen.managers.usercollaborations.CreateCollaborationRequestBodyItemTypeField;
import com.box.sdkgen.managers.usercollaborations.CreateCollaborationRequestBodyRoleField;
import com.box.sdkgen.schemas.folderfull.FolderFull;
import com.box.sdkgen.schemas.folderreference.FolderReference;
import com.box.sdkgen.schemas.integrationmapping.IntegrationMapping;
import com.box.sdkgen.schemas.integrationmappingboxitemslack.IntegrationMappingBoxItemSlack;
import com.box.sdkgen.schemas.integrationmappingpartneritemslack.IntegrationMappingPartnerItemSlack;
import com.box.sdkgen.schemas.integrationmappingpartneritemteamscreaterequest.IntegrationMappingPartnerItemTeamsCreateRequest;
Expand All @@ -28,50 +36,69 @@ public class IntegrationMappingsITest {

@Test
public void testSlackIntegrationMappings() {
String userId = getEnvVar("USER_ID");
String slackAutomationUserId = getEnvVar("SLACK_AUTOMATION_USER_ID");
String slackOrgId = getEnvVar("SLACK_ORG_ID");
String slackPartnerItemId = getEnvVar("SLACK_PARTNER_ITEM_ID");
BoxClient userClient = getDefaultClientWithUserSubject(userId);
FolderFull folder =
client
userClient
.getFolders()
.createFolder(
new CreateFolderRequestBody(
getUuid(), new CreateFolderRequestBodyParentField("0")));
String slackOrgId = "1";
String partnerItemId = "1";
String userId = getEnvVar("USER_ID");
BoxClient userClient = getDefaultClientWithUserSubject(userId);
assertThrows(
RuntimeException.class,
() ->
userClient
.getIntegrationMappings()
.createSlackIntegrationMapping(
new IntegrationMappingSlackCreateRequest(
new IntegrationMappingPartnerItemSlack
.IntegrationMappingPartnerItemSlackBuilder(partnerItemId)
.slackOrgId(slackOrgId)
.build(),
new IntegrationMappingBoxItemSlack(folder.getId()))));
IntegrationMappings integrationMappings =
userClient
.getUserCollaborations()
.createCollaboration(
new CreateCollaborationRequestBody(
new CreateCollaborationRequestBodyItemField
.CreateCollaborationRequestBodyItemFieldBuilder()
.type(CreateCollaborationRequestBodyItemTypeField.FOLDER)
.id(folder.getId())
.build(),
new CreateCollaborationRequestBodyAccessibleByField
.CreateCollaborationRequestBodyAccessibleByFieldBuilder(
CreateCollaborationRequestBodyAccessibleByTypeField.USER)
.id(slackAutomationUserId)
.build(),
CreateCollaborationRequestBodyRoleField.CO_OWNER));
IntegrationMappings slackIntegrations =
userClient.getIntegrationMappings().getSlackIntegrationMapping();
assert integrationMappings.getEntries().size() == 0;
String integrationMappingId = "123456";
assertThrows(
RuntimeException.class,
() ->
userClient
.getIntegrationMappings()
.updateSlackIntegrationMappingById(
integrationMappingId,
new UpdateSlackIntegrationMappingByIdRequestBody
.UpdateSlackIntegrationMappingByIdRequestBodyBuilder()
.boxItem(new IntegrationMappingBoxItemSlack("1234567"))
.build()));
assertThrows(
RuntimeException.class,
() ->
userClient
.getIntegrationMappings()
.deleteSlackIntegrationMappingById(integrationMappingId));
client.getFolders().deleteFolderById(folder.getId());
if (slackIntegrations.getEntries().size() == 0) {
userClient
.getIntegrationMappings()
.createSlackIntegrationMapping(
new IntegrationMappingSlackCreateRequest(
new IntegrationMappingPartnerItemSlack.IntegrationMappingPartnerItemSlackBuilder(
slackPartnerItemId)
.slackOrgId(slackOrgId)
.build(),
new IntegrationMappingBoxItemSlack(folder.getId())));
}
IntegrationMappings slackMappings =
userClient.getIntegrationMappings().getSlackIntegrationMapping();
assert slackMappings.getEntries().size() >= 1;
IntegrationMapping slackIntegrationMapping = slackMappings.getEntries().get(0);
assert convertToString(slackIntegrationMapping.getIntegrationType()).equals("slack");
assert convertToString(slackIntegrationMapping.getType()).equals("integration_mapping");
assert convertToString(slackIntegrationMapping.getBoxItem().getType()).equals("folder");
IntegrationMapping updatedSlackMapping =
userClient
.getIntegrationMappings()
.updateSlackIntegrationMappingById(
slackIntegrationMapping.getId(),
new UpdateSlackIntegrationMappingByIdRequestBody
.UpdateSlackIntegrationMappingByIdRequestBodyBuilder()
.boxItem(new IntegrationMappingBoxItemSlack(folder.getId()))
.build());
assert convertToString(updatedSlackMapping.getBoxItem().getType()).equals("folder");
assert updatedSlackMapping.getBoxItem().getId().equals(folder.getId());
if (slackMappings.getEntries().size() > 2) {
userClient
.getIntegrationMappings()
.deleteSlackIntegrationMappingById(slackIntegrationMapping.getId());
}
userClient.getFolders().deleteFolderById(folder.getId());
}

@Test
Expand Down
Loading