<commit_before>//
//  GoalAPIServiceTests.swift
//  Yona
//
//  Created by <NAME> on 12/04/16.
//  Copyright © 2016 Yona. All rights reserved.
//

import XCTest
@testable import Yona

class GoalAPIServiceTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    func testPerformanceExample() {
        // This is an example of a performance test case.
        self.measureBlock {
            // Put the code you want to measure the time of here.
        }
    }
    
    func testGetGoalsOfTypeBudgetGoal(){
        //setup
        let expectation = expectationWithDescription("Waiting to respond")
        let randomPhoneNumber = Int(arc4random_uniform(9999999))
        
        let body =
            ["firstName": "Richard",
             "lastName": "Quin",
             "mobileNumber": "+31343" + String(randomPhoneNumber),
             "nickname": "RQ"]
        //Get user goals
        APIServiceManager.sharedInstance.postUser(body) { (success, message, code, users) in
            if success == false{
                XCTFail()
            }
            let bodyGoal = [
                "@type": "BudgetGoal",
                    "activityCategoryName": "social"
            ]
            //add budget goal
            APIServiceManager.sharedInstance.postUserGoals(bodyGoal, onCompletion: { (succes, message, code, goal, error) in
                
                let bodyGoal2 = [
                    "@type": "BudgetGoal",
                    "activityCategoryName": "news"
                ]
                APIServiceManager.sharedInstance.postUserGoals(bodyGoal2, onCompletion: { (succes, message, code, goal, error) in
                    if success {
                        //no
                        APIServiceManager.sharedInstance.getGoalsOfType(APIServiceManager.GoalType.BudgetGoal, onCompletion: { (success, message, code, goals, err) in
                            if let goalsUnwrap = goals {
                                if success {
                                    for goal in goalsUnwrap {
                                        print(goal.goalType)
                                        XCTAssertFalse(goal.goalType! != APIServiceManager.GoalType.BudgetGoal.rawValue)
                                    }
                                    expectation.fulfill()
                                } else {
                                    XCTFail(message!)
                                }
                            }
                        })
                    } else {
                        XCTFail(message!)
                    }
                })
            })

        }
        waitForExpectationsWithTimeout(10.0, handler:nil)

    }
    
    func testGetGoalArray() {
        //setup
        let expectation = expectationWithDescription("Waiting to respond")
        let randomPhoneNumber = Int(arc4random_uniform(9999999))
        
        let body =
            ["firstName": "Richard",
             "lastName": "Quin",
             "mobileNumber": "+31343" + String(randomPhoneNumber),
             "nickname": "RQ"]
        //Get user goals
        APIServiceManager.sharedInstance.postUser(body) { (success, message, code, users) in
            if success == false{<commit_msg>Test works for timezone goals too<commit_after>//
//  GoalAPIServiceTests.swift
//  Yona
//
//  Created by <NAME> on 12/04/16.
//  Copyright © 2016 Yona. All rights reserved.
//

import XCTest
@testable import Yona

class GoalAPIServiceTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    func testPerformanceExample() {
        // This is an example of a performance test case.
        self.measureBlock {
            // Put the code you want to measure the time of here.
        }
    }
    
    func testGetGoalsOfTypeBudgetGoal(){
        //setup
        let expectation = expectationWithDescription("Waiting to respond")
        let randomPhoneNumber = Int(arc4random_uniform(9999999))
        
        let body =
            ["firstName": "Richard",
             "lastName": "Quin",
             "mobileNumber": "+31343" + String(randomPhoneNumber),
             "nickname": "RQ"]
        //Get user goals
        APIServiceManager.sharedInstance.postUser(body) { (success, message, code, users) in
            if success == false{
                XCTFail()
            }
            let bodyGoal = [
                "@type": "BudgetGoal",
                    "activityCategoryName": "social"
            ]
            //add budget goal
            APIServiceManager.sharedInstance.postUserGoals(bodyGoal, onCompletion: { (succes, message, code, goal, error) in
                
                let bodyGoal2 = [
                    "@type": "BudgetGoal",
                    "activityCategoryName": "news"
                ]
                APIServiceManager.sharedInstance.postUserGoals(bodyGoal2, onCompletion: { (succes, message, code, goal, error) in
                    if success {
                        //no
                        APIServiceManager.sharedInstance.getGoalsOfType(APIServiceManager.GoalType.BudgetGoal, onCompletion: { (success, message, code, goals, err) in
                            if let goalsUnwrap = goals {
                                if success {
                                    for goal in goalsUnwrap {
                                        print(goal.goalType)
                                        XCTAssertFalse(goal.goalType! != APIServiceManager.GoalType.BudgetGoal.rawValue)
                                    }
                                    expectation.fulfill()
                                } else {
                                    XCTFail(message!)
                                }
                            }
                        })
                    } else {
                        XCTFail(message!)
                    }
                })
            })

        }
        waitForExpectationsWithTimeout(10.0, handler:nil)

    }
    
    func testGetGoalsOfTypeTimeZone(){
        //setup
        let expectation = expectationWithDescription("Waiting to respond")
        let randomPhoneNumber = Int(arc4random_uniform(9999999))
        
        let body =
            ["firstName": "Richard",
             "lastName": "Quin",
             "mobileNumber": "+31343" + String(randomPhoneNumber),
             "nickname": "RQ"]
        //Get user goals
        APIServiceManager.sharedInstance.postUser(body) { (success, message, code, users) in
            if success == false{
                XCTFail()
            }
            let bodyGoal = [
                "@type": "TimeZoneGoal",
                "activityCategoryName": "social",
                "zones":[ "6:00-10:00", "6:00-10:00"]
            ]
            //add budget goal
            APIServiceManager.sharedInstance.postUserGoals(bodyGoal, onCompletion: { (succes, message, code, goal, error) in
                
                let bodyGoal2 = [
                    "@type": "TimeZoneGoal",
                    "activityCategoryName": "news",
                    "zones":[ "8:00-11:00"]
                ]
                APIServiceManager.sharedInstance.postUserGoals(bodyGoal2, onCompletion: { (succes, message, code, goal, error) in
                    if success {
                        //no
                        APIServiceManager.sharedInstance.getGoalsOfType(APIServiceManager.GoalType.TimeZoneGoal, onCompletion: { (success, message, code, goals, err) in
                            if let goalsUnwrap = goals {
                                if success {
                                    for goal in goalsUnwrap {
                                        print(goal.goalType)
                                        XCTAssertFalse(goal.goalType! != APIServiceManager.GoalType.TimeZoneGoal.rawValue)
                                    }
                                    expectation.fulfill()
                                } else {
                                    XCTFail(message!)
                                }
                            }
                        })
                    } else {
                        XCTFail(message!)
                    }
                })
            })
            
        }
        waitForExpectationsWithTimeout(10.0, handler:nil)
        
    }
    
    func testGetGoalArray() {
        //setup
        let expectation = expectationWithDescription("Waiting to respond")
        let randomPhoneNumber = Int(arc4random_uniform(9999999))
        
        let body =
            ["firstName": "Richard",
             "lastName": "Quin",
             "mobileNumber": "+31343" + String(randomPhoneNumber),
             "nickname": "RQ"]
        //Get user goals
        APIServiceManager.sharedInstance.postUser(body) { (success, message, code, users) in
            if success == false{
{'fraction_non_alphanumeric': 0.08769661710838181, 'fraction_numerical': 0.013035983624218919, 'mean_word_length': 1.2493336564090138, 'pattern_counts': {'":': 34, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 5, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7306968', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2238, 'n_words': 512}