-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathMostStarredGithubReposJSONTests.swift
106 lines (60 loc) · 4.34 KB
/
MostStarredGithubReposJSONTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// MostStarredGithubReposJSONTests.swift
// mobile-coding-challenge-unit-tests
//
// Created by Mobile on 9/20/20.
// Copyright © 2020 Zakariae. All rights reserved.
//
import XCTest
import Moya
import SwiftyJSON
class MostStarredGithubReposJSONTests: XCTestCase {
override func setUp() {
super.setUp()
self.continueAfterFailure = false
}
func testForIsTheMostStarredGithubReposJSONCorrect(){
let expectation = self.expectation(description: "theMostStarredGithubReposJSONExpectation")
var previousMonthDate: Date?
if let _previousMonthDate = Calendar.current.date(byAdding: .month, value: -1, to: Date()){
previousMonthDate = _previousMonthDate
let requestProvider = MoyaProvider<RequestHandler>()
requestProvider.request(.getMostGithubRepos(created_at: previousMonthDate!.formattedDate(using: "YYYY-MM-dd"), page: 1)) { result in
switch result {
case let .success(moyaResponse):
let responseJSON = JSON(moyaResponse.data)
var mostStarredGithubRepos: [JSON]?
var totalCount : Int?
if moyaResponse.statusCode == 200{
if let _mostStarredGithubRepos = responseJSON["items"].array{
if let _totalCount = responseJSON["total_count"].int{
mostStarredGithubRepos = _mostStarredGithubRepos
totalCount = _totalCount
var totalChecks: Int = 0
for _mostStarredGithubRepo in mostStarredGithubRepos!{
let mostStarredGithubRepo = GithubRepositoryEntity(from: _mostStarredGithubRepo)
XCTAssertNotNil(mostStarredGithubRepo, "TEST: IS THE MOST STARRED GITHUB REPOS JSON CORRECT => Response JSON is not fit : Something missed from GithubRepositoryEntity")
totalChecks += 1
}
XCTAssertEqual(totalChecks, mostStarredGithubRepos!.count)
expectation.fulfill()
return
}
XCTAssertNotNil(totalCount, "TEST: IS THE MOST STARRED GITHUB REPOS JSON CORRECT => Response JSON is not fit : (total_count => Int) is not exists or is not an integer.")
return
}
XCTAssertNotNil(mostStarredGithubRepos, "TEST: IS THE MOST STARRED GITHUB REPOS JSON CORRECT => Response JSON is not fit : [items] is not exists or is not an array.")
return
}
XCTAssertEqual(moyaResponse.statusCode, 200, "TEST: IS THE MOST STARRED GITHUB REPOS JSON CORRECT => Created_at is not fit")
expectation.fulfill()
default:
expectation.fulfill()
}
}
self.wait(for: [expectation], timeout: 10.0)
return
}
XCTAssertNotNil(previousMonthDate, "TEST: IS THE MOST STARRED GITHUB REPOS JSON CORRECT => Previous month date is incorrect")
}
}