Skip to content

Commit

Permalink
test: add tests for App item associations (box/box-codegen#561) (#221)
Browse files Browse the repository at this point in the history
Co-authored-by: box-sdk-build <[email protected]>
  • Loading branch information
box-sdk-build and box-sdk-build authored Sep 6, 2024
1 parent 546f487 commit 43ea668
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "engineHash": "2994c4a", "specHash": "6ca858e", "version": "0.4.0" }
{ "engineHash": "66f851a", "specHash": "6ca858e", "version": "0.4.0" }
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ To run integration tests, you need several environment variables specifying your
4. Set the `USER_ID` environment variable to its corresponding value from the `General Settings` tab the section `App Info` of your application.
5. Set the `BOX_FILE_REQUEST_ID` environment variable to the ID of file request already created in the user account, `BOX_EXTERNAL_USER_EMAIL` with email of free external user which not belongs to any enterprise.
6. Set the `WORKFLOW_FOLDER_ID` envornment variable to 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.
7. 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.

### Running tests

Expand Down
32 changes: 32 additions & 0 deletions Tests/AppItemAssociations/AppItemAssociationsManagerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Foundation
import BoxSdkGen
import XCTest

class AppItemAssociationsManagerTests: XCTestCase {

public func testListFileAppItemAssocations() async throws {
let client: BoxClient = CommonsManager().getDefaultClientWithUserSubject(userId: Utils.getEnvironmentVariable(name: "USER_ID"))
let fileId: String = Utils.getEnvironmentVariable(name: "APP_ITEM_ASSOCIATION_FILE_ID")
let fileAppItemAssociations: AppItemAssociations = try await client.appItemAssociations.getFileAppItemAssociations(fileId: fileId)
XCTAssertTrue(fileAppItemAssociations.entries!.count == 1)
let association: AppItemAssociation = fileAppItemAssociations.entries![0]
XCTAssertTrue(association.id != "")
XCTAssertTrue(Utils.Strings.toString(value: association.appItem.applicationType) == "hubs")
XCTAssertTrue(Utils.Strings.toString(value: association.appItem.type) == "app_item")
let file: FileFull = try await client.files.getFileById(fileId: fileId, queryParams: GetFileByIdQueryParams(fields: ["is_associated_with_app_item"]))
XCTAssertTrue(file.isAssociatedWithAppItem! == true)
}

public func testListFolderAppItemAssocations() async throws {
let client: BoxClient = CommonsManager().getDefaultClientWithUserSubject(userId: Utils.getEnvironmentVariable(name: "USER_ID"))
let folderId: String = Utils.getEnvironmentVariable(name: "APP_ITEM_ASSOCIATION_FOLDER_ID")
let folderAppItemAssociations: AppItemAssociations = try await client.appItemAssociations.getFolderAppItemAssociations(folderId: folderId)
XCTAssertTrue(folderAppItemAssociations.entries!.count == 1)
let association: AppItemAssociation = folderAppItemAssociations.entries![0]
XCTAssertTrue(association.id != "")
XCTAssertTrue(Utils.Strings.toString(value: association.appItem.applicationType) == "hubs")
XCTAssertTrue(Utils.Strings.toString(value: association.appItem.type) == "app_item")
let folder: FolderFull = try await client.folders.getFolderById(folderId: folderId, queryParams: GetFolderByIdQueryParams(fields: ["is_associated_with_app_item"]))
XCTAssertTrue(folder.isAssociatedWithAppItem! == true)
}
}
10 changes: 8 additions & 2 deletions docs/AppItemAssociations.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ This operation is performed by calling function `getFileAppItemAssociations`.
See the endpoint docs at
[API Reference](https://developer.box.com/reference/get-files-id-app-item-associations/).

*Currently we don't have an example for calling `getFileAppItemAssociations` in integration tests*
<!-- sample get_files_id_app_item_associations -->
```
try await client.appItemAssociations.getFileAppItemAssociations(fileId: fileId)
```

### Arguments

Expand Down Expand Up @@ -51,7 +54,10 @@ This operation is performed by calling function `getFolderAppItemAssociations`.
See the endpoint docs at
[API Reference](https://developer.box.com/reference/get-folders-id-app-item-associations/).

*Currently we don't have an example for calling `getFolderAppItemAssociations` in integration tests*
<!-- sample get_folders_id_app_item_associations -->
```
try await client.appItemAssociations.getFolderAppItemAssociations(folderId: folderId)
```

### Arguments

Expand Down
2 changes: 1 addition & 1 deletion docs/Files.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ See the endpoint docs at

<!-- sample get_files_id -->
```
try await client.files.getFileById(fileId: file.id)
try await client.files.getFileById(fileId: fileId, queryParams: GetFileByIdQueryParams(fields: ["is_associated_with_app_item"]))
```

### Arguments
Expand Down
2 changes: 1 addition & 1 deletion docs/Folders.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See the endpoint docs at

<!-- sample get_folders_id -->
```
try await client.folders.getFolderById(folderId: newFolder.id)
try await client.folders.getFolderById(folderId: folderId, queryParams: GetFolderByIdQueryParams(fields: ["is_associated_with_app_item"]))
```

### Arguments
Expand Down

0 comments on commit 43ea668

Please sign in to comment.