Created
April 11, 2022 22:13
-
-
Save Viniciuscarvalho/ac81aaf09ee0c397507588375ee2c106 to your computer and use it in GitHub Desktop.
ServiceManagerTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import XCTest | |
| @testable import DeliveryAppChallenge | |
| final class ServiceManagerTests: XCTestCase { | |
| // MARK: Subject under test | |
| var sut: APIService! | |
| // MARK: Test setup | |
| override func setUp() { | |
| super.setUp() | |
| self.sut = APIService() | |
| } | |
| override func tearDown() { | |
| super.tearDown() | |
| self.sut = nil | |
| URLProtocolMock.urlRequests.removeAll() | |
| } | |
| func test_get_whenFetchRestaurants_shouldReturnSuccess() { | |
| // Given | |
| let endpoint = Router.fetchRestaurants | |
| let dataMock = dataMock() | |
| let successCompletion = createResquestCompletionMock( | |
| endpoint: endpoint, | |
| dataMock: dataMock, | |
| statusCode: 200, | |
| error: nil | |
| ) | |
| let mockSession = URLProtocolMock.mockSession( | |
| with: endpoint.getRequest, | |
| completionMock: successCompletion | |
| ) | |
| self.sut = APIService(mockSession) | |
| let expectation = expectation(description: "success") | |
| // When | |
| sut.get( | |
| request: endpoint.getRequest, | |
| of: [RestaurantsListModel].self, | |
| completion: { result in | |
| // Then | |
| switch result { | |
| case .failure: | |
| XCTFail() | |
| case .success(let model): | |
| expectation.fulfill() | |
| if let first = try? XCTUnwrap(model.first) { | |
| XCTAssertEqual(first.name, dataMock[0].name) | |
| XCTAssertEqual(first.category, dataMock[0].category) | |
| XCTAssertEqual(first.deliveryTime.min, dataMock[0].deliveryTime.min) | |
| XCTAssertEqual(first.deliveryTime.max, dataMock[0].deliveryTime.max) | |
| } else { | |
| XCTFail() | |
| } | |
| } | |
| } | |
| ) | |
| wait(for: [expectation], timeout: 1) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment