<commit_before>import request from 'request'

const jobDataProperties = ['name', 'tags', 'public', 'build', 'extra']

class TBService {
    /**
     * gather information about runner
     */
    before (capabilities) {
        this.sessionId = global.browser.sessionId
        this.capabilities = capabilities
        this.auth = global.browser.requestHandler.auth || {}
        this.tbUser = this.auth.user
        this.tbSecret = this.auth.pass
        this.APIUri = `https://api.testingbot.com/v1/tests/${this.sessionId}`
    }

    beforeSuite (suite) {
        this.suiteTitle = suite.title
    }

    beforeTest (test) {
        if (!this.tbUser || !this.tbSecret) {
            return
        }

        global.browser.execute('tb:context=' + test.parent + ' - ' + test.title)
    }

    beforeFeature (feature) {
        if (!this.tbUser || !this.tbSecret) {
            return
        }

        this.suiteTitle = feature.getName()
        global.browser.execute('tb:context=Feature: ' + this.suiteTitle)
    }

    beforeScenario (scenario) {
        if (!this.tbUser || !this.tbSecret) {
            return
        }

        global.browser.execute('tb:context=Scenario: ' + scenario.getName())
    }

    /**
     * update TestingBot info
     */
    after (failures) {
        if (!this.tbUser || !this.tbSecret) {
            return
        }

        return new Promise((resolve, reject) => request.put(this.APIUri, {
            json: true,
            auth: {
                user: this.tbUser,
                pass: <PASSWORD>
            },
            body: this.getBody(failures)
        }, (e, res, body) => {
            if (e) {
                return reject(e)
            }
            global.browser.jobData = body
            resolve(body)
        }))
    }

    /**
     * massage data
     */
    getBody (failures) {
        let body = { test: {} }

        /**
         * set default values
         */
        body.test[name] = this.suiteTitle

        for (let prop of jobDataProperties) {
            if (!this.capabilities[prop]) {
                continue
            }

            body.test[prop] = this.capabilities[prop]
        }

        body.test[success] = failures === 0
        return body
    }
}

export default TBService<commit_msg>fix reporting success state to Testingbot<commit_after>import request from 'request'

const jobDataProperties = ['name', 'tags', 'public', 'build', 'extra']

class TBService {
    /**
     * gather information about runner
     */
    before (capabilities) {
        this.sessionId = global.browser.sessionId
        this.capabilities = capabilities
        this.auth = global.browser.requestHandler.auth || {}
        this.tbUser = this.auth.user
        this.tbSecret = this.auth.pass
        this.APIUri = `https://api.testingbot.com/v1/tests/${this.sessionId}`
    }

    beforeSuite (suite) {
        this.suiteTitle = suite.title
    }

    beforeTest (test) {
        if (!this.tbUser || !this.tbSecret) {
            return
        }

        global.browser.execute('tb:context=' + test.parent + ' - ' + test.title)
    }

    beforeFeature (feature) {
        if (!this.tbUser || !this.tbSecret) {
            return
        }

        this.suiteTitle = feature.getName()
        global.browser.execute('tb:context=Feature: ' + this.suiteTitle)
    }

    beforeScenario (scenario) {
        if (!this.tbUser || !this.tbSecret) {
            return
        }

        global.browser.execute('tb:context=Scenario: ' + scenario.getName())
    }

    /**
     * update TestingBot info
     */
    after (failures) {
        if (!this.tbUser || !this.tbSecret) {
            return
        }

        return new Promise((resolve, reject) => request.put(this.APIUri, {
            json: true,
            auth: {
                user: this.tbUser,
                pass: this.tbSecret
            },
            body: this.getBody(failures)
        }, (e, res, body) => {
            if (e) {
                return reject(e)
            }
            global.browser.jobData = body
            resolve(body)
        }))
    }

    /**
     * massage data
     */
    getBody (failures) {
        let body = { test: {} }

        /**
         * set default values
         */
        body.test['name'] = this.suiteTitle

        for (let prop of jobDataProperties) {
            if (!this.capabilities[prop]) {
                continue
            }

            body.test[prop] = this.capabilities[prop]
        }

        body.test['success'] = failures === 0 ? "1" : "0"
        return body
    }
}

export default TBService
{'fraction_non_alphanumeric': 0.12773801778356106, 'fraction_numerical': 0.0013012361743656475, 'mean_word_length': 1.5953854811480022, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '2049218', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1308, 'n_words': 256}