@@ -53,6 +53,28 @@ final class VeryfiSDKTests: XCTestCase {
53
53
wait ( for: [ expectation] , timeout: 20.0 )
54
54
}
55
55
56
+ func testGetDocumentWithQueryItems( ) {
57
+ if ( mockResponses) {
58
+ client = ClientSpy ( clientId: clientId, clientSecret: clientSecret, username: username, apiKey: apiKey, resource: " getDocuments " )
59
+ }
60
+
61
+ let expectation = XCTestExpectation ( description: " Get all documents in a JSON array " )
62
+ let queryItems = [ URLQueryItem ( name: " order_by " , value: " created " ) ]
63
+ client. getDocuments ( queryItems: queryItems, withCompletion: { result in
64
+ switch result {
65
+ case . success( let data) :
66
+ let jsonResponse = try ? JSONSerialization . jsonObject ( with: data, options: [ ] ) as? NSDictionary
67
+ XCTAssertGreaterThanOrEqual ( jsonResponse!. count, 2 )
68
+ case . failure( let error) :
69
+ print ( error)
70
+ XCTAssertTrue ( false )
71
+ }
72
+ expectation. fulfill ( )
73
+ } )
74
+
75
+ wait ( for: [ expectation] , timeout: 20.0 )
76
+ }
77
+
56
78
func testGetDocument( ) {
57
79
let expectation = XCTestExpectation ( description: " Get a document by id in a JSON " )
58
80
@@ -326,7 +348,7 @@ final class VeryfiSDKTests: XCTestCase {
326
348
327
349
let expectation = XCTestExpectation ( description: " Add line item to document " )
328
350
let documentId = 63480993
329
- let params = AddLineItem ( order: 20 , description: " Test " , total: 44.4 )
351
+ let params = AddLineItem ( order: 20 , description: " Test " , total: 44.0 )
330
352
params. sku = " testsku "
331
353
client. addLineItem ( documentId: String ( documentId) , params: params, withCompletion: { result in
332
354
switch result {
@@ -353,28 +375,48 @@ final class VeryfiSDKTests: XCTestCase {
353
375
client = ClientSpy ( clientId: clientId, clientSecret: clientSecret, username: username, apiKey: apiKey, resource: " addLineItem " )
354
376
}
355
377
356
- let expectation = XCTestExpectation ( description: " Add line item to document " )
378
+ let expectation1 = XCTestExpectation ( description: " Add line item to document " )
357
379
let documentId = 63480993
358
- let lineItemId = 190399931
359
- let params = UpdateLineItem ( )
360
- params . description = " Test "
361
- client. updateLineItem ( documentId: String ( documentId) , lineItemId : String ( lineItemId ) , params: params , withCompletion: { result in
380
+ var lineItemId = 0
381
+ let params1 = AddLineItem ( order : 20 , description : " Test " , total : 44.0 )
382
+ params1 . sku = " testsku "
383
+ client. addLineItem ( documentId: String ( documentId) , params: params1 , withCompletion: { result in
362
384
switch result {
363
385
case . success( let data) :
364
386
let jsonResponse = try ? JSONSerialization . jsonObject ( with: data, options: [ ] ) as? NSDictionary
365
387
if mockResponses {
366
388
XCTAssertGreaterThanOrEqual ( jsonResponse!. count, 2 )
367
389
} else {
368
- XCTAssertEqual ( jsonResponse![ " description " ] as? String , params . description )
390
+ lineItemId = jsonResponse![ " id " ] as? Int ?? 0
369
391
}
370
392
case . failure( let error) :
371
393
print ( error)
372
394
XCTFail ( )
373
395
}
374
- expectation . fulfill ( )
396
+ expectation1 . fulfill ( )
375
397
} )
398
+ wait ( for: [ expectation1] , timeout: 20.0 )
376
399
377
- wait ( for: [ expectation] , timeout: 20.0 )
400
+ let expectation2 = XCTestExpectation ( description: " Update line item to document " )
401
+ let params2 = UpdateLineItem ( )
402
+ params2. description = " Test "
403
+ client. updateLineItem ( documentId: String ( documentId) , lineItemId: String ( lineItemId) , params: params2, withCompletion: { result in
404
+ switch result {
405
+ case . success( let data) :
406
+ let jsonResponse = try ? JSONSerialization . jsonObject ( with: data, options: [ ] ) as? NSDictionary
407
+ if mockResponses {
408
+ XCTAssertGreaterThanOrEqual ( jsonResponse!. count, 2 )
409
+ } else {
410
+ XCTAssertEqual ( jsonResponse![ " description " ] as? String , params2. description)
411
+ }
412
+ case . failure( let error) :
413
+ print ( error)
414
+ XCTFail ( )
415
+ }
416
+ expectation2. fulfill ( )
417
+ } )
418
+
419
+ wait ( for: [ expectation2] , timeout: 20.0 )
378
420
}
379
421
380
422
func testDeleteDocumentLineItems( ) {
0 commit comments