@@ -475,76 +475,117 @@ class StatsRemoteV2Tests: RemoteTestCase, RESTTestable {
475475
476476 func testFetchPostDetail( ) {
477477 let expect = expectation ( description: " It should return post detail " )
478-
478+
479479 stubRemoteResponse ( sitePostDetailsEndpoint, filename: getPostsDetailsFilename, contentType: . ApplicationJSON)
480-
480+
481481 let feb21 = DateComponents ( year: 2019 , month: 2 , day: 21 )
482482 let date = Calendar . autoupdatingCurrent. date ( from: feb21) !
483-
483+
484484 remote. getDetails ( forPostID: 9001 ) { ( postDetails, error) in
485485 XCTAssertNil ( error)
486486 XCTAssertNotNil ( postDetails)
487-
487+
488488 XCTAssertEqual ( postDetails? . fetchedDate, date)
489489 XCTAssertEqual ( postDetails? . totalViewsCount, 163343 )
490-
490+
491491 let dailyAverages = 10 + 12 + 12 + 12 + 2
492492 XCTAssertEqual ( postDetails? . dailyAveragesPerMonth. count, postDetails? . monthlyBreakdown. count)
493493 XCTAssertEqual ( postDetails? . dailyAveragesPerMonth. count, dailyAverages)
494-
494+
495495 let feb19Averages = postDetails? . dailyAveragesPerMonth. first { $0. date == DateComponents ( year: 2019 , month: 2 ) }
496496 XCTAssertNotNil ( feb19Averages)
497497 XCTAssertEqual ( feb19Averages? . period, . month)
498498 XCTAssertEqual ( feb19Averages? . viewsCount, 112 )
499-
499+
500500 let feb19Views = postDetails? . monthlyBreakdown. first { $0. date == DateComponents ( year: 2019 , month: 2 ) }
501501 XCTAssertNotNil ( feb19Views)
502502 XCTAssertEqual ( feb19Views? . period, . month)
503503 XCTAssertEqual ( feb19Views? . viewsCount, 2578 )
504-
504+
505505 XCTAssertEqual ( postDetails? . lastTwoWeeks. count, 14 )
506-
506+
507507 XCTAssertEqual ( postDetails? . lastTwoWeeks. first? . viewsCount, 112 )
508508 XCTAssertEqual ( postDetails? . lastTwoWeeks. first? . period, . day)
509509 XCTAssertEqual ( postDetails? . lastTwoWeeks. first? . date, DateComponents ( year: 2019 , month: 2 , day: 08 ) )
510-
510+
511511 XCTAssertEqual ( postDetails? . lastTwoWeeks. last? . viewsCount, 324 )
512512 XCTAssertEqual ( postDetails? . lastTwoWeeks. last? . period, . day)
513513 XCTAssertEqual ( postDetails? . lastTwoWeeks. last? . date, DateComponents ( year: 2019 , month: 2 , day: 21 ) )
514-
514+
515515 XCTAssertEqual ( postDetails? . recentWeeks. count, 6 )
516-
516+
517517 let leastRecentWeek = postDetails? . recentWeeks. first
518518 let mostRecentWeek = postDetails? . recentWeeks. last
519-
519+
520520 XCTAssertNotNil ( leastRecentWeek)
521521 XCTAssertNotNil ( mostRecentWeek)
522-
522+
523523 XCTAssertEqual ( leastRecentWeek? . totalViewsCount, 688 )
524524 XCTAssertEqual ( leastRecentWeek? . averageViewsCount, 98 )
525525 XCTAssertEqual ( leastRecentWeek!. changePercentage, 0.0 , accuracy: 0.0000000001 )
526+ XCTAssertFalse ( leastRecentWeek!. isChangeInfinity)
526527 XCTAssertEqual ( leastRecentWeek? . startDay, DateComponents ( year: 2019 , month: 01 , day: 14 ) )
527528 XCTAssertEqual ( leastRecentWeek? . endDay, DateComponents ( year: 2019 , month: 01 , day: 20 ) )
528529 XCTAssertEqual ( leastRecentWeek? . days. count, 7 )
529530 XCTAssertEqual ( leastRecentWeek? . days. first? . date, leastRecentWeek? . startDay)
530531 XCTAssertEqual ( leastRecentWeek? . days. last? . date, leastRecentWeek? . endDay)
531532 XCTAssertEqual ( leastRecentWeek? . days. first? . viewsCount, 174 )
532533 XCTAssertEqual ( leastRecentWeek? . days. last? . viewsCount, 60 )
533-
534+
534535 XCTAssertEqual ( mostRecentWeek? . totalViewsCount, 867 )
535536 XCTAssertEqual ( mostRecentWeek? . averageViewsCount, 181 )
536537 XCTAssertEqual ( mostRecentWeek!. changePercentage, 38.7732 , accuracy: 0.001 )
538+ XCTAssertFalse ( mostRecentWeek!. isChangeInfinity)
537539 XCTAssertEqual ( mostRecentWeek? . startDay, DateComponents ( year: 2019 , month: 02 , day: 18 ) )
538540 XCTAssertEqual ( mostRecentWeek? . endDay, DateComponents ( year: 2019 , month: 02 , day: 21 ) )
539541 XCTAssertEqual ( mostRecentWeek? . days. count, 4 )
540542 XCTAssertEqual ( mostRecentWeek? . days. first? . date, mostRecentWeek? . startDay)
541543 XCTAssertEqual ( mostRecentWeek? . days. last? . date, mostRecentWeek? . endDay)
542544 XCTAssertEqual ( mostRecentWeek? . days. first? . viewsCount, 157 )
543545 XCTAssertEqual ( mostRecentWeek? . days. last? . viewsCount, 324 )
544-
546+
547+ // Test newly added fields
548+ XCTAssertEqual ( postDetails? . highestMonth, 8800 )
549+ XCTAssertEqual ( postDetails? . highestDayAverage, 283 )
550+ XCTAssertEqual ( postDetails? . highestWeekAverage, 334 )
551+
552+ // Test yearly totals
553+ XCTAssertEqual ( postDetails? . yearlyTotals [ 2015 ] , 37861 )
554+ XCTAssertEqual ( postDetails? . yearlyTotals [ 2016 ] , 36447 )
555+ XCTAssertEqual ( postDetails? . yearlyTotals [ 2017 ] , 37529 )
556+ XCTAssertEqual ( postDetails? . yearlyTotals [ 2018 ] , 45429 )
557+ XCTAssertEqual ( postDetails? . yearlyTotals [ 2019 ] , 6077 )
558+
559+ // Test overall averages
560+ XCTAssertEqual ( postDetails? . overallAverages [ 2015 ] , 130 )
561+ XCTAssertEqual ( postDetails? . overallAverages [ 2016 ] , 99 )
562+ XCTAssertEqual ( postDetails? . overallAverages [ 2017 ] , 102 )
563+ XCTAssertEqual ( postDetails? . overallAverages [ 2018 ] , 124 )
564+ XCTAssertEqual ( postDetails? . overallAverages [ 2019 ] , 112 )
565+
566+ // Test fields array
567+ XCTAssertEqual ( postDetails? . fields, [ " period " , " views " ] )
568+
569+ // Test post object
570+ XCTAssertNotNil ( postDetails? . post)
571+ XCTAssertEqual ( postDetails? . post? . postID, 12345 )
572+ XCTAssertEqual ( postDetails? . post? . title, " Sample Blog Post Title " )
573+ XCTAssertEqual ( postDetails? . post? . authorID, " 1234567 " )
574+ XCTAssertEqual ( postDetails? . post? . status, " publish " )
575+ XCTAssertEqual ( postDetails? . post? . type, " post " )
576+ XCTAssertEqual ( postDetails? . post? . excerpt, " This is a sample excerpt. " )
577+ XCTAssertEqual ( postDetails? . post? . name, " sample-blog-post-title " )
578+ XCTAssertEqual ( postDetails? . post? . commentStatus, " open " )
579+ XCTAssertEqual ( postDetails? . post? . password, " " )
580+ XCTAssertEqual ( postDetails? . post? . parent, 0 )
581+ XCTAssertEqual ( postDetails? . post? . guid, " https://example.wordpress.com/?p=12345 " )
582+ XCTAssertEqual ( postDetails? . post? . mimeType, " " )
583+ XCTAssertEqual ( postDetails? . post? . commentCount, " 3 " )
584+ XCTAssertEqual ( postDetails? . post? . permalink, " http://example.wordpress.com/2019/01/15/sample-blog-post-title/ " )
585+
545586 expect. fulfill ( )
546587 }
547-
588+
548589 waitForExpectations ( timeout: timeout, handler: nil )
549590 }
550591
@@ -576,9 +617,11 @@ class StatsRemoteV2Tests: RemoteTestCase, RESTTestable {
576617 XCTAssertEqual ( summary? . summaryData [ 9 ] . likesCount, 126 )
577618 XCTAssertEqual ( summary? . summaryData [ 9 ] . commentsCount, 0 )
578619
579- XCTAssertEqual ( summary? . summaryData [ 9 ] . periodStartDate, Calendar . autoupdatingCurrent. date ( byAdding: . day,
580- value: 7 * 9 , // 7 days * nine objects
581- to: dec17Date) )
620+ XCTAssertEqual ( summary? . summaryData [ 9 ] . periodStartDate, Calendar . autoupdatingCurrent. date (
621+ byAdding: . day,
622+ value: 7 * 9 , // 7 days * nine objects
623+ to: dec17Date
624+ ) )
582625
583626 expect. fulfill ( )
584627 }
0 commit comments