@@ -440,6 +440,95 @@ class APICommandTests: XCTestCase {
440440 }
441441 }
442442
443+ func testClientVersionAPIMethod( ) {
444+ let clientVersion = API . clientVersion ( )
445+ XCTAssertTrue ( clientVersion. contains ( ParseConstants . sdk) )
446+ XCTAssertTrue ( clientVersion. contains ( ParseConstants . version) )
447+
448+ let splitString = clientVersion
449+ . components ( separatedBy: ParseConstants . sdk)
450+ XCTAssertEqual ( splitString. count, 2 )
451+ //If successful, will remove `swift` resulting in ""
452+ XCTAssertEqual ( splitString [ 0 ] , " " )
453+ XCTAssertEqual ( splitString [ 1 ] , ParseConstants . version)
454+
455+ //Test incorrect split
456+ let splitString2 = clientVersion
457+ . components ( separatedBy: " hello " )
458+ XCTAssertEqual ( splitString2. count, 1 )
459+ XCTAssertEqual ( splitString2 [ 0 ] , clientVersion)
460+ }
461+
462+ func testClientVersionHeader( ) {
463+ let headers = API . getHeaders ( options: [ ] )
464+ XCTAssertEqual ( headers [ " X-Parse-Client-Version " ] , API . clientVersion ( ) )
465+
466+ let post = API . Command < Level , NoBody ? > ( method: . POST, path: . login) { _ in
467+ return nil
468+ }
469+ switch post. prepareURLRequest ( options: [ ] ) {
470+
471+ case . success( let request) :
472+ if request. allHTTPHeaderFields ? [ " X-Parse-Client-Version " ] != API . clientVersion ( ) {
473+ XCTFail ( " Should contain correct Client Version header " )
474+ }
475+ case . failure( let error) :
476+ XCTFail ( error. localizedDescription)
477+ }
478+
479+ let put = API . Command < Level , NoBody ? > ( method: . PUT, path: . login) { _ in
480+ return nil
481+ }
482+ switch put. prepareURLRequest ( options: [ ] ) {
483+
484+ case . success( let request) :
485+ if request. allHTTPHeaderFields ? [ " X-Parse-Client-Version " ] != API . clientVersion ( ) {
486+ XCTFail ( " Should contain correct Client Version header " )
487+ }
488+ case . failure( let error) :
489+ XCTFail ( error. localizedDescription)
490+ }
491+
492+ let patch = API . Command < Level , NoBody ? > ( method: . PATCH, path: . login) { _ in
493+ return nil
494+ }
495+ switch patch. prepareURLRequest ( options: [ ] ) {
496+
497+ case . success( let request) :
498+ if request. allHTTPHeaderFields ? [ " X-Parse-Client-Version " ] != API . clientVersion ( ) {
499+ XCTFail ( " Should contain correct Client Version header " )
500+ }
501+ case . failure( let error) :
502+ XCTFail ( error. localizedDescription)
503+ }
504+
505+ let delete = API . Command < Level , NoBody ? > ( method: . DELETE, path: . login) { _ in
506+ return nil
507+ }
508+ switch delete. prepareURLRequest ( options: [ ] ) {
509+
510+ case . success( let request) :
511+ if request. allHTTPHeaderFields ? [ " X-Parse-Client-Version " ] != API . clientVersion ( ) {
512+ XCTFail ( " Should contain correct Client Version header " )
513+ }
514+ case . failure( let error) :
515+ XCTFail ( error. localizedDescription)
516+ }
517+
518+ let get = API . Command < Level , NoBody ? > ( method: . GET, path: . login) { _ in
519+ return nil
520+ }
521+ switch get. prepareURLRequest ( options: [ ] ) {
522+
523+ case . success( let request) :
524+ if request. allHTTPHeaderFields ? [ " X-Parse-Client-Version " ] != API . clientVersion ( ) {
525+ XCTFail ( " Should contain correct Client Version header " )
526+ }
527+ case . failure( let error) :
528+ XCTFail ( error. localizedDescription)
529+ }
530+ }
531+
443532 func testIdempodency( ) {
444533 let headers = API . getHeaders ( options: [ ] )
445534 XCTAssertNotNil ( headers [ " X-Parse-Request-Id " ] )
0 commit comments