diff --git a/.codegen.json b/.codegen.json index 39e895e..1fe1622 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "0e509a3", "specHash": "f737b7b", "version": "0.6.1" } +{ "engineHash": "90eaba8", "specHash": "f737b7b", "version": "0.6.1" } diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5abd21e..e84fec9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/README.md b/README.md index a718a1d..5cbe152 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/integrationmappings.md b/docs/integrationmappings.md index 73f3ee4..67085f3 100644 --- a/docs/integrationmappings.md +++ b/docs/integrationmappings.md @@ -57,7 +57,7 @@ See the endpoint docs at ``` -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 @@ -90,7 +90,7 @@ See the endpoint docs at ``` -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 @@ -125,7 +125,7 @@ See the endpoint docs at ``` -userClient.getIntegrationMappings().deleteSlackIntegrationMappingById(integrationMappingId) +userClient.getIntegrationMappings().deleteSlackIntegrationMappingById(slackIntegrationMapping.getId()) ``` ### Arguments diff --git a/src/test/java/com/box/sdkgen/test/integrationmappings/IntegrationMappingsITest.java b/src/test/java/com/box/sdkgen/test/integrationmappings/IntegrationMappingsITest.java index f627cab..f4cfa90 100644 --- a/src/test/java/com/box/sdkgen/test/integrationmappings/IntegrationMappingsITest.java +++ b/src/test/java/com/box/sdkgen/test/integrationmappings/IntegrationMappingsITest.java @@ -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; @@ -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; @@ -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