//
//  MainPresenterTests.swift
//  JSONPlaceholderapp
//
//  Created by Iván Díaz Molina on 08/06/2020.
//  Copyright (c) 2020 Iván Díaz Molina. All rights reserved.
//
//  This file was generated by the Clean Swift Xcode Templates so
//  you can apply clean architecture to your iOS and Mac projects,
//  see http://clean-swift.com
//

@testable import JSONPlaceholderapp
import XCTest

class MainPresenterTests: XCTestCase {
    // MARK: Subject under test
    
    var sut: MainPresenter!
    
    // MARK: Test lifecycle
    
    override func setUp() {
        super.setUp()
        setupMainPresenter()
    }
    
    override func tearDown() {
        super.tearDown()
    }
    
    // MARK: Test setup
    
    func setupMainPresenter() {
        sut = MainPresenter()
    }
    
    // MARK: Test doubles
    
    class MainDisplayLogicSpy: MainDisplayLogic {
        
        var setupViewCalled = false
        var displayPostsAndUsersCalled = false
        
        func setupView(viewModel: Main.Models.ViewModel) {
            setupViewCalled = true
        }
        
        func displayPostsAndUsers(viewModel: Main.Models.ViewModel) {
            displayPostsAndUsersCalled = true
        }
    }
    
    // MARK: Tests
    
    func testSetupView() {
        // Given
        let spy = MainDisplayLogicSpy()
        sut.viewController = spy
        let response = Main.Models.Response()
        
        // When
        sut.setupView(response: response)
        
        // Then
        XCTAssertTrue(spy.setupViewCalled, "setupView(response:) should ask the view controller to display the result")
    }
    
    func testPresentPostsAndUsers() {
        // Given
        let spy = MainDisplayLogicSpy()
        sut.viewController = spy
        let response = Main.Models.Response()
        
        // When
        sut.presentPostsAndUsers(response: response)
        
        // Then
        XCTAssertTrue(spy.displayPostsAndUsersCalled, "presentPostsAndUsers(response:) should ask the view controller to display the result")
    }
}
