@@ -4,14 +4,28 @@ import { serializeCreateFolderRequestBody } from '../managers/folders.generated.
4
4
import { deserializeCreateFolderRequestBody } from '../managers/folders.generated.js' ;
5
5
import { serializeCreateFolderRequestBodyParentField } from '../managers/folders.generated.js' ;
6
6
import { deserializeCreateFolderRequestBodyParentField } from '../managers/folders.generated.js' ;
7
+ import { serializeCreateCollaborationRequestBody } from '../managers/userCollaborations.generated.js' ;
8
+ import { deserializeCreateCollaborationRequestBody } from '../managers/userCollaborations.generated.js' ;
9
+ import { serializeCreateCollaborationRequestBodyItemField } from '../managers/userCollaborations.generated.js' ;
10
+ import { deserializeCreateCollaborationRequestBodyItemField } from '../managers/userCollaborations.generated.js' ;
11
+ import { serializeCreateCollaborationRequestBodyItemTypeField } from '../managers/userCollaborations.generated.js' ;
12
+ import { deserializeCreateCollaborationRequestBodyItemTypeField } from '../managers/userCollaborations.generated.js' ;
13
+ import { serializeCreateCollaborationRequestBodyAccessibleByField } from '../managers/userCollaborations.generated.js' ;
14
+ import { deserializeCreateCollaborationRequestBodyAccessibleByField } from '../managers/userCollaborations.generated.js' ;
15
+ import { serializeCreateCollaborationRequestBodyAccessibleByTypeField } from '../managers/userCollaborations.generated.js' ;
16
+ import { deserializeCreateCollaborationRequestBodyAccessibleByTypeField } from '../managers/userCollaborations.generated.js' ;
17
+ import { serializeCreateCollaborationRequestBodyRoleField } from '../managers/userCollaborations.generated.js' ;
18
+ import { deserializeCreateCollaborationRequestBodyRoleField } from '../managers/userCollaborations.generated.js' ;
19
+ import { serializeIntegrationMappings } from '../schemas/integrationMappings.generated.js' ;
20
+ import { deserializeIntegrationMappings } from '../schemas/integrationMappings.generated.js' ;
7
21
import { serializeIntegrationMappingSlackCreateRequest } from '../schemas/integrationMappingSlackCreateRequest.generated.js' ;
8
22
import { deserializeIntegrationMappingSlackCreateRequest } from '../schemas/integrationMappingSlackCreateRequest.generated.js' ;
9
23
import { serializeIntegrationMappingPartnerItemSlack } from '../schemas/integrationMappingPartnerItemSlack.generated.js' ;
10
24
import { deserializeIntegrationMappingPartnerItemSlack } from '../schemas/integrationMappingPartnerItemSlack.generated.js' ;
11
25
import { serializeIntegrationMappingBoxItemSlack } from '../schemas/integrationMappingBoxItemSlack.generated.js' ;
12
26
import { deserializeIntegrationMappingBoxItemSlack } from '../schemas/integrationMappingBoxItemSlack.generated.js' ;
13
- import { serializeIntegrationMappings } from '../schemas/integrationMappings .generated.js' ;
14
- import { deserializeIntegrationMappings } from '../schemas/integrationMappings .generated.js' ;
27
+ import { serializeIntegrationMapping } from '../schemas/integrationMapping .generated.js' ;
28
+ import { deserializeIntegrationMapping } from '../schemas/integrationMapping .generated.js' ;
15
29
import { serializeUpdateSlackIntegrationMappingByIdRequestBody } from '../managers/integrationMappings.generated.js' ;
16
30
import { deserializeUpdateSlackIntegrationMappingByIdRequestBody } from '../managers/integrationMappings.generated.js' ;
17
31
import { serializeIntegrationMappingTeamsCreateRequest } from '../schemas/integrationMappingTeamsCreateRequest.generated.js' ;
@@ -32,10 +46,17 @@ import { BoxClient } from '../client.generated.js';
32
46
import { FolderFull } from '../schemas/folderFull.generated.js' ;
33
47
import { CreateFolderRequestBody } from '../managers/folders.generated.js' ;
34
48
import { CreateFolderRequestBodyParentField } from '../managers/folders.generated.js' ;
49
+ import { CreateCollaborationRequestBody } from '../managers/userCollaborations.generated.js' ;
50
+ import { CreateCollaborationRequestBodyItemField } from '../managers/userCollaborations.generated.js' ;
51
+ import { CreateCollaborationRequestBodyItemTypeField } from '../managers/userCollaborations.generated.js' ;
52
+ import { CreateCollaborationRequestBodyAccessibleByField } from '../managers/userCollaborations.generated.js' ;
53
+ import { CreateCollaborationRequestBodyAccessibleByTypeField } from '../managers/userCollaborations.generated.js' ;
54
+ import { CreateCollaborationRequestBodyRoleField } from '../managers/userCollaborations.generated.js' ;
55
+ import { IntegrationMappings } from '../schemas/integrationMappings.generated.js' ;
35
56
import { IntegrationMappingSlackCreateRequest } from '../schemas/integrationMappingSlackCreateRequest.generated.js' ;
36
57
import { IntegrationMappingPartnerItemSlack } from '../schemas/integrationMappingPartnerItemSlack.generated.js' ;
37
58
import { IntegrationMappingBoxItemSlack } from '../schemas/integrationMappingBoxItemSlack.generated.js' ;
38
- import { IntegrationMappings } from '../schemas/integrationMappings .generated.js' ;
59
+ import { IntegrationMapping } from '../schemas/integrationMapping .generated.js' ;
39
60
import { UpdateSlackIntegrationMappingByIdRequestBody } from '../managers/integrationMappings.generated.js' ;
40
61
import { IntegrationMappingTeamsCreateRequest } from '../schemas/integrationMappingTeamsCreateRequest.generated.js' ;
41
62
import { IntegrationMappingPartnerItemTeamsCreateRequest } from '../schemas/integrationMappingPartnerItemTeamsCreateRequest.generated.js' ;
@@ -45,8 +66,10 @@ import { UpdateTeamsIntegrationMappingByIdRequestBody } from '../managers/integr
45
66
import { generateByteStream } from '../internal/utils.js' ;
46
67
import { getUuid } from '../internal/utils.js' ;
47
68
import { getEnvVar } from '../internal/utils.js' ;
69
+ import { toString } from '../internal/utils.js' ;
48
70
import { getDefaultClient } from './commons.generated.js' ;
49
71
import { getDefaultClientWithUserSubject } from './commons.generated.js' ;
72
+ import { sdToJson } from '../serialization/json.js' ;
50
73
import { SerializedData } from '../serialization/json.js' ;
51
74
import { sdIsEmpty } from '../serialization/json.js' ;
52
75
import { sdIsBoolean } from '../serialization/json.js' ;
@@ -56,45 +79,96 @@ import { sdIsList } from '../serialization/json.js';
56
79
import { sdIsMap } from '../serialization/json.js' ;
57
80
export const client : BoxClient = getDefaultClient ( ) ;
58
81
test ( 'testSlackIntegrationMappings' , async function testSlackIntegrationMappings ( ) : Promise < any > {
59
- const folder : FolderFull = await client . folders . createFolder ( {
82
+ const userId : string = getEnvVar ( 'USER_ID' ) ;
83
+ const slackAutomationUserId : string = getEnvVar ( 'SLACK_AUTOMATION_USER_ID' ) ;
84
+ const slackOrgId : string = getEnvVar ( 'SLACK_ORG_ID' ) ;
85
+ const slackPartnerItemId : string = getEnvVar ( 'SLACK_PARTNER_ITEM_ID' ) ;
86
+ const userClient : BoxClient = getDefaultClientWithUserSubject ( userId ) ;
87
+ const folder : FolderFull = await userClient . folders . createFolder ( {
60
88
name : getUuid ( ) ,
61
89
parent : { id : '0' } satisfies CreateFolderRequestBodyParentField ,
62
90
} satisfies CreateFolderRequestBody ) ;
63
- const slackOrgId : string = '1' ;
64
- const partnerItemId : string = '1' ;
65
- const userId : string = getEnvVar ( 'USER_ID' ) ;
66
- const userClient : BoxClient = getDefaultClientWithUserSubject ( userId ) ;
67
- await expect ( async ( ) => {
91
+ await userClient . userCollaborations . createCollaboration ( {
92
+ item : {
93
+ type : 'folder' as CreateCollaborationRequestBodyItemTypeField ,
94
+ id : folder . id ,
95
+ } satisfies CreateCollaborationRequestBodyItemField ,
96
+ accessibleBy : {
97
+ type : 'user' as CreateCollaborationRequestBodyAccessibleByTypeField ,
98
+ id : slackAutomationUserId ,
99
+ } satisfies CreateCollaborationRequestBodyAccessibleByField ,
100
+ role : 'co-owner' as CreateCollaborationRequestBodyRoleField ,
101
+ } satisfies CreateCollaborationRequestBody ) ;
102
+ const slackIntegrations : IntegrationMappings =
103
+ await userClient . integrationMappings . getSlackIntegrationMapping ( ) ;
104
+ if ( slackIntegrations . entries ! . length == 0 ) {
68
105
await userClient . integrationMappings . createSlackIntegrationMapping ( {
69
106
partnerItem : new IntegrationMappingPartnerItemSlack ( {
70
- id : partnerItemId ,
107
+ id : slackPartnerItemId ,
71
108
slackOrgId : slackOrgId ,
72
109
} ) ,
73
110
boxItem : new IntegrationMappingBoxItemSlack ( { id : folder . id } ) ,
74
111
} satisfies IntegrationMappingSlackCreateRequest ) ;
75
- } ) . rejects . toThrow ( ) ;
76
- const integrationMappings : IntegrationMappings =
112
+ }
113
+ const slackMappings : IntegrationMappings =
77
114
await userClient . integrationMappings . getSlackIntegrationMapping ( ) ;
78
- if ( ! ( integrationMappings . entries ! . length == 0 ) ) {
115
+ if ( ! ( slackMappings . entries ! . length >= 1 ) ) {
79
116
throw new Error ( 'Assertion failed' ) ;
80
117
}
81
- const integrationMappingId : string = '123456' ;
82
- await expect ( async ( ) => {
118
+ const slackIntegrationMapping : IntegrationMapping = slackMappings . entries ! [ 0 ] ;
119
+ if (
120
+ ! ( ( toString ( slackIntegrationMapping . integrationType ) as string ) == 'slack' )
121
+ ) {
122
+ throw new Error ( 'Assertion failed' ) ;
123
+ }
124
+ if (
125
+ ! (
126
+ ( toString ( slackIntegrationMapping . type ) as string ) ==
127
+ 'integration_mapping'
128
+ )
129
+ ) {
130
+ throw new Error ( 'Assertion failed' ) ;
131
+ }
132
+ if (
133
+ ! ( ( toString ( slackIntegrationMapping . boxItem . type ) as string ) == 'folder' )
134
+ ) {
135
+ throw new Error ( 'Assertion failed' ) ;
136
+ }
137
+ if ( ! ( slackIntegrationMapping . partnerItem . id == slackPartnerItemId ) ) {
138
+ throw new Error ( 'Assertion failed' ) ;
139
+ }
140
+ if ( ! ( slackIntegrationMapping . partnerItem . slackWorkspaceId == slackOrgId ) ) {
141
+ throw new Error ( 'Assertion failed' ) ;
142
+ }
143
+ if (
144
+ ! (
145
+ ( toString ( slackIntegrationMapping . partnerItem . type ) as string ) ==
146
+ 'channel'
147
+ )
148
+ ) {
149
+ throw new Error ( 'Assertion failed' ) ;
150
+ }
151
+ const updatedSlackMapping : IntegrationMapping =
83
152
await userClient . integrationMappings . updateSlackIntegrationMappingById (
84
- integrationMappingId ,
153
+ slackIntegrationMapping . id ,
85
154
{
86
155
requestBody : {
87
- boxItem : new IntegrationMappingBoxItemSlack ( { id : '1234567' } ) ,
156
+ boxItem : new IntegrationMappingBoxItemSlack ( { id : folder . id } ) ,
88
157
} satisfies UpdateSlackIntegrationMappingByIdRequestBody ,
89
158
} satisfies UpdateSlackIntegrationMappingByIdOptionalsInput ,
90
159
) ;
91
- } ) . rejects . toThrow ( ) ;
92
- await expect ( async ( ) => {
160
+ if ( ! ( ( toString ( updatedSlackMapping . boxItem . type ) as string ) == 'folder' ) ) {
161
+ throw new Error ( 'Assertion failed' ) ;
162
+ }
163
+ if ( ! ( updatedSlackMapping . boxItem . id == folder . id ) ) {
164
+ throw new Error ( 'Assertion failed' ) ;
165
+ }
166
+ if ( slackMappings . entries ! . length > 2 ) {
93
167
await userClient . integrationMappings . deleteSlackIntegrationMappingById (
94
- integrationMappingId ,
168
+ slackIntegrationMapping . id ,
95
169
) ;
96
- } ) . rejects . toThrow ( ) ;
97
- await client . folders . deleteFolderById ( folder . id ) ;
170
+ }
171
+ await userClient . folders . deleteFolderById ( folder . id ) ;
98
172
} ) ;
99
173
test ( 'testTeamsIntegrationMappings' , async function testTeamsIntegrationMappings ( ) : Promise < any > {
100
174
const folder : FolderFull = await client . folders . createFolder ( {
0 commit comments