<commit_before>// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import assert from 'assert';
import TestHelper from './test_helper.jsx';

describe('Client.User', function() {
    this.timeout(100000);

    it('getMe', function(done) {
        TestHelper.initBasic(() => {
            TestHelper.basicClient().getMe(
                function(data) {
                    assert.equal(data.id, TestHelper.basicUser().id);
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('getInitialLoad', function(done) {
        TestHelper.initBasic(() => {
            TestHelper.basicClient().getInitialLoad(
                function(data) {
                    assert.equal(data.user.id.length > 0, true);
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('createUser', function(done) {
        var client = TestHelper.createClient();
        var user = TestHelper.fakeUser();
        client.createUser(
            user,
            function(data) {
                assert.equal(data.id.length > 0, true);
                assert.equal(data.email, user.email);
                done();
            },
            function(err) {
                done(new Error(err.message));
            }
        );
    });

    it('loginByEmail', function(done) {
        var client = TestHelper.createClient();
        var user = TestHelper.fakeUser();
        client.createUser(
            user,
            function() {
                client.login(
                    user.email,
                    user.password,
                    null,
                    function(data) {
                        assert.equal(data.id.length > 0, true);
                        assert.equal(data.email, user.email);
                        done();
                    },
                    function(err) {
                        done(new Error(err.message));
                    }
                );
            },
            function(err) {
                done(new Error(err.message));
            }
        );
    });

    it('loginById', function(done) {
        var client = TestHelper.createClient();
        var user = TestHelper.fakeUser();
        client.createUser(
            user,
            function(newUser) {
                assert.equal(user.email, newUser.email);
                client.loginById(
                    newUser.id,
                    user.password,
                    null,
                    function(data) {
                        assert.equal(data.id.length > 0, true);
                        assert.equal(data.email, user.email);
                        done();
                    },
                    function(err) {
                        done(new Error(err.message));
                    }
                );
            },
            function(err) {
                done(new Error(err.message));
            }
        );
    });

    it('loginByUsername', function(done) {
        var client = TestHelper.createClient();
        var user = TestHelper.fakeUser();
        client.createUser(
            user,
            function() {
                client.login(
                    user.username,
                    user.password,
                    null,
                    function(data) {
                        assert.equal(data.id.length > 0, true);
                        assert.equal(data.email, user.email);
                        done();
                    },
                    function(err) {
                        done(new Error(err.message));
                    }
                );
            },
            function(err) {
                done(new Error(err.message));
            }
        );
    });

    it('updateUser', function(done) {
        TestHelper.initBasic(() => {
            var user = TestHelper.basicUser();
            user.nickname = 'updated';

            TestHelper.basicClient().updateUser(
                user, null,
                function(data) {
                    assert.equal(data.nickname, 'updated');
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('updatePassword', function(done) {
        TestHelper.initBasic(() => {
            var user = TestHelper.basicUser();

            TestHelper.basicClient().updatePassword(
                user.id,
                user.password,
                '<PASSWORD>',
                function(data) {
                    assert.equal(data.user_id, user.id);
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('updateUserNotifyProps', function(done) {
        TestHelper.initBasic(() => {
            var user = TestHelper.basicUser();

            var notifyProps = {
                all: 'true',
                channel: 'true',
                desktop: 'all',
                desktop_sound: 'true',
                email: 'false',
                first_name: 'false',
                mention_keys: '',
                user_id: user.id
            };

            TestHelper.basicClient().updateUserNotifyProps(
                notifyProps,
                function(data) {
                    assert.equal(data.notify_props.email, 'false');
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('updateRoles', function(done) {
        TestHelper.initBasic(() => {<commit_msg>Fix client tests (#3628)<commit_after>// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import assert from 'assert';
import TestHelper from './test_helper.jsx';

describe('Client.User', function() {
    this.timeout(100000);

    it('getMe', function(done) {
        TestHelper.initBasic(() => {
            TestHelper.basicClient().getMe(
                function(data) {
                    assert.equal(data.id, TestHelper.basicUser().id);
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('getInitialLoad', function(done) {
        TestHelper.initBasic(() => {
            TestHelper.basicClient().getInitialLoad(
                function(data) {
                    assert.equal(data.user.id.length > 0, true);
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('createUser', function(done) {
        var client = TestHelper.createClient();
        var user = TestHelper.fakeUser();
        client.createUser(
            user,
            function(data) {
                assert.equal(data.id.length > 0, true);
                assert.equal(data.email, user.email);
                done();
            },
            function(err) {
                done(new Error(err.message));
            }
        );
    });

    it('loginByEmail', function(done) {
        var client = TestHelper.createClient();
        var user = TestHelper.fakeUser();
        client.createUser(
            user,
            function() {
                client.login(
                    user.email,
                    user.password,
                    null,
                    function(data) {
                        assert.equal(data.id.length > 0, true);
                        assert.equal(data.email, user.email);
                        done();
                    },
                    function(err) {
                        done(new Error(err.message));
                    }
                );
            },
            function(err) {
                done(new Error(err.message));
            }
        );
    });

    it('loginById', function(done) {
        var client = TestHelper.createClient();
        var user = TestHelper.fakeUser();
        client.createUser(
            user,
            function(newUser) {
                assert.equal(user.email, newUser.email);
                client.loginById(
                    newUser.id,
                    user.password,
                    null,
                    function(data) {
                        assert.equal(data.id.length > 0, true);
                        assert.equal(data.email, user.email);
                        done();
                    },
                    function(err) {
                        done(new Error(err.message));
                    }
                );
            },
            function(err) {
                done(new Error(err.message));
            }
        );
    });

    it('loginByUsername', function(done) {
        var client = TestHelper.createClient();
        var user = TestHelper.fakeUser();
        client.createUser(
            user,
            function() {
                client.login(
                    user.username,
                    user.password,
                    null,
                    function(data) {
                        assert.equal(data.id.length > 0, true);
                        assert.equal(data.email, user.email);
                        done();
                    },
                    function(err) {
                        done(new Error(err.message));
                    }
                );
            },
            function(err) {
                done(new Error(err.message));
            }
        );
    });

    it('updateUser', function(done) {
        TestHelper.initBasic(() => {
            var user = TestHelper.basicUser();
            user.nickname = 'updated';

            TestHelper.basicClient().updateUser(
                user, null,
                function(data) {
                    assert.equal(data.nickname, 'updated');
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('updatePassword', function(done) {
        TestHelper.initBasic(() => {
            var user = TestHelper.basicUser();

            TestHelper.basicClient().updatePassword(
                user.id,
                user.password,
                '<PASSWORD>',
                function(data) {
                    assert.equal(data.user_id, user.id);
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('updateUserNotifyProps', function(done) {
        TestHelper.initBasic(() => {
            var user = TestHelper.basicUser();

            var notifyProps = {
                all: 'true',
                channel: 'true',
                desktop: 'all',
                desktop_sound: 'true',
                email: 'false',
                first_name: 'false',
                mention_keys: '',
                comments: 'any',
                user_id: user.id
            };

            TestHelper.basicClient().updateUserNotifyProps(
                notifyProps,
                function(data) {
                    assert.equal(data.notify_props.email, 'false');
                    done();
                },
                function(err) {
                    done(new Error(err.message));
                }
            );
        });
    });

    it('updateRoles', function(done) {
        TestHelper.initBasic(() => {
{'fraction_non_alphanumeric': 0.1167754897036665, 'fraction_numerical': 0.002846140967687929, 'mean_word_length': 1.0119568878410239, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '649527', 'n_tokens_mistral': 2992, 'n_tokens_neox': 2742, 'n_words': 453}