<commit_before>//
//  DraftMessageManagerSpec.swift
//  Rocket.ChatTests
//
//  Created by <NAME> on 07/11/17.
//  Copyright © 2017 Rocket.Chat. All rights reserved.
//

import XCTest
@testable import Rocket_Chat

class DraftMessageManagerSpec: XCTestCase {

    var servers: [[String: String]] = []
    let testServerURL = "wss://foo.com/websocket"
    let draftMessage = "Testing draft messages per channel"
    let subscription: Subscription = {
        let subscription = Subscription()
        subscription.rid = "testing-id"
        return subscription
    }()

    override func setUp() {
        super.setUp()

        servers = [[
            ServerPersistKeys.databaseName: "foo.realm",
            ServerPersistKeys.serverURL: testServerURL,
            ServerPersistKeys.token: "1",
            ServerPersistKeys.userId: "1"
        ]]
    }

    func testUpdateDraftMessage() {
        UserDefaults.standard.set(servers, forKey: ServerPersistKeys.servers)
        DatabaseManager.selectDatabase(at: 0)
        DraftMessageManager.update(draftMessage: draftMessage, for: subscription)

        let selectedServerDraftMessages = UserDefaults.standard.dictionary(forKey: DraftMessageManager.selectedServerKey)
        let expectedSelectedServerDraftMessages: [String: Any] = [String(format: "\(subscription.rid)-cacheddraftmessage"): draftMessage]
        XCTAssertEqual(selectedServerDraftMessages as NSObject?, expectedSelectedServerDraftMessages as NSObject, "cached draft messages by server data is correct")
    }

    func testDraftMessageRetrieving() {
        UserDefaults.standard.set(servers, forKey: ServerPersistKeys.servers)
        DatabaseManager.selectDatabase(at: 0)
        DraftMessageManager.update(draftMessage: draftMessage, for: subscription)

        XCTAssertEqual(DraftMessageManager.draftMessage(for: subscription), draftMessage, "draftMessage is correct")
    }

    func testClearEmptyServerDraftMessages() {
        UserDefaults.standard.set(servers, forKey: ServerPersistKeys.servers)
        DatabaseManager.selectDatabase(at: 0)
        DraftMessageManager.update(draftMessage: draftMessage, for: subscription)

        UserDefaults.standard.set(nil, forKey: ServerPersistKeys.servers)
        DraftMessageManager.clearServerDraftMessages()

        XCTAssertEqual(UserDefaults.standard.dictionary(forKey: testServerURL) != nil, true, "no server data was cleared when clearing draft messages for a empty server")
    }

    func testClearServerDraftMessages() {
        UserDefaults.standard.set(servers, forKey: ServerPersistKeys.servers)
        DatabaseManager.selectDatabase(at: 0)
        DraftMessageManager.update(draftMessage: draftMessage, for: subscription)

        DraftMessageManager.clearServerDraftMessages()
        XCTAssertEqual(UserDefaults.standard.dictionary(forKey: DraftMessageManager.selectedServerKey) == nil, true, "successfully cleared selected server draft messages")
    }

}<commit_msg>Use more appropriate XCTAsserts when testing for nil or not nil values<commit_after>//
//  DraftMessageManagerSpec.swift
//  Rocket.ChatTests
//
//  Created by <NAME> on 07/11/17.
//  Copyright © 2017 Rocket.Chat. All rights reserved.
//

import XCTest
@testable import Rocket_Chat

class DraftMessageManagerSpec: XCTestCase {

    var servers: [[String: String]] = []
    let testServerURL = "wss://foo.com/websocket"
    let draftMessage = "Testing draft messages per channel"
    let subscription: Subscription = {
        let subscription = Subscription()
        subscription.rid = "testing-id"
        return subscription
    }()

    override func setUp() {
        super.setUp()

        servers = [[
            ServerPersistKeys.databaseName: "foo.realm",
            ServerPersistKeys.serverURL: testServerURL,
            ServerPersistKeys.token: "1",
            ServerPersistKeys.userId: "1"
        ]]
    }

    func testUpdateDraftMessage() {
        UserDefaults.standard.set(servers, forKey: ServerPersistKeys.servers)
        DatabaseManager.selectDatabase(at: 0)
        DraftMessageManager.update(draftMessage: draftMessage, for: subscription)

        let selectedServerDraftMessages = UserDefaults.standard.dictionary(forKey: DraftMessageManager.selectedServerKey)
        let expectedSelectedServerDraftMessages: [String: Any] = [String(format: "\(subscription.rid)-cacheddraftmessage"): draftMessage]
        XCTAssertEqual(selectedServerDraftMessages as NSObject?, expectedSelectedServerDraftMessages as NSObject, "cached draft messages by server data is correct")
    }

    func testDraftMessageRetrieving() {
        UserDefaults.standard.set(servers, forKey: ServerPersistKeys.servers)
        DatabaseManager.selectDatabase(at: 0)
        DraftMessageManager.update(draftMessage: draftMessage, for: subscription)

        XCTAssertEqual(DraftMessageManager.draftMessage(for: subscription), draftMessage, "draftMessage is correct")
    }

    func testClearEmptyServerDraftMessages() {
        UserDefaults.standard.set(servers, forKey: ServerPersistKeys.servers)
        DatabaseManager.selectDatabase(at: 0)
        DraftMessageManager.update(draftMessage: draftMessage, for: subscription)

        UserDefaults.standard.set(nil, forKey: ServerPersistKeys.servers)
        DraftMessageManager.clearServerDraftMessages()

        XCTAssertNotNil(UserDefaults.standard.dictionary(forKey: testServerURL), "no server data was cleared when clearing draft messages for a empty server")
    }

    func testClearServerDraftMessages() {
        UserDefaults.standard.set(servers, forKey: ServerPersistKeys.servers)
        DatabaseManager.selectDatabase(at: 0)
        DraftMessageManager.update(draftMessage: draftMessage, for: subscription)

        DraftMessageManager.clearServerDraftMessages()
        XCTAssertNil(UserDefaults.standard.dictionary(forKey: DraftMessageManager.selectedServerKey), "successfully cleared selected server draft messages")
    }

}
{'fraction_non_alphanumeric': 0.08708809683927371, 'fraction_numerical': 0.005379959650302623, 'mean_word_length': 3.820907617504052, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4551334', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1568, 'n_words': 341}