@@ -8,7 +8,7 @@ const metaModelDocumentFields = require('../testData/sfDocumentFields.json')
8
8
const sfDocumentMetamodel = require ( '../testData/sfDocumentMetamodel.json' )
9
9
const { globalConsts } = require ( '../../lib/common.js' ) ;
10
10
const {
11
- getContext, fetchToken, defaultCfg, testsCommon,
11
+ getContext, fetchToken, describeDocReq , defaultCfg, testsCommon,
12
12
} = require ( '../common.js' ) ;
13
13
14
14
describe ( 'Upsert v2 Object test' , ( ) => {
@@ -90,49 +90,43 @@ describe('Upsert v2 Object test', () => {
90
90
91
91
describe ( 'Main process' , ( ) => {
92
92
const configuration = {
93
+ ...defaultCfg ,
93
94
secretId : 'secretId' ,
94
95
sobject : 'Document' ,
95
96
typeOfSearch : 'allFields' ,
96
97
updateFields : [ 'Url' , 'Body' ] ,
97
98
lookupField : 'Id'
98
99
}
99
100
100
- it . skip ( 'Object found, going to update' , async ( ) => {
101
+ it ( 'Object found, going to update' , async ( ) => {
101
102
const testCfg = {
102
103
...configuration
103
104
}
104
105
const msg = {
105
106
body : {
106
107
Id : 1 ,
107
108
Url : '😂' ,
108
- Body : 'http://test.env.mock/somedata.txt '
109
+ Body : 'YXNkYXNkYXNkcXdlcXdlcXdl '
109
110
}
110
111
}
111
-
112
112
fetchToken ( )
113
- const describeReq = nock ( testsCommon . instanceUrl )
114
- . get ( `/services/data/v ${ globalConsts . SALESFORCE_API_VERSION } /sobjects/Document/describe` )
115
- . reply ( 200 , metaModelDocumentReply )
113
+ describeDocReq ( globalConsts . SALESFORCE_API_VERSION , metaModelDocumentReply )
114
+ fetchToken ( )
115
+ describeDocReq ( globalConsts . SALESFORCE_API_VERSION , metaModelDocumentReply )
116
116
fetchToken ( )
117
117
const queryReq = nock ( testsCommon . instanceUrl )
118
- . get ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /query?q=${
119
- testsCommon . buildSOQL ( metaModelDocumentReply , { Id : 1 } )
118
+ . get ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /query?q=${ testsCommon . buildSOQL ( metaModelDocumentReply , { Id : 1 } )
120
119
} `)
121
120
. reply ( 200 , { done : true , totalSize : 1 , records : [ { Id : 1 , Url : '😂' } ] } )
122
121
fetchToken ( ) ;
123
122
const patchDocReq = nock ( testsCommon . instanceUrl )
124
123
. patch ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /sobjects/Document/1` , { Url : '😂' , Body : 'YXNkYXNkYXNkcXdlcXdlcXdl' } )
125
124
. reply ( 204 )
126
- const getTxtReq = nock ( 'http://test.env.mock' )
127
- . get ( '/somedata.txt' )
128
- . replyWithFile ( 200 , `${ __dirname } /../testData/somedata.txt` ) ;
129
125
130
126
const result = await upsert . process . call ( getContext ( ) , msg , testCfg )
131
127
expect ( result . body . success ) . to . eql ( true ) ;
132
- describeReq . done ( )
133
128
queryReq . done ( )
134
129
patchDocReq . done ( )
135
- getTxtReq . done ( )
136
130
} )
137
131
138
132
it ( 'Object not found, going to create' , async ( ) => {
@@ -147,13 +141,12 @@ describe('Upsert v2 Object test', () => {
147
141
}
148
142
149
143
fetchToken ( )
150
- const describeReq = nock ( testsCommon . instanceUrl )
151
- . get ( `/services/data/v ${ globalConsts . SALESFORCE_API_VERSION } /sobjects/Document/describe` )
152
- . reply ( 200 , metaModelDocumentReply )
144
+ describeDocReq ( globalConsts . SALESFORCE_API_VERSION , metaModelDocumentReply )
145
+ fetchToken ( )
146
+ describeDocReq ( globalConsts . SALESFORCE_API_VERSION , metaModelDocumentReply )
153
147
fetchToken ( )
154
148
const queryReq = nock ( testsCommon . instanceUrl )
155
- . get ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /query?q=${
156
- testsCommon . buildSOQL ( metaModelDocumentReply , { Id : 1 } )
149
+ . get ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /query?q=${ testsCommon . buildSOQL ( metaModelDocumentReply , { Id : 1 } )
157
150
} `)
158
151
. reply ( 200 , { done : true , totalSize : 1 , records : [ ] } )
159
152
fetchToken ( )
@@ -163,7 +156,6 @@ describe('Upsert v2 Object test', () => {
163
156
164
157
const result = await upsert . process . call ( getContext ( ) , msg , testCfg )
165
158
expect ( result . body . success ) . to . eql ( true ) ;
166
- describeReq . done ( )
167
159
queryReq . done ( )
168
160
postDocReq . done ( )
169
161
} )
@@ -179,17 +171,14 @@ describe('Upsert v2 Object test', () => {
179
171
}
180
172
181
173
fetchToken ( )
182
- const describeReq = nock ( testsCommon . instanceUrl )
183
- . get ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /sobjects/Document/describe` )
184
- . reply ( 200 , metaModelDocumentReply )
174
+ describeDocReq ( globalConsts . SALESFORCE_API_VERSION , metaModelDocumentReply )
185
175
fetchToken ( )
186
176
const createDocReq = nock ( testsCommon . instanceUrl )
187
177
. post ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /sobjects/Document` , msg . body )
188
178
. reply ( 200 , { id : 2 , success : true , } )
189
179
190
180
const result = await upsert . process . call ( getContext ( ) , msg , testCfg )
191
181
expect ( result . body . success ) . to . eql ( true ) ;
192
- describeReq . done ( )
193
182
createDocReq . done ( )
194
183
} )
195
184
@@ -204,10 +193,13 @@ describe('Upsert v2 Object test', () => {
204
193
}
205
194
}
206
195
196
+ fetchToken ( )
197
+ const describeReq = nock ( testsCommon . instanceUrl )
198
+ . get ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /sobjects/Document/describe` )
199
+ . reply ( 200 , metaModelDocumentReply )
207
200
fetchToken ( )
208
201
const scope = nock ( testsCommon . instanceUrl )
209
- . get ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /query?q=${
210
- testsCommon . buildSOQL ( metaModelDocumentReply , { Id : 1 } )
202
+ . get ( `/services/data/v${ globalConsts . SALESFORCE_API_VERSION } /query?q=${ testsCommon . buildSOQL ( metaModelDocumentReply , { Id : 1 } )
211
203
} `)
212
204
. reply ( 200 , { done : true , totalSize : 1 , records : [ 1 , 2 ] } )
213
205
@@ -217,6 +209,7 @@ describe('Upsert v2 Object test', () => {
217
209
expect ( err . message ) . to . eql ( 'Found more than 1 Object' ) ;
218
210
}
219
211
scope . done ( )
212
+ describeReq . done ( )
220
213
} )
221
214
} )
222
215
} )
0 commit comments