PLT-5755: Infrastructure for Component Testing. (#5814)

This migrates the existing webapp tests to using Jest and Enzyme. The
infrastructure is put in place for React component testing, and a few
simple example component tests are implemented.

This also adds snapshot testing of components, coverage checking for the
webapp (although that is not yet integrated to Coveralls), and the
ability to run npm run test:watch to automatically re-run affected tests
when working on the webapp codebase.
Этот коммит содержится в:
George Goldberg
2017-03-23 18:05:36 +00:00
коммит произвёл Christopher Speller
родитель c6ded1dbfd
Коммит 7d449e0556
40 изменённых файлов: 1426 добавлений и 799 удалений

1
.gitignore поставляемый
Просмотреть файл

@@ -78,6 +78,7 @@ enterprise
cover.out cover.out
ecover.out ecover.out
*.test *.test
webapp/coverage
.agignore .agignore
.ctags .ctags

Просмотреть файл

@@ -1,4 +1,4 @@
.PHONY: build package run stop run-client run-server stop-client stop-server restart restart-server restart-client start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist setup-mac prepare-enteprise run-client-tests setup-run-client-tests cleanup-run-client-tests test-client build-linux build-osx build-windows internal-test-client vet .PHONY: build package run stop run-client run-server stop-client stop-server restart restart-server restart-client start-docker clean-dist clean nuke check-style check-client-style check-server-style check-unit-tests test dist setup-mac prepare-enteprise run-client-tests setup-run-client-tests cleanup-run-client-tests test-client build-linux build-osx build-windows internal-test-web-client vet run-server-for-web-client-tests
# For golang 1.5.x compatibility (remove when we don't want to support it anymore) # For golang 1.5.x compatibility (remove when we don't want to support it anymore)
export GO15VENDOREXPERIMENT=1 export GO15VENDOREXPERIMENT=1
@@ -254,6 +254,9 @@ test-server: test-te test-ee
internal-test-web-client: start-docker prepare-enterprise internal-test-web-client: start-docker prepare-enterprise
$(GO) run $(GOFLAGS) ./cmd/platform/*go test web_client_tests $(GO) run $(GOFLAGS) ./cmd/platform/*go test web_client_tests
run-server-for-web-client-tests:
$(GO) run $(GOFLAGS) ./cmd/platform/*go test web_client_tests_server
test-client: start-docker prepare-enterprise test-client: start-docker prepare-enterprise
@echo Running client tests @echo Running client tests

Просмотреть файл

@@ -10,9 +10,12 @@ import (
"os/exec" "os/exec"
"github.com/mattermost/platform/api" "github.com/mattermost/platform/api"
"github.com/mattermost/platform/api4"
"github.com/mattermost/platform/app" "github.com/mattermost/platform/app"
"github.com/mattermost/platform/utils" "github.com/mattermost/platform/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os/signal"
"syscall"
) )
var testCmd = &cobra.Command{ var testCmd = &cobra.Command{
@@ -27,9 +30,16 @@ var runWebClientTestsCmd = &cobra.Command{
RunE: webClientTestsCmdF, RunE: webClientTestsCmdF,
} }
var runServerForWebClientTestsCmd = &cobra.Command{
Use: "web_client_tests_server",
Short: "Run the server configured for running the web client tests against it",
RunE: serverForWebClientTestsCmdF,
}
func init() { func init() {
testCmd.AddCommand( testCmd.AddCommand(
runWebClientTestsCmd, runWebClientTestsCmd,
runServerForWebClientTestsCmd,
) )
} }
@@ -37,6 +47,7 @@ func webClientTestsCmdF(cmd *cobra.Command, args []string) error {
initDBCommandContextCobra(cmd) initDBCommandContextCobra(cmd)
utils.InitTranslations(utils.Cfg.LocalizationSettings) utils.InitTranslations(utils.Cfg.LocalizationSettings)
api.InitRouter() api.InitRouter()
api4.InitApi(false)
api.InitApi() api.InitApi()
setupClientTests() setupClientTests()
app.StartServer() app.StartServer()
@@ -46,6 +57,24 @@ func webClientTestsCmdF(cmd *cobra.Command, args []string) error {
return nil return nil
} }
func serverForWebClientTestsCmdF(cmd *cobra.Command, args []string) error {
initDBCommandContextCobra(cmd)
utils.InitTranslations(utils.Cfg.LocalizationSettings)
api.InitRouter()
api4.InitApi(false)
api.InitApi()
setupClientTests()
app.StartServer()
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-c
app.StopServer()
return nil
}
func setupClientTests() { func setupClientTests() {
*utils.Cfg.TeamSettings.EnableOpenServer = true *utils.Cfg.TeamSettings.EnableOpenServer = true
*utils.Cfg.ServiceSettings.EnableCommands = false *utils.Cfg.ServiceSettings.EnableCommands = false

7
webapp/.babelrc Обычный файл
Просмотреть файл

@@ -0,0 +1,7 @@
{
"presets": [
"es2015",
"react",
"stage-0"
]
}

Просмотреть файл

@@ -2149,6 +2149,7 @@ export default class Client {
request. request.
post(`${this.getEmojiRoute()}/delete`). post(`${this.getEmojiRoute()}/delete`).
set(this.defaultHeaders). set(this.defaultHeaders).
type('application/json').
accept('application/json'). accept('application/json').
send({id}). send({id}).
end(this.handleResponse.bind(this, 'deleteEmoji', success, error)); end(this.handleResponse.bind(this, 'deleteEmoji', success, error));
@@ -2218,6 +2219,7 @@ export default class Client {
request. request.
post(`${this.getChannelNeededRoute(channelId)}/posts/${reaction.post_id}/reactions/save`). post(`${this.getChannelNeededRoute(channelId)}/posts/${reaction.post_id}/reactions/save`).
set(this.defaultHeaders). set(this.defaultHeaders).
type('application/json').
accept('application/json'). accept('application/json').
send(reaction). send(reaction).
end(this.handleResponse.bind(this, 'saveReaction', success, error)); end(this.handleResponse.bind(this, 'saveReaction', success, error));
@@ -2229,6 +2231,7 @@ export default class Client {
request. request.
post(`${this.getChannelNeededRoute(channelId)}/posts/${reaction.post_id}/reactions/delete`). post(`${this.getChannelNeededRoute(channelId)}/posts/${reaction.post_id}/reactions/delete`).
set(this.defaultHeaders). set(this.defaultHeaders).
type('application/json').
accept('application/json'). accept('application/json').
send(reaction). send(reaction).
end(this.handleResponse.bind(this, 'deleteReaction', success, error)); end(this.handleResponse.bind(this, 'deleteReaction', success, error));

Просмотреть файл

@@ -140,7 +140,7 @@ export default class AboutBuildModal extends React.Component {
id='about.version' id='about.version'
defaultMessage='Version:' defaultMessage='Version:'
/> />
{version} <span id='versionString'>{version}</span>
</div> </div>
<div> <div>
<FormattedMessage <FormattedMessage

Просмотреть файл

@@ -1,6 +1,8 @@
{ {
"name": "mattermost-webapp", "name": "mattermost-webapp",
"browser": {"./client/web_client.jsx": "./client/browser_web_client.jsx"}, "browser": {
"./client/web_client.jsx": "./client/browser_web_client.jsx"
},
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"dependencies": { "dependencies": {
@@ -39,6 +41,7 @@
"devDependencies": { "devDependencies": {
"babel-core": "6.24.0", "babel-core": "6.24.0",
"babel-eslint": "7.1.1", "babel-eslint": "7.1.1",
"babel-jest": "19.0.0",
"babel-loader": "6.4.0", "babel-loader": "6.4.0",
"babel-plugin-transform-runtime": "6.23.0", "babel-plugin-transform-runtime": "6.23.0",
"babel-polyfill": "6.23.0", "babel-polyfill": "6.23.0",
@@ -48,6 +51,8 @@
"copy-webpack-plugin": "4.0.1", "copy-webpack-plugin": "4.0.1",
"cross-env": "3.2.3", "cross-env": "3.2.3",
"css-loader": "0.27.3", "css-loader": "0.27.3",
"enzyme": "2.7.1",
"enzyme-to-json": "1.5.0",
"eslint": "3.17.1", "eslint": "3.17.1",
"eslint-plugin-react": "6.10.0", "eslint-plugin-react": "6.10.0",
"exports-loader": "0.6.4", "exports-loader": "0.6.4",
@@ -55,29 +60,66 @@
"file-loader": "0.10.1", "file-loader": "0.10.1",
"html-loader": "0.4.5", "html-loader": "0.4.5",
"html-webpack-plugin": "2.28.0", "html-webpack-plugin": "2.28.0",
"identity-obj-proxy": "3.0.0",
"image-webpack-loader": "3.2.0", "image-webpack-loader": "3.2.0",
"imports-loader": "0.7.1", "imports-loader": "0.7.1",
"jest": "19.0.2",
"jest-cli": "19.0.2",
"jquery-deferred": "0.3.1", "jquery-deferred": "0.3.1",
"jsdom": "9.12.0", "jsdom": "9.12.0",
"jsdom-global": "2.1.1", "jsdom-global": "2.1.1",
"json-loader": "0.5.4", "json-loader": "0.5.4",
"mocha": "3.2.0",
"mocha-jsdom": "1.1.0",
"mocha-webpack": "0.7.0",
"node-sass": "4.5.0", "node-sass": "4.5.0",
"raw-loader": "0.5.1", "raw-loader": "0.5.1",
"react-addons-test-utils": "15.4.2", "react-addons-test-utils": "15.4.2",
"react-dom": "15.4.2",
"sass-loader": "6.0.3", "sass-loader": "6.0.3",
"style-loader": "0.13.2", "style-loader": "0.13.2",
"url-loader": "0.5.8", "url-loader": "0.5.8",
"webpack": "2.2.1", "webpack": "2.2.1",
"webpack-node-externals": "1.5.4" "webpack-node-externals": "1.5.4"
}, },
"jest": {
"snapshotSerializers": [
"<rootDir>/node_modules/enzyme-to-json/serializer"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/non_npm_dependencies/"
],
"collectCoverageFrom": [
"actions/**/*.{js,jsx}",
"client/**/*.{js,jsx}",
"components/**/*.{js,jsx}",
"routes/**/*.{js,jsx}",
"stores/**/*.{js,jsx}",
"utils/**/*.{js,jsx}"
],
"coverageReporters": [
"lcov",
"text-summary"
],
"moduleNameMapper": {
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "identity-obj-proxy",
"^.+\\.(css|less|scss)$": "identity-obj-proxy",
"^.+\\.(json)$": "identity-obj-proxy"
},
"moduleDirectories": [
"",
"node_modules",
"non_npm_dependencies"
],
"transformIgnorePatterns": [
"node_modules/(?!react-native|react-router)"
]
},
"scripts": { "scripts": {
"check": "eslint --ext \".jsx\" --ignore-pattern node_modules --quiet .", "check": "eslint --ext \".jsx\" --ignore-pattern node_modules --quiet .",
"build": "cross-env NODE_ENV=production webpack", "build": "cross-env NODE_ENV=production webpack",
"run": "cross-env NODE_ENV=production webpack --progress --watch", "run": "cross-env NODE_ENV=production webpack --progress --watch",
"run-fullmap": "webpack --progress --watch", "run-fullmap": "webpack --progress --watch",
"test": "mocha-webpack --webpack-config webpack.config.js \"**/*.test.jsx\"" "test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
} }
} }

Просмотреть файл

@@ -8,5 +8,8 @@
"no-unreachable": 0, "no-unreachable": 0,
"new-cap": 0, "new-cap": 0,
"max-nested-callbacks": 0 "max-nested-callbacks": 0
},
"env": {
"jest": true
} }
} }

Просмотреть файл

@@ -1,59 +1,56 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
var assert = require('assert'); import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.Admin', function() { describe('Client.Admin', function() {
this.timeout(10000); test('Admin.reloadConfig', function(done) {
TestHelper.initBasic(done, () => {
it('Admin.reloadConfig', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().reloadConfig( TestHelper.basicClient().reloadConfig(
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.recycleDatabaseConnection', function(done) { test('Admin.recycleDatabaseConnection', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().recycleDatabaseConnection( TestHelper.basicClient().recycleDatabaseConnection(
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.getComplianceReports', function(done) { test('Admin.getComplianceReports', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().getComplianceReports( TestHelper.basicClient().getComplianceReports(
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.saveComplianceReports', function(done) { test('Admin.saveComplianceReports', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var job = {}; var job = {};
@@ -66,97 +63,97 @@ describe('Client.Admin', function() {
TestHelper.basicClient().saveComplianceReports( TestHelper.basicClient().saveComplianceReports(
job, job,
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.getLogs', function(done) { test('Admin.getLogs', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().getLogs( TestHelper.basicClient().getLogs(
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.getServerAudits', function(done) { test('Admin.getServerAudits', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().getServerAudits( TestHelper.basicClient().getServerAudits(
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.getConfig', function(done) { test('Admin.getConfig', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().getConfig( TestHelper.basicClient().getConfig(
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.getAnalytics', function(done) { test('Admin.getAnalytics', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().getAnalytics( TestHelper.basicClient().getAnalytics(
'standard', 'standard',
null, null,
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.getTeamAnalytics', function(done) { test('Admin.getTeamAnalytics', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().getTeamAnalytics( TestHelper.basicClient().getTeamAnalytics(
TestHelper.basicTeam().id, TestHelper.basicTeam().id,
'standard', 'standard',
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.saveConfig', function(done) { test('Admin.saveConfig', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var config = {}; var config = {};
config.site_name = 'test'; config.site_name = 'test';
@@ -164,18 +161,18 @@ describe('Client.Admin', function() {
TestHelper.basicClient().saveConfig( TestHelper.basicClient().saveConfig(
config, config,
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.testEmail', function(done) { test('Admin.testEmail', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var config = {}; var config = {};
config.site_name = 'test'; config.site_name = 'test';
@@ -183,35 +180,35 @@ describe('Client.Admin', function() {
TestHelper.basicClient().testEmail( TestHelper.basicClient().testEmail(
config, config,
function() { function() {
done(new Error('should need system admin permissions')); done.fail(new Error('should need system admin permissions'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.adminResetMfa', function(done) { test('Admin.adminResetMfa', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().adminResetMfa( TestHelper.basicClient().adminResetMfa(
TestHelper.basicUser().id, TestHelper.basicUser().id,
function() { function() {
done(new Error('should need a license')); done.fail(new Error('should need a license'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.adminResetPassword', function(done) { test('Admin.adminResetPassword', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
@@ -223,44 +220,44 @@ describe('Client.Admin', function() {
}, },
function(err) { function(err) {
// this should fail since you're not a system admin // this should fail since you're not a system admin
assert.equal(err.id, 'api.context.invalid_param.app_error'); expect(err.id).toBe('api.context.invalid_param.app_error');
done(); done();
} }
); );
}); });
}); });
it('License.getClientLicenceConfig', function(done) { test('License.getClientLicenceConfig', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getClientLicenceConfig( TestHelper.basicClient().getClientLicenceConfig(
function(data) { function(data) {
assert.equal(data.IsLicensed, 'false'); expect(data.IsLicensed).toBe('false');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('License.removeLicenseFile', function(done) { test('License.removeLicenseFile', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().removeLicenseFile( TestHelper.basicClient().removeLicenseFile(
function() { function() {
done(new Error('not enabled')); done.fail(new Error('not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
}); });
it('Admin.ldapSyncNow', function(done) { test('Admin.ldapSyncNow', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().ldapSyncNow( TestHelper.basicClient().ldapSyncNow(
@@ -275,20 +272,20 @@ describe('Client.Admin', function() {
}); });
}); });
/*it('License.uploadLicenseFile', function(done) { test.skip('License.uploadLicenseFile', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().uploadLicenseFile( TestHelper.basicClient().uploadLicenseFile(
'form data', 'form data',
function() { function() {
done(new Error('not enabled')); done.fail(new Error('not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.permissions.app_error'); expect(err.id).toBe('api.context.permissions.app_error');
done(); done();
} }
); );
}); });
});*/ });
}); });

Просмотреть файл

@@ -1,55 +1,52 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.Channels', function() { describe('Client.Channels', function() {
this.timeout(100000); test('createChannel', function(done) {
TestHelper.initBasic(done, () => {
it('createChannel', function(done) {
TestHelper.initBasic(() => {
var channel = TestHelper.fakeChannel(); var channel = TestHelper.fakeChannel();
channel.team_id = TestHelper.basicTeam().id; channel.team_id = TestHelper.basicTeam().id;
TestHelper.basicClient().createChannel( TestHelper.basicClient().createChannel(
channel, channel,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.name, channel.name); expect(data.name).toBe(channel.name);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('createDirectChannel', function(done) { test('createDirectChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().createUser( TestHelper.basicClient().createUser(
TestHelper.fakeUser(), TestHelper.fakeUser(),
function(user2) { function(user2) {
TestHelper.basicClient().createDirectChannel( TestHelper.basicClient().createDirectChannel(
user2.id, user2.id,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('createGroupChannel', function(done) { test('createGroupChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().createUser( TestHelper.basicClient().createUser(
TestHelper.fakeUser(), TestHelper.fakeUser(),
(user1) => { (user1) => {
@@ -59,84 +56,84 @@ describe('Client.Channels', function() {
TestHelper.basicClient().createGroupChannel( TestHelper.basicClient().createGroupChannel(
[user2.id, user1.id], [user2.id, user1.id],
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateChannel', function(done) { test('updateChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
channel.display_name = 'changed'; channel.display_name = 'changed';
TestHelper.basicClient().updateChannel( TestHelper.basicClient().updateChannel(
channel, channel,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.display_name, 'changed'); expect(data.display_name).toEqual('changed');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateChannelHeader', function(done) { test('updateChannelHeader', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
channel.display_name = 'changed'; channel.display_name = 'changed';
TestHelper.basicClient().updateChannelHeader( TestHelper.basicClient().updateChannelHeader(
channel.id, channel.id,
'new header', 'new header',
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.header, 'new header'); expect(data.header).toBe('new header');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateChannelPurpose', function(done) { test('updateChannelPurpose', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
channel.display_name = 'changed'; channel.display_name = 'changed';
TestHelper.basicClient().updateChannelPurpose( TestHelper.basicClient().updateChannelPurpose(
channel.id, channel.id,
'new purpose', 'new purpose',
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.purpose, 'new purpose'); expect(data.purpose).toEqual('new purpose');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateChannelNotifyProps', function(done) { test('updateChannelNotifyProps', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var props = {}; var props = {};
props.channel_id = TestHelper.basicChannel().id; props.channel_id = TestHelper.basicChannel().id;
props.user_id = TestHelper.basicUser().id; props.user_id = TestHelper.basicUser().id;
@@ -144,34 +141,34 @@ describe('Client.Channels', function() {
TestHelper.basicClient().updateChannelNotifyProps( TestHelper.basicClient().updateChannelNotifyProps(
props, props,
function(data) { function(data) {
assert.equal(data.desktop, 'all'); expect(data.desktop).toEqual('all');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('leaveChannel', function(done) { test('leaveChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
TestHelper.basicClient().leaveChannel( TestHelper.basicClient().leaveChannel(
channel.id, channel.id,
function(data) { function(data) {
assert.equal(data.id, channel.id); expect(data.id).toEqual(channel.id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('joinChannel', function(done) { test('joinChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
TestHelper.basicClient().leaveChannel( TestHelper.basicClient().leaveChannel(
channel.id, channel.id,
@@ -182,19 +179,19 @@ describe('Client.Channels', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('joinChannelByName', function(done) { test('joinChannelByName', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
TestHelper.basicClient().leaveChannel( TestHelper.basicClient().leaveChannel(
channel.id, channel.id,
@@ -205,35 +202,35 @@ describe('Client.Channels', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('deleteChannel', function(done) { test('deleteChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
TestHelper.basicClient().deleteChannel( TestHelper.basicClient().deleteChannel(
channel.id, channel.id,
function(data) { function(data) {
assert.equal(data.id, channel.id); expect(data.id).toEqual(channel.id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('viewChannel', function(done) { test('viewChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
TestHelper.basicClient().viewChannel( TestHelper.basicClient().viewChannel(
channel.id, channel.id,
@@ -243,195 +240,195 @@ describe('Client.Channels', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateLastViewedAt', function(done) { test('updateLastViewedAt', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var channel = TestHelper.basicChannel(); var channel = TestHelper.basicChannel();
TestHelper.basicClient().updateLastViewedAt( TestHelper.basicClient().updateLastViewedAt(
channel.id, channel.id,
true, true,
function(data) { function(data) {
assert.equal(data.id, channel.id); expect(data.id).toEqual(channel.id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getChannels', function(done) { test('getChannels', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getChannels( TestHelper.basicClient().getChannels(
function(data) { function(data) {
assert.equal(data.length, 3); expect(data.length).toBe(3);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getChannel', function(done) { test('getChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getChannel( TestHelper.basicClient().getChannel(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
function(data) { function(data) {
assert.equal(TestHelper.basicChannel().id, data.channel.id); expect(TestHelper.basicChannel().id).toEqual(data.channel.id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getMoreChannels', function(done) { test('getMoreChannels', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getMoreChannels( TestHelper.basicClient().getMoreChannels(
function(data) { function(data) {
assert.equal(data.length, 0); expect(data.length).toBe(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getMoreChannelsPage', function(done) { test('getMoreChannelsPage', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getMoreChannelsPage( TestHelper.basicClient().getMoreChannelsPage(
0, 0,
100, 100,
function(data) { function(data) {
assert.equal(data.length, 0); expect(data.length).toBe(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('searchMoreChannels', function(done) { test('searchMoreChannels', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().searchMoreChannels( TestHelper.basicClient().searchMoreChannels(
'blargh', 'blargh',
function(data) { function(data) {
assert.equal(data.length, 0); expect(data.length).toBe(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('autocompleteChannels', function(done) { test('autocompleteChannels', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().autocompleteChannels( TestHelper.basicClient().autocompleteChannels(
TestHelper.basicChannel().name, TestHelper.basicChannel().name,
function(data) { function(data) {
assert.equal(data != null, true); expect(data).not.toBeNull();
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getChannelCounts', function(done) { test('getChannelCounts', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getChannelCounts( TestHelper.basicClient().getChannelCounts(
function(data) { function(data) {
assert.equal(data.counts[TestHelper.basicChannel().id], 1); expect(data.counts[TestHelper.basicChannel().id]).toBe(1);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getMyChannelMembers', function(done) { test('getMyChannelMembers', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getMyChannelMembers( TestHelper.basicClient().getMyChannelMembers(
function(data) { function(data) {
assert.equal(data.length > 0, true); expect(data.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getMyChannelMembersForTeam', function(done) { test('getMyChannelMembersForTeam', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getMyChannelMembersForTeam( TestHelper.basicClient().getMyChannelMembersForTeam(
TestHelper.basicTeam().id, TestHelper.basicTeam().id,
function(data) { function(data) {
assert.equal(data.length > 0, true); expect(data.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getChannelStats', function(done) { test('getChannelStats', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getChannelStats( TestHelper.basicClient().getChannelStats(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
function(data) { function(data) {
assert.equal(data.member_count, 1); expect(data.member_count).toBe(1);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getChannelMember', function(done) { test('getChannelMember', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getChannelMember( TestHelper.basicClient().getChannelMember(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
TestHelper.basicUser().id, TestHelper.basicUser().id,
function(data) { function(data) {
assert.equal(data.channel_id, TestHelper.basicChannel().id); expect(data.channel_id).toEqual(TestHelper.basicChannel().id);
assert.equal(data.user_id, TestHelper.basicUser().id); expect(data.user_id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('addChannelMember', function(done) { test('addChannelMember', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().createUserWithInvite( TestHelper.basicClient().createUserWithInvite(
TestHelper.fakeUser(), TestHelper.fakeUser(),
null, null,
@@ -442,47 +439,47 @@ describe('Client.Channels', function() {
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
user2.id, user2.id,
function(data) { function(data) {
assert.equal(data.channel_id.length > 0, true); expect(data.channel_id.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('removeChannelMember', function(done) { test('removeChannelMember', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().removeChannelMember( TestHelper.basicClient().removeChannelMember(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
TestHelper.basicUser().id, TestHelper.basicUser().id,
function(data) { function(data) {
assert.equal(data.channel_id.length > 0, true); expect(data.channel_id.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getChannelByName', function(done) { test('getChannelByName', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getChannelByName( TestHelper.basicClient().getChannelByName(
TestHelper.basicChannel().name, TestHelper.basicChannel().name,
function(data) { function(data) {
assert.equal(data.name, TestHelper.basicChannel().name); expect(data.name).toEqual(TestHelper.basicChannel().name);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });

Просмотреть файл

@@ -1,61 +1,58 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.Commands', function() { describe('Client.Commands', function() {
this.timeout(100000); test('listCommands', function(done) {
TestHelper.initBasic(done, () => {
it('listCommands', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().listCommands( TestHelper.basicClient().listCommands(
function(data) { function(data) {
assert.equal(data.length > 0, true); expect(data.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('listTeamCommands', function(done) { test('listTeamCommands', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().listTeamCommands( TestHelper.basicClient().listTeamCommands(
function() { function() {
done(new Error('cmds not enabled')); done.fail(new Error('cmds not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.command.disabled.app_error'); expect(err.id).toEqual('api.command.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('executeCommand', function(done) { test('executeCommand', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
const args = {}; const args = {};
args.channel_id = TestHelper.basicChannel().id; args.channel_id = TestHelper.basicChannel().id;
TestHelper.basicClient().executeCommand( TestHelper.basicClient().executeCommand(
'/shrug', '/shrug',
args, args,
function(data) { function(data) {
assert.equal(data.response_type, 'in_channel'); expect(data.response_type).toEqual('in_channel');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('addCommand', function(done) { test('addCommand', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var cmd = {}; var cmd = {};
@@ -72,18 +69,18 @@ describe('Client.Commands', function() {
TestHelper.basicClient().addCommand( TestHelper.basicClient().addCommand(
cmd, cmd,
function() { function() {
done(new Error('cmds not enabled')); done.fail(new Error('cmds not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.command.disabled.app_error'); expect(err.id).toEqual('api.command.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('editCommand', function(done) { test('editCommand', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var cmd = {}; var cmd = {};
@@ -100,42 +97,42 @@ describe('Client.Commands', function() {
TestHelper.basicClient().editCommand( TestHelper.basicClient().editCommand(
cmd, cmd,
function() { function() {
done(new Error('cmds not enabled')); done.fail(new Error('cmds not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.command.disabled.app_error'); expect(err.id).toEqual('api.command.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('deleteCommand', function(done) { test('deleteCommand', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().deleteCommand( TestHelper.basicClient().deleteCommand(
TestHelper.generateId(), TestHelper.generateId(),
function() { function() {
done(new Error('cmds not enabled')); done.fail(new Error('cmds not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.command.disabled.app_error'); expect(err.id).toEqual('api.command.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('regenCommandToken', function(done) { test('regenCommandToken', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().regenCommandToken( TestHelper.basicClient().regenCommandToken(
TestHelper.generateId(), TestHelper.generateId(),
function() { function() {
done(new Error('cmds not enabled')); done.fail(new Error('cmds not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.command.disabled.app_error'); expect(err.id).toEqual('api.command.disabled.app_error');
done(); done();
} }
); );

Просмотреть файл

@@ -1,50 +1,47 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
const fs = require('fs'); const fs = require('fs');
describe('Client.Emoji', function() { describe('Client.Emoji', function() {
this.timeout(100000);
const testGifFileName = 'testEmoji.gif'; const testGifFileName = 'testEmoji.gif';
before(function() { beforeAll(function() {
// write a temporary file so that we have something to upload for testing // write a temporary file so that we have something to upload for testing
const buffer = new Buffer('R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=', 'base64'); const buffer = new Buffer('R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=', 'base64');
const testGif = fs.openSync(testGifFileName, 'w+'); const testGif = fs.openSync(testGifFileName, 'w+');
fs.writeFileSync(testGif, buffer); fs.writeFileSync(testGif, buffer);
}); });
after(function() { afterAll(function() {
fs.unlinkSync(testGifFileName); fs.unlinkSync(testGifFileName);
}); });
it('addEmoji', function(done) { test('addEmoji', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
const name = TestHelper.generateId(); const name = TestHelper.generateId();
TestHelper.basicClient().addEmoji( TestHelper.basicClient().addEmoji(
{creator_id: TestHelper.basicUser().id, name}, {creator_id: TestHelper.basicUser().id, name},
fs.createReadStream(testGifFileName), fs.createReadStream(testGifFileName),
function(data) { function(data) {
assert.equal(data.name, name); expect(data.name).toEqual(name);
assert.notEqual(data.id, null); expect(data.id).not.toBeNull();
TestHelper.basicClient().deleteEmoji(data.id); //TestHelper.basicClient().deleteEmoji(data.id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('deleteEmoji', function(done) { test('deleteEmoji', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().addEmoji( TestHelper.basicClient().addEmoji(
{creator_id: TestHelper.basicUser().id, name: TestHelper.generateId()}, {creator_id: TestHelper.basicUser().id, name: TestHelper.generateId()},
fs.createReadStream(testGifFileName), fs.createReadStream(testGifFileName),
@@ -55,19 +52,19 @@ describe('Client.Emoji', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('listEmoji', function(done) { test('listEmoji', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
const name = TestHelper.generateId(); const name = TestHelper.generateId();
TestHelper.basicClient().addEmoji( TestHelper.basicClient().addEmoji(
{creator_id: TestHelper.basicUser().id, name}, {creator_id: TestHelper.basicUser().id, name},
@@ -75,7 +72,7 @@ describe('Client.Emoji', function() {
function() { function() {
TestHelper.basicClient().listEmoji( TestHelper.basicClient().listEmoji(
function(data) { function(data) {
assert(data.length > 0, true); expect(data.length).toBeGreaterThan(0);
let found = false; let found = false;
for (const emoji of data) { for (const emoji of data) {
@@ -88,16 +85,16 @@ describe('Client.Emoji', function() {
if (found) { if (found) {
done(); done();
} else { } else {
done(new Error('test emoji wasn\'t returned')); done.fail(new Error('test emoji wasn\'t returned'));
} }
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });

Просмотреть файл

@@ -1,17 +1,14 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
const fs = require('fs'); const fs = require('fs');
describe('Client.File', function() { describe('Client.File', function() {
this.timeout(100000);
const testGifFileName = 'testFile.gif'; const testGifFileName = 'testFile.gif';
before(function() { beforeAll(function() {
// write a temporary file so that we have something to upload for testing // write a temporary file so that we have something to upload for testing
const buffer = new Buffer('R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=', 'base64'); const buffer = new Buffer('R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=', 'base64');
@@ -19,12 +16,12 @@ describe('Client.File', function() {
fs.writeFileSync(testGif, buffer); fs.writeFileSync(testGif, buffer);
}); });
after(function() { afterAll(function() {
fs.unlinkSync(testGifFileName); fs.unlinkSync(testGifFileName);
}); });
it('uploadFile', function(done) { test('uploadFile', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
const clientId = TestHelper.generateId(); const clientId = TestHelper.generateId();
TestHelper.basicClient().uploadFile( TestHelper.basicClient().uploadFile(
@@ -33,21 +30,21 @@ describe('Client.File', function() {
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
clientId, clientId,
function(resp) { function(resp) {
assert.equal(resp.file_infos.length, 1); expect(resp.file_infos.length).toBe(1);
assert.equal(resp.client_ids.length, 1); expect(resp.client_ids.length).toBe(1);
assert.equal(resp.client_ids[0], clientId); expect(resp.client_ids[0]).toEqual(clientId);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getFile', function(done) { test('getFile', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().uploadFile( TestHelper.basicClient().uploadFile(
fs.createReadStream(testGifFileName), fs.createReadStream(testGifFileName),
testGifFileName, testGifFileName,
@@ -60,19 +57,19 @@ describe('Client.File', function() {
done(); done();
}, },
function(err2) { function(err2) {
done(new Error(err2.message)); done.fail(new Error(err2.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getFileThumbnail', function(done) { test('getFileThumbnail', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().uploadFile( TestHelper.basicClient().uploadFile(
fs.createReadStream(testGifFileName), fs.createReadStream(testGifFileName),
testGifFileName, testGifFileName,
@@ -85,19 +82,19 @@ describe('Client.File', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getFilePreview', function(done) { test('getFilePreview', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().uploadFile( TestHelper.basicClient().uploadFile(
fs.createReadStream(testGifFileName), fs.createReadStream(testGifFileName),
testGifFileName, testGifFileName,
@@ -110,19 +107,19 @@ describe('Client.File', function() {
done(); done();
}, },
function(err2) { function(err2) {
done(new Error(err2.message)); done.fail(new Error(err2.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getFileInfo', function(done) { test('getFileInfo', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().uploadFile( TestHelper.basicClient().uploadFile(
fs.createReadStream(testGifFileName), fs.createReadStream(testGifFileName),
testGifFileName, testGifFileName,
@@ -134,25 +131,26 @@ describe('Client.File', function() {
TestHelper.basicClient().getFileInfo( TestHelper.basicClient().getFileInfo(
fileId, fileId,
function(info) { function(info) {
assert.equal(info.id, fileId); expect(info.id).toEqual(fileId);
assert.equal(info.name, testGifFileName); expect(info.name).toEqual(testGifFileName);
done(); done();
}, },
function(err2) { function(err2) {
done(new Error(err2.message)); done.fail(new Error(err2.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getPublicLink', function(done) { test('getPublicLink', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().uploadFile( TestHelper.basicClient().uploadFile(
fs.createReadStream(testGifFileName), fs.createReadStream(testGifFileName),
testGifFileName, testGifFileName,
@@ -166,12 +164,12 @@ describe('Client.File', function() {
TestHelper.basicClient().createPost( TestHelper.basicClient().createPost(
post, post,
function(data) { function(data) {
assert.deepEqual(data.file_ids, post.file_ids); expect(data.file_ids).toEqual(post.file_ids);
TestHelper.basicClient().getPublicLink( TestHelper.basicClient().getPublicLink(
post.file_ids[0], post.file_ids[0],
function() { function() {
done(new Error('public links should be disabled by default')); done.fail(new Error('public links should be disabled by default'));
// request. // request.
// get(link). // get(link).
@@ -182,31 +180,31 @@ describe('Client.File', function() {
// done(); // done();
// }, // },
// function(err4) { // function(err4) {
// done(new Error(err4.message)); // done.fail(new Error(err4.message));
// } // }
// )); // ));
}, },
function() { function() {
done(); done();
// done(new Error(err3.message)); // done.fail(new Error(err3.message));
} }
); );
}, },
function(err2) { function(err2) {
done(new Error(err2.message)); done.fail(new Error(err2.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getFileInfosForPost', function(done) { test('getFileInfosForPost', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().uploadFile( TestHelper.basicClient().uploadFile(
fs.createReadStream(testGifFileName), fs.createReadStream(testGifFileName),
testGifFileName, testGifFileName,
@@ -220,29 +218,29 @@ describe('Client.File', function() {
TestHelper.basicClient().createPost( TestHelper.basicClient().createPost(
post, post,
function(data) { function(data) {
assert.deepEqual(data.file_ids, post.file_ids); expect(data.file_ids).toEqual(post.file_ids);
TestHelper.basicClient().getFileInfosForPost( TestHelper.basicClient().getFileInfosForPost(
post.channel_id, post.channel_id,
data.id, data.id,
function(files) { function(files) {
assert.equal(files.length, 1); expect(files.length).toBe(1);
assert.equal(files[0].id, resp.file_infos[0].id); expect(files[0].id).toEqual(resp.file_infos[0].id);
done(); done();
}, },
function(err3) { function(err3) {
done(new Error(err3.message)); done.fail(new Error(err3.message));
} }
); );
}, },
function(err2) { function(err2) {
done(new Error(err2.message)); done.fail(new Error(err2.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });

Просмотреть файл

@@ -1,42 +1,39 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
var assert = require('assert'); import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.General', function() { describe('Client.General', function() {
this.timeout(10000); test('General.getClientConfig', function(done) {
TestHelper.initBasic(done, () => {
it('General.getClientConfig', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().getClientConfig( TestHelper.basicClient().getClientConfig(
function(data) { function(data) {
assert.equal(data.SiteName, 'Mattermost'); expect(data.SiteName).toEqual('Mattermost');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('General.getPing', function(done) { test('General.getPing', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getPing( TestHelper.basicClient().getPing(
function(data) { function(data) {
assert.equal(data.version.length > 0, true); expect(data.version.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('General.logClientError', function(done) { test('General.logClientError', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var config = {}; var config = {};
config.site_name = 'test'; config.site_name = 'test';
TestHelper.basicClient().logClientError('this is a test'); TestHelper.basicClient().logClientError('this is a test');

Просмотреть файл

@@ -1,14 +1,11 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.Hooks', function() { describe('Client.Hooks', function() {
this.timeout(100000); test('addIncomingHook', function(done) {
TestHelper.initBasic(done, () => {
it('addIncomingHook', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var hook = {}; var hook = {};
@@ -19,18 +16,18 @@ describe('Client.Hooks', function() {
TestHelper.basicClient().addIncomingHook( TestHelper.basicClient().addIncomingHook(
hook, hook,
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.incoming_webhook.disabled.app_error'); expect(err.id).toBe('api.incoming_webhook.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('updateIncomingHook', function(done) { test('updateIncomingHook', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var hook = {}; var hook = {};
@@ -41,49 +38,49 @@ describe('Client.Hooks', function() {
TestHelper.basicClient().updateIncomingHook( TestHelper.basicClient().updateIncomingHook(
hook, hook,
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.incoming_webhook.disabled.app_error'); expect(err.id).toBe('api.incoming_webhook.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('deleteIncomingHook', function(done) { test('deleteIncomingHook', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().deleteIncomingHook( TestHelper.basicClient().deleteIncomingHook(
TestHelper.generateId(), TestHelper.generateId(),
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.incoming_webhook.disabled.app_error'); expect(err.id).toBe('api.incoming_webhook.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('listIncomingHooks', function(done) { test('listIncomingHooks', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().listIncomingHooks( TestHelper.basicClient().listIncomingHooks(
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.incoming_webhook.disabled.app_error'); expect(err.id).toBe('api.incoming_webhook.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('addOutgoingHook', function(done) { test('addOutgoingHook', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var hook = {}; var hook = {};
@@ -94,65 +91,65 @@ describe('Client.Hooks', function() {
TestHelper.basicClient().addOutgoingHook( TestHelper.basicClient().addOutgoingHook(
hook, hook,
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.outgoing_webhook.disabled.app_error'); expect(err.id).toBe('api.outgoing_webhook.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('deleteOutgoingHook', function(done) { test('deleteOutgoingHook', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().deleteOutgoingHook( TestHelper.basicClient().deleteOutgoingHook(
TestHelper.generateId(), TestHelper.generateId(),
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.outgoing_webhook.disabled.app_error'); expect(err.id).toBe('api.outgoing_webhook.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('listOutgoingHooks', function(done) { test('listOutgoingHooks', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().listOutgoingHooks( TestHelper.basicClient().listOutgoingHooks(
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.outgoing_webhook.disabled.app_error'); expect(err.id).toBe('api.outgoing_webhook.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('regenOutgoingHookToken', function(done) { test('regenOutgoingHookToken', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().regenOutgoingHookToken( TestHelper.basicClient().regenOutgoingHookToken(
TestHelper.generateId(), TestHelper.generateId(),
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.outgoing_webhook.disabled.app_error'); expect(err.id).toBe('api.outgoing_webhook.disabled.app_error');
done(); done();
} }
); );
}); });
}); });
it('updateOutgoingHook', function(done) { test('updateOutgoingHook', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var hook = {}; var hook = {};
@@ -163,10 +160,10 @@ describe('Client.Hooks', function() {
TestHelper.basicClient().updateOutgoingHook( TestHelper.basicClient().updateOutgoingHook(
hook, hook,
function() { function() {
done(new Error('hooks not enabled')); done.fail(new Error('hooks not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.outgoing_webhook.disabled.app_error'); expect(err.id).toBe('api.outgoing_webhook.disabled.app_error');
done(); done();
} }
); );

Просмотреть файл

@@ -1,14 +1,11 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.OAuth', function() { describe('Client.OAuth', function() {
this.timeout(100000); test('registerOAuthApp', function(done) {
TestHelper.initBasic(done, () => {
it('registerOAuthApp', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var app = {}; var app = {};
@@ -20,18 +17,18 @@ describe('Client.OAuth', function() {
TestHelper.basicClient().registerOAuthApp( TestHelper.basicClient().registerOAuthApp(
app, app,
function() { function() {
done(new Error('not enabled')); done.fail(new Error('not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.oauth.register_oauth_app.turn_off.app_error'); expect(err.id).toBe('api.oauth.register_oauth_app.turn_off.app_error');
done(); done();
} }
); );
}); });
}); });
it('allowOAuth2', function(done) { test('allowOAuth2', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().allowOAuth2( TestHelper.basicClient().allowOAuth2(
@@ -41,10 +38,10 @@ describe('Client.OAuth', function() {
'state', 'state',
'scope', 'scope',
function() { function() {
done(new Error('not enabled')); done.fail(new Error('not enabled'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.oauth.allow_oauth.turn_off.app_error'); expect(err.id).toBe('api.oauth.allow_oauth.turn_off.app_error');
done(); done();
} }
); );

Просмотреть файл

@@ -1,63 +1,60 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.Posts', function() { describe('Client.Posts', function() {
this.timeout(100000); test('createPost', function(done) {
TestHelper.initBasic(done, () => {
it('createPost', function(done) {
TestHelper.initBasic(() => {
var post = TestHelper.fakePost(); var post = TestHelper.fakePost();
post.channel_id = TestHelper.basicChannel().id; post.channel_id = TestHelper.basicChannel().id;
TestHelper.basicClient().createPost( TestHelper.basicClient().createPost(
post, post,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getPostById', function(done) { test('getPostById', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getPostById( TestHelper.basicClient().getPostById(
TestHelper.basicPost().id, TestHelper.basicPost().id,
function(data) { function(data) {
assert.equal(data.order[0], TestHelper.basicPost().id); expect(data.order[0]).toEqual(TestHelper.basicPost().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getPost', function(done) { test('getPost', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getPost( TestHelper.basicClient().getPost(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
TestHelper.basicPost().id, TestHelper.basicPost().id,
function(data) { function(data) {
assert.equal(data.order[0], TestHelper.basicPost().id); expect(data.order[0]).toEqual(TestHelper.basicPost().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updatePost', function(done) { test('updatePost', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var post = TestHelper.basicPost(); var post = TestHelper.basicPost();
post.message = 'new message'; post.message = 'new message';
post.channel_id = TestHelper.basicChannel().id; post.channel_id = TestHelper.basicChannel().id;
@@ -65,83 +62,83 @@ describe('Client.Posts', function() {
TestHelper.basicClient().updatePost( TestHelper.basicClient().updatePost(
post, post,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('deletePost', function(done) { test('deletePost', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().deletePost( TestHelper.basicClient().deletePost(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
TestHelper.basicPost().id, TestHelper.basicPost().id,
function(data) { function(data) {
assert.equal(data.id, TestHelper.basicPost().id); expect(data.id).toEqual(TestHelper.basicPost().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('searchPost', function(done) { test('searchPost', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().search( TestHelper.basicClient().search(
'unit test', 'unit test',
false, false,
function(data) { function(data) {
assert.equal(data.order[0], TestHelper.basicPost().id); expect(data.order[0]).toEqual(TestHelper.basicPost().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getPostsPage', function(done) { test('getPostsPage', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getPostsPage( TestHelper.basicClient().getPostsPage(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
0, 0,
10, 10,
function(data) { function(data) {
assert.equal(data.order[0], TestHelper.basicPost().id); expect(data.order[0]).toEqual(TestHelper.basicPost().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getPosts', function(done) { test('getPosts', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getPosts( TestHelper.basicClient().getPosts(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
0, 0,
function(data) { function(data) {
assert.equal(data.order[0], TestHelper.basicPost().id); expect(data.order[0]).toEqual(TestHelper.basicPost().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getPostsBefore', function(done) { test('getPostsBefore', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var post = TestHelper.fakePost(); var post = TestHelper.fakePost();
post.channel_id = TestHelper.basicChannel().id; post.channel_id = TestHelper.basicChannel().id;
@@ -154,23 +151,23 @@ describe('Client.Posts', function() {
0, 0,
10, 10,
function(data) { function(data) {
assert.equal(data.order[0], TestHelper.basicPost().id); expect(data.order[0]).toEqual(TestHelper.basicPost().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getPostsAfter', function(done) { test('getPostsAfter', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var post = TestHelper.fakePost(); var post = TestHelper.fakePost();
post.channel_id = TestHelper.basicChannel().id; post.channel_id = TestHelper.basicChannel().id;
@@ -183,23 +180,23 @@ describe('Client.Posts', function() {
0, 0,
10, 10,
function(data) { function(data) {
assert.equal(data.order[0], rpost.id); expect(data.order[0]).toEqual(rpost.id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getFlaggedPosts', function(done) { test('getFlaggedPosts', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var pref = {}; var pref = {};
pref.user_id = TestHelper.basicUser().id; pref.user_id = TestHelper.basicUser().id;
pref.category = 'flagged_post'; pref.category = 'flagged_post';
@@ -216,16 +213,16 @@ describe('Client.Posts', function() {
0, 0,
2, 2,
function(data) { function(data) {
assert.equal(data.order[0], TestHelper.basicPost().id); expect(data.order[0]).toEqual(TestHelper.basicPost().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });

Просмотреть файл

@@ -1,29 +1,26 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.Preferences', function() { describe('Client.Preferences', function() {
this.timeout(100000); test('getAllPreferences', function(done) {
TestHelper.initBasic(done, () => {
it('getAllPreferences', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().getAllPreferences( TestHelper.basicClient().getAllPreferences(
function(data) { function(data) {
assert.equal(data[0].category, 'tutorial_step'); expect(data[0].category).toBe('tutorial_step');
assert.equal(data[0].user_id, TestHelper.basicUser().id); expect(data[0].user_id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('savePreferences', function(done) { test('savePreferences', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var perf = {}; var perf = {};
perf.user_id = TestHelper.basicUser().id; perf.user_id = TestHelper.basicUser().id;
perf.category = 'test'; perf.category = 'test';
@@ -36,27 +33,27 @@ describe('Client.Preferences', function() {
TestHelper.basicClient().savePreferences( TestHelper.basicClient().savePreferences(
perfs, perfs,
function(data) { function(data) {
assert.equal(data, true); expect(data).toBe(true);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getPreferenceCategory', function(done) { test('getPreferenceCategory', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getPreferenceCategory( TestHelper.basicClient().getPreferenceCategory(
'tutorial_step', 'tutorial_step',
function(data) { function(data) {
assert.equal(data[0].category, 'tutorial_step'); expect(data[0].category).toBe('tutorial_step');
assert.equal(data[0].user_id, TestHelper.basicUser().id); expect(data[0].user_id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });

Просмотреть файл

@@ -1,13 +1,11 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import TestHelper from './test_helper.jsx'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
describe('Client.Reaction', function() { describe('Client.Reaction', function() {
this.timeout(100000); test('saveListReaction', function(done) {
TestHelper.initBasic(done, () => {
it('saveListReaction', function(done) {
TestHelper.initBasic(() => {
const channelId = TestHelper.basicChannel().id; const channelId = TestHelper.basicChannel().id;
const postId = TestHelper.basicPost().id; const postId = TestHelper.basicPost().id;
@@ -31,23 +29,23 @@ describe('Client.Reaction', function() {
reactions[0].emoji_name === reaction.emoji_name) { reactions[0].emoji_name === reaction.emoji_name) {
done(); done();
} else { } else {
done(new Error('test reaction wasn\'t returned')); done.fail(new Error('test reaction wasn\'t returned'));
} }
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('deleteReaction', function(done) { test('deleteReaction', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
const channelId = TestHelper.basicChannel().id; const channelId = TestHelper.basicChannel().id;
const postId = TestHelper.basicPost().id; const postId = TestHelper.basicPost().id;
@@ -68,12 +66,12 @@ describe('Client.Reaction', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });

Просмотреть файл

@@ -1,168 +1,165 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.Team', function() { describe('Client.Team', function() {
this.timeout(100000); test('findTeamByName', function(done) {
TestHelper.initBasic(done, () => {
it('findTeamByName', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().findTeamByName( TestHelper.basicClient().findTeamByName(
TestHelper.basicTeam().name, TestHelper.basicTeam().name,
function(data) { function(data) {
assert.equal(data, true); expect(data).toBe(true);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('createTeam', function(done) { test('createTeam', function(done) {
var team = TestHelper.fakeTeam(); var team = TestHelper.fakeTeam();
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().createTeam( TestHelper.basicClient().createTeam(
team, team,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.name, team.name); expect(data.name).toEqual(team.name);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getAllTeams', function(done) { test('getAllTeams', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getAllTeams( TestHelper.basicClient().getAllTeams(
function(data) { function(data) {
assert.equal(data[TestHelper.basicTeam().id].name, TestHelper.basicTeam().name); expect(data[TestHelper.basicTeam().id].name).toEqual(TestHelper.basicTeam().name);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getAllTeamListings', function(done) { test('getAllTeamListings', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getAllTeamListings( TestHelper.basicClient().getAllTeamListings(
function(data) { function(data) {
assert.equal(data != null, true); expect(data).not.toBeNull();
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getMyTeam', function(done) { test('getMyTeam', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getMyTeam( TestHelper.basicClient().getMyTeam(
function(data) { function(data) {
assert.equal(data.name, TestHelper.basicTeam().name); expect(data.name).toEqual(TestHelper.basicTeam().name);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getMyTeamMembers', function(done) { test('getMyTeamMembers', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getMyTeamMembers( TestHelper.basicClient().getMyTeamMembers(
function(data) { function(data) {
assert.equal(data.length > 0, true); expect(data.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getTeamMembers', function(done) { test('getTeamMembers', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getTeamMembers( TestHelper.basicClient().getTeamMembers(
TestHelper.basicTeam().id, TestHelper.basicTeam().id,
0, 0,
100, 100,
function(data) { function(data) {
assert.equal(data.length > 0, true); expect(data.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getTeamMember', function(done) { test('getTeamMember', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getTeamMember( TestHelper.basicClient().getTeamMember(
TestHelper.basicTeam().id, TestHelper.basicTeam().id,
TestHelper.basicUser().id, TestHelper.basicUser().id,
function(data) { function(data) {
assert.equal(data.user_id, TestHelper.basicUser().id); expect(data.user_id).toEqual(TestHelper.basicUser().id);
assert.equal(data.team_id, TestHelper.basicTeam().id); expect(data.team_id).toEqual(TestHelper.basicTeam().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getTeamStats', function(done) { test('getTeamStats', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getTeamStats( TestHelper.basicClient().getTeamStats(
TestHelper.basicTeam().id, TestHelper.basicTeam().id,
function(data) { function(data) {
assert.equal(data.total_member_count > 0, true); expect(data.total_member_count).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getTeamMembersByIds', function(done) { test('getTeamMembersByIds', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getTeamMembersByIds( TestHelper.basicClient().getTeamMembersByIds(
TestHelper.basicTeam().id, TestHelper.basicTeam().id,
[TestHelper.basicUser().id], [TestHelper.basicUser().id],
function(data) { function(data) {
assert.equal(data[0].user_id, TestHelper.basicUser().id); expect(data[0].user_id).toEqual(TestHelper.basicUser().id);
assert.equal(data[0].team_id, TestHelper.basicTeam().id); expect(data[0].team_id).toEqual(TestHelper.basicTeam().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('inviteMembers', function(done) { test('inviteMembers', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var data = {}; var data = {};
data.invites = []; data.invites = [];
var invite = {}; var invite = {};
@@ -174,54 +171,54 @@ describe('Client.Team', function() {
TestHelper.basicClient().inviteMembers( TestHelper.basicClient().inviteMembers(
data, data,
function(dataBack) { function(dataBack) {
assert.equal(dataBack.invites.length, 1); expect(dataBack.invites.length).toBe(1);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateTeam', function(done) { test('updateTeam', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var team = TestHelper.basicTeam(); var team = TestHelper.basicTeam();
team.display_name = 'test_updated'; team.display_name = 'test_updated';
TestHelper.basicClient().updateTeam( TestHelper.basicClient().updateTeam(
team, team,
function(data) { function(data) {
assert.equal(data.display_name, 'test_updated'); expect(data.display_name).toBe('test_updated');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateTeamDescription', function(done) { test('updateTeamDescription', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var team = TestHelper.basicTeam(); var team = TestHelper.basicTeam();
team.description = 'test_updated'; team.description = 'test_updated';
TestHelper.basicClient().updateTeam( TestHelper.basicClient().updateTeam(
team, team,
function(data) { function(data) {
assert.equal(data.description, 'test_updated'); expect(data.description).toBe('test_updated');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('addUserToTeam', function(done) { test('addUserToTeam', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().createUser( TestHelper.basicClient().createUser(
TestHelper.fakeUser(), TestHelper.fakeUser(),
function(user2) { function(user2) {
@@ -229,54 +226,54 @@ describe('Client.Team', function() {
'', '',
user2.id, user2.id,
function(data) { function(data) {
assert.equal(data.user_id, user2.id); expect(data.user_id).toEqual(user2.id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('removeUserFromTeam', function(done) { test('removeUserFromTeam', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().removeUserFromTeam( TestHelper.basicClient().removeUserFromTeam(
'', '',
TestHelper.basicUser().id, TestHelper.basicUser().id,
function(data) { function(data) {
assert.equal(data.user_id, TestHelper.basicUser().id); expect(data.user_id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getInviteInfo', function(done) { test('getInviteInfo', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getInviteInfo( TestHelper.basicClient().getInviteInfo(
TestHelper.basicTeam().invite_id, TestHelper.basicTeam().invite_id,
function(data) { function(data) {
assert.equal(data.display_name.length > 0, true); expect(data.display_name.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateTeamMemberRoles', function(done) { test('updateTeamMemberRoles', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
var team = TestHelper.basicTeam(); var team = TestHelper.basicTeam();
@@ -288,23 +285,22 @@ describe('Client.Team', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getTeamByName', function(done) { test('getTeamByName', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getTeamByName( TestHelper.basicClient().getTeamByName(
TestHelper.basicTeam().name, TestHelper.basicTeam().name,
function(data) { function(data) {
console.log(data); expect(data.name).toEqual(TestHelper.basicTeam().name);
assert.equal(data.name, TestHelper.basicTeam().name);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });

Просмотреть файл

@@ -1,102 +1,99 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import assert from 'assert'; import TestHelper from 'tests/helpers/client-test-helper.jsx';
import TestHelper from './test_helper.jsx';
describe('Client.User', function() { describe('Client.User', function() {
this.timeout(100000); test('getMe', function(done) {
TestHelper.initBasic(done, () => {
it('getMe', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().getMe( TestHelper.basicClient().getMe(
function(data) { function(data) {
assert.equal(data.id, TestHelper.basicUser().id); expect(data.id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getUser', function(done) { test('getUser', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getUser( TestHelper.basicClient().getUser(
TestHelper.basicUser().id, TestHelper.basicUser().id,
function(data) { function(data) {
assert.equal(data.id, TestHelper.basicUser().id); expect(data.id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getByUsername', function(done) { test('getByUsername', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getByUsername( TestHelper.basicClient().getByUsername(
TestHelper.basicUser().username, TestHelper.basicUser().username,
function(data) { function(data) {
assert.equal(data.username, TestHelper.basicUser().username); expect(data.username).toEqual(TestHelper.basicUser().username);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getByEmail', function(done) { test('getByEmail', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getByEmail( TestHelper.basicClient().getByEmail(
TestHelper.basicUser().email, TestHelper.basicUser().email,
function(data) { function(data) {
assert.equal(data.email, TestHelper.basicUser().email); expect(data.email).toEqual(TestHelper.basicUser().email);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getInitialLoad', function(done) { test('getInitialLoad', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getInitialLoad( TestHelper.basicClient().getInitialLoad(
function(data) { function(data) {
assert.equal(data.user.id.length > 0, true); expect(data.user.id.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('createUser', function(done) { test('createUser', function(done) {
var client = TestHelper.createClient(); var client = TestHelper.createClient();
var user = TestHelper.fakeUser(); var user = TestHelper.fakeUser();
client.createUser( client.createUser(
user, user,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.email, user.email); expect(data.email).toEqual(user.email);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
it('loginByEmail', function(done) { test('loginByEmail', function(done) {
var client = TestHelper.createClient(); var client = TestHelper.createClient();
var user = TestHelper.fakeUser(); var user = TestHelper.fakeUser();
client.createUser( client.createUser(
@@ -107,49 +104,49 @@ describe('Client.User', function() {
user.password, user.password,
null, null,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.email, user.email); expect(data.email).toEqual(user.email);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
it('loginById', function(done) { test('loginById', function(done) {
var client = TestHelper.createClient(); var client = TestHelper.createClient();
var user = TestHelper.fakeUser(); var user = TestHelper.fakeUser();
client.createUser( client.createUser(
user, user,
function(newUser) { function(newUser) {
assert.equal(user.email, newUser.email); expect(user.email).toEqual(newUser.email);
client.loginById( client.loginById(
newUser.id, newUser.id,
user.password, user.password,
null, null,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.email, user.email); expect(data.email).toEqual(user.email);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
it('loginByUsername', function(done) { test('loginByUsername', function(done) {
var client = TestHelper.createClient(); var client = TestHelper.createClient();
var user = TestHelper.fakeUser(); var user = TestHelper.fakeUser();
client.createUser( client.createUser(
@@ -160,41 +157,41 @@ describe('Client.User', function() {
user.password, user.password,
null, null,
function(data) { function(data) {
assert.equal(data.id.length > 0, true); expect(data.id.length).toBeGreaterThan(0);
assert.equal(data.email, user.email); expect(data.email).toEqual(user.email);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
it('updateUser', function(done) { test('updateUser', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
user.nickname = 'updated'; user.nickname = 'updated';
TestHelper.basicClient().updateUser( TestHelper.basicClient().updateUser(
user, null, user, null,
function(data) { function(data) {
assert.equal(data.nickname, 'updated'); expect(data.nickname).toBe('updated');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updatePassword', function(done) { test('updatePassword', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
TestHelper.basicClient().updatePassword( TestHelper.basicClient().updatePassword(
@@ -202,18 +199,18 @@ describe('Client.User', function() {
user.password, user.password,
'update_password', 'update_password',
function(data) { function(data) {
assert.equal(data.user_id, user.id); expect(data.user_id).toEqual(user.id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateUserNotifyProps', function(done) { test('updateUserNotifyProps', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
var notifyProps = { var notifyProps = {
@@ -231,25 +228,26 @@ describe('Client.User', function() {
TestHelper.basicClient().updateUserNotifyProps( TestHelper.basicClient().updateUserNotifyProps(
notifyProps, notifyProps,
function(data) { function(data) {
assert.equal(data.notify_props.email, 'false'); expect(data.notify_props.email).toBe('false');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateUserRoles', function(done) { test('updateUserRoles', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
TestHelper.basicClient().updateUserRoles( TestHelper.basicClient().updateUserRoles(
user.id, user.id,
'', '',
function() { function() {
done(new Error('Not supposed to work')); done.fail(new Error('Not supposed to work'));
}, },
function() { function() {
done(); done();
@@ -258,43 +256,43 @@ describe('Client.User', function() {
}); });
}); });
it('updateActive', function(done) { test('updateActive', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
const user = TestHelper.basicUser(); const user = TestHelper.basicUser();
TestHelper.basicClient().updateActive( TestHelper.basicClient().updateActive(
user.id, user.id,
false, false,
function(data) { function(data) {
assert.ok(data.delete_at > 0); expect(data.delete_at).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('sendPasswordReset', function(done) { test('sendPasswordReset', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
TestHelper.basicClient().sendPasswordReset( TestHelper.basicClient().sendPasswordReset(
user.email, user.email,
function(data) { function(data) {
assert.equal(data.email, user.email); expect(data.email).toEqual(user.email);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('resetPassword', function(done) { test('resetPassword', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().resetPassword( TestHelper.basicClient().resetPassword(
@@ -305,15 +303,15 @@ describe('Client.User', function() {
}, },
function(err) { function(err) {
// this should fail since you're not a system admin // this should fail since you're not a system admin
assert.equal(err.id, 'api.context.invalid_param.app_error'); expect(err.id).toBe('api.context.invalid_param.app_error');
done(); done();
} }
); );
}); });
}); });
it('emailToOAuth', function(done) { test('emailToOAuth', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
@@ -327,33 +325,33 @@ describe('Client.User', function() {
}, },
function(err) { function(err) {
// this should fail since you're not a system admin // this should fail since you're not a system admin
assert.equal(err.id, 'api.user.check_user_password.invalid.app_error'); expect(err.id).toBe('api.user.check_user_password.invalid.app_error');
done(); done();
} }
); );
}); });
}); });
it('oauthToEmail', function(done) { test('oauthToEmail', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
TestHelper.basicClient().oauthToEmail( TestHelper.basicClient().oauthToEmail(
user.email, user.email,
'new_password', 'new_password',
function(data) { function(data) {
assert.equal(data.follow_link.length > 0, true); expect(data.follow_link.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('emailToLdap', function(done) { test('emailToLdap', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
@@ -373,8 +371,8 @@ describe('Client.User', function() {
}); });
}); });
it('ldapToEmail', function(done) { test('ldapToEmail', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
var user = TestHelper.basicUser(); var user = TestHelper.basicUser();
@@ -387,47 +385,48 @@ describe('Client.User', function() {
throw Error('shouldnt work'); throw Error('shouldnt work');
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.user.ldap_to_email.not_ldap_account.app_error'); expect(err.id).toBe('api.user.ldap_to_email.not_ldap_account.app_error');
done(); done();
} }
); );
}); });
}); });
it('logout', function(done) { test('logout', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().logout( TestHelper.basicClient().logout(
function(data) { function(data) {
assert.equal(data.user_id, TestHelper.basicUser().id); expect(data.user_id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('checkMfa', function(done) { test('checkMfa', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().checkMfa( TestHelper.basicClient().checkMfa(
TestHelper.generateId(), TestHelper.generateId(),
function(data) { function(data) {
assert.equal(data.mfa_required, 'false'); expect(data.mfa_required).toBe('false');
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('generateMfaSecret', function(done) { test('generateMfaSecret', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().generateMfaSecret( TestHelper.basicClient().generateMfaSecret(
function() { function() {
done(new Error('not enabled')); done.fail(new Error('not enabled'));
}, },
function() { function() {
done(); done();
@@ -436,224 +435,224 @@ describe('Client.User', function() {
}); });
}); });
it('getSessions', function(done) { test('getSessions', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getSessions( TestHelper.basicClient().getSessions(
TestHelper.basicUser().id, TestHelper.basicUser().id,
function(data) { function(data) {
assert.equal(data[0].user_id, TestHelper.basicUser().id); expect(data[0].user_id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('revokeSession', function(done) { test('revokeSession', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getSessions( TestHelper.basicClient().getSessions(
TestHelper.basicUser().id, TestHelper.basicUser().id,
function(sessions) { function(sessions) {
TestHelper.basicClient().revokeSession( TestHelper.basicClient().revokeSession(
sessions[0].id, sessions[0].id,
function(data) { function(data) {
assert.equal(data.id, sessions[0].id); expect(data.id).toEqual(sessions[0].id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getAudits', function(done) { test('getAudits', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getAudits( TestHelper.basicClient().getAudits(
TestHelper.basicUser().id, TestHelper.basicUser().id,
function(data) { function(data) {
assert.equal(data[0].user_id, TestHelper.basicUser().id); expect(data[0].user_id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getProfiles', function(done) { test('getProfiles', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getProfiles( TestHelper.basicClient().getProfiles(
0, 0,
100, 100,
function(data) { function(data) {
assert.equal(Object.keys(data).length > 0, true); expect(Object.keys(data).length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getProfilesInTeam', function(done) { test('getProfilesInTeam', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getProfilesInTeam( TestHelper.basicClient().getProfilesInTeam(
TestHelper.basicTeam().id, TestHelper.basicTeam().id,
0, 0,
100, 100,
function(data) { function(data) {
assert.equal(data[TestHelper.basicUser().id].id, TestHelper.basicUser().id); expect(data[TestHelper.basicUser().id].id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getProfilesByIds', function(done) { test('getProfilesByIds', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getProfilesByIds( TestHelper.basicClient().getProfilesByIds(
[TestHelper.basicUser().id], [TestHelper.basicUser().id],
function(data) { function(data) {
assert.equal(data[TestHelper.basicUser().id].id, TestHelper.basicUser().id); expect(data[TestHelper.basicUser().id].id).toEqual(TestHelper.basicUser().id);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getProfilesInChannel', function(done) { test('getProfilesInChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getProfilesInChannel( TestHelper.basicClient().getProfilesInChannel(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
0, 0,
100, 100,
function(data) { function(data) {
assert.equal(Object.keys(data).length > 0, true); expect(Object.keys(data).length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getProfilesNotInChannel', function(done) { test('getProfilesNotInChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().getProfilesNotInChannel( TestHelper.basicClient().getProfilesNotInChannel(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
0, 0,
100, 100,
function(data) { function(data) {
assert.equal(Object.keys(data).length > 0, false); expect(Object.keys(data).length).not.toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('searchUsers', function(done) { test('searchUsers', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().searchUsers( TestHelper.basicClient().searchUsers(
'uid', 'uid',
TestHelper.basicTeam().id, TestHelper.basicTeam().id,
{}, {},
function(data) { function(data) {
assert.equal(data.length > 0, true); expect(data.length).toBeGreaterThan(0);
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('autocompleteUsersInChannel', function(done) { test('autocompleteUsersInChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().autocompleteUsersInChannel( TestHelper.basicClient().autocompleteUsersInChannel(
'uid', 'uid',
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
function(data) { function(data) {
assert.equal(data != null, true); expect(data).not.toBeNull();
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('autocompleteUsersInTeam', function(done) { test('autocompleteUsersInTeam', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().autocompleteUsersInTeam( TestHelper.basicClient().autocompleteUsersInTeam(
'uid', 'uid',
function(data) { function(data) {
assert.equal(data != null, true); expect(data).not.toBeNull();
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('autocompleteUsers', function(done) { test('autocompleteUsers', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().autocompleteUsers( TestHelper.basicClient().autocompleteUsers(
'uid', 'uid',
function(data) { function(data) {
assert.equal(data != null, true); expect(data).not.toBeNull();
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('getStatusesByIds', function(done) { test('getStatusesByIds', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var ids = []; var ids = [];
ids.push(TestHelper.basicUser().id); ids.push(TestHelper.basicUser().id);
TestHelper.basicClient().getStatusesByIds( TestHelper.basicClient().getStatusesByIds(
ids, ids,
function(data) { function(data) {
assert.equal(data[TestHelper.basicUser().id] != null, true); expect(data[TestHelper.basicUser().id]).not.toBeNull();
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('setActiveChannel', function(done) { test('setActiveChannel', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
var ids = []; var ids = [];
ids.push(TestHelper.basicUser().id); ids.push(TestHelper.basicUser().id);
@@ -663,31 +662,31 @@ describe('Client.User', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('verifyEmail', function(done) { test('verifyEmail', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().verifyEmail( TestHelper.basicClient().verifyEmail(
'junk', 'junk',
'junk', 'junk',
function() { function() {
done(new Error('should be invalid')); done.fail(new Error('should be invalid'));
}, },
function(err) { function(err) {
assert.equal(err.id, 'api.context.invalid_param.app_error'); expect(err.id).toBe('api.context.invalid_param.app_error');
done(); done();
} }
); );
}); });
}); });
it('resendVerification', function(done) { test('resendVerification', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().resendVerification( TestHelper.basicClient().resendVerification(
TestHelper.basicUser().email, TestHelper.basicUser().email,
@@ -695,20 +694,20 @@ describe('Client.User', function() {
done(); done();
}, },
function(err) { function(err) {
done(new Error(err.message)); done.fail(new Error(err.message));
} }
); );
}); });
}); });
it('updateMfa', function(done) { test('updateMfa', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
TestHelper.basicClient().updateMfa( TestHelper.basicClient().updateMfa(
'junk', 'junk',
true, true,
function() { function() {
done(new Error('not enabled')); done.fail(new Error('not enabled'));
}, },
function() { function() {
done(); done();

Просмотреть файл

@@ -1,49 +1,46 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
/*
var assert = require('assert');
import TestHelper from './test_helper.jsx';
describe('Client.WebSocket', function() { import TestHelper from 'tests/helpers/client-test-helper.jsx';
this.timeout(10000);
it('WebSocket.getStatusesByIds', function(done) { describe.skip('Client.WebSocket', function() {
TestHelper.initBasic(() => { test('WebSocket.getStatusesByIds', function(done) {
TestHelper.initBasic(done, () => {
TestHelper.basicWebSocketClient().getStatusesByIds( TestHelper.basicWebSocketClient().getStatusesByIds(
[TestHelper.basicUser().id], [TestHelper.basicUser().id],
function(resp) { function(resp) {
TestHelper.basicWebSocketClient().close(); TestHelper.basicWebSocketClient().close();
assert.equal(resp.data[TestHelper.basicUser().id], 'online'); expect(resp.data[TestHelper.basicUser().id]).toBe('online');
done(); done();
} }
); );
}, true); }, true);
}); });
it('WebSocket.getStatuses', function(done) { test('WebSocket.getStatuses', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicWebSocketClient().getStatuses( TestHelper.basicWebSocketClient().getStatuses(
function(resp) { function(resp) {
TestHelper.basicWebSocketClient().close(); TestHelper.basicWebSocketClient().close();
assert.equal(resp.data != null, true); expect(resp.data).not.toBe(null);
done(); done();
} }
); );
}, true); }, true);
}); });
it('WebSocket.userTyping', function(done) { test('WebSocket.userTyping', function(done) {
TestHelper.initBasic(() => { TestHelper.initBasic(done, () => {
TestHelper.basicWebSocketClient().userTyping( TestHelper.basicWebSocketClient().userTyping(
TestHelper.basicChannel().id, TestHelper.basicChannel().id,
'', '',
function(resp) { function(resp) {
TestHelper.basicWebSocketClient().close(); TestHelper.basicWebSocketClient().close();
assert.equal(resp.status, 'OK'); expect(resp.status).toBe('OK');
done(); done();
} }
); );
}, true); }, true);
}); });
});*/ });

Просмотреть файл

@@ -0,0 +1,334 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/AboutBuildModal should match snapshot for enterprise edition 1`] = `
<Modal
animation={true}
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="about-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"modals": Array [],
}
}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
show={true}
>
<ModalHeader
aria-label="Close"
bsClass="modal-header"
closeButton={true}
>
<ModalTitle
bsClass="modal-title"
componentClass="h4"
>
<FormattedMessage
defaultMessage="About Mattermost"
id="about.title"
values={Object {}}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<div
className="about-modal__content"
>
<div
className="about-modal__logo"
>
<span
className="icon"
dangerouslySetInnerHTML={
Object {
"__html": "<svg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px'viewBox='0 0 500 500' style='enable-background:new 0 0 500 500;' xml:space='preserve'> <style type='text/css'> .st0{fill-rule:evenodd;clip-rule:evenodd;fill:#222222;} </style> <g id='XMLID_1_'> <g id='XMLID_3_'> <path id='XMLID_4_' class='st0' d='M396.9,47.7l2.6,53.1c43,47.5,60,114.8,38.6,178.1c-32,94.4-137.4,144.1-235.4,110.9 S51.1,253.1,83,158.7C104.5,95.2,159.2,52,222.5,40.5l34.2-40.4C150-2.8,49.3,63.4,13.3,169.9C-31,300.6,39.1,442.5,169.9,486.7 s272.6-25.8,316.9-156.6C522.7,223.9,483.1,110.3,396.9,47.7z'/> </g> <path id='XMLID_2_' class='st0' d='M335.6,204.3l-1.8-74.2l-1.5-42.7l-1-37c0,0,0.2-17.8-0.4-22c-0.1-0.9-0.4-1.6-0.7-2.2 c0-0.1-0.1-0.2-0.1-0.3c0-0.1-0.1-0.2-0.1-0.2c-0.7-1.2-1.8-2.1-3.1-2.6c-1.4-0.5-2.9-0.4-4.2,0.2c0,0-0.1,0-0.1,0 c-0.2,0.1-0.3,0.1-0.4,0.2c-0.6,0.3-1.2,0.7-1.8,1.3c-3,3-13.7,17.2-13.7,17.2l-23.2,28.8l-27.1,33l-46.5,57.8 c0,0-21.3,26.6-16.6,59.4s29.1,48.7,48,55.1c18.9,6.4,48,8.5,71.6-14.7C336.4,238.4,335.6,204.3,335.6,204.3z'/> </g> </svg>",
}
}
/>
</div>
<div>
<h3
className="about-modal__title"
>
Mattermost
<FormattedMessage
defaultMessage="Enterprise Edition"
id="about.teamEditiont1"
values={Object {}}
/>
</h3>
<p
className="about-modal__subtitle padding-bottom"
>
<FormattedMessage
defaultMessage="Modern communication from behind your firewall."
id="about.enterpriseEditionSt"
values={Object {}}
/>
</p>
<div
className="form-group less"
>
<div>
<FormattedMessage
defaultMessage="Version:"
id="about.version"
values={Object {}}
/>
<span
id="versionString"
>
 3.6.0  (3.6.2)
</span>
</div>
<div>
<FormattedMessage
defaultMessage="Database:"
id="about.database"
values={Object {}}
/>
 Postgres
</div>
</div>
</div>
</div>
<div
className="about-modal__footer"
>
<div>
<FormattedMessage
defaultMessage="Learn more about Enterprise Edition at "
id="about.enterpriseEditionLearn"
values={Object {}}
/>
<a
href="http://about.mattermost.com/"
rel="noopener noreferrer"
target="_blank"
>
about.mattermost.com
</a>
</div>
<div
className="form-group about-modal__copyright"
>
<FormattedMessage
defaultMessage="Copyright 2016 Mattermost, Inc. All rights reserved"
id="about.copyright"
values={Object {}}
/>
</div>
</div>
<div
className="about-modal__hash form-group padding-top x2"
>
<p>
<FormattedMessage
defaultMessage="Build Hash:"
id="about.hash"
values={Object {}}
/>
 
abcdef1234567890
<br />
<FormattedMessage
defaultMessage="EE Build Hash:"
id="about.hashee"
values={Object {}}
/>
 
0123456789abcdef
</p>
<p>
<FormattedMessage
defaultMessage="Build Date:"
id="about.date"
values={Object {}}
/>
 
21 January 2017
</p>
</div>
</ModalBody>
</Modal>
`;
exports[`components/AboutBuildModal should match snapshot for team edition 1`] = `
<Modal
animation={true}
autoFocus={true}
backdrop={true}
bsClass="modal"
dialogClassName="about-modal"
dialogComponentClass={[Function]}
enforceFocus={true}
keyboard={true}
manager={
ModalManager {
"containers": Array [],
"data": Array [],
"handleContainerOverflow": true,
"hideSiblingNodes": true,
"modals": Array [],
}
}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
show={true}
>
<ModalHeader
aria-label="Close"
bsClass="modal-header"
closeButton={true}
>
<ModalTitle
bsClass="modal-title"
componentClass="h4"
>
<FormattedMessage
defaultMessage="About Mattermost"
id="about.title"
values={Object {}}
/>
</ModalTitle>
</ModalHeader>
<ModalBody
bsClass="modal-body"
componentClass="div"
>
<div
className="about-modal__content"
>
<div
className="about-modal__logo"
>
<span
className="icon"
dangerouslySetInnerHTML={
Object {
"__html": "<svg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px'viewBox='0 0 500 500' style='enable-background:new 0 0 500 500;' xml:space='preserve'> <style type='text/css'> .st0{fill-rule:evenodd;clip-rule:evenodd;fill:#222222;} </style> <g id='XMLID_1_'> <g id='XMLID_3_'> <path id='XMLID_4_' class='st0' d='M396.9,47.7l2.6,53.1c43,47.5,60,114.8,38.6,178.1c-32,94.4-137.4,144.1-235.4,110.9 S51.1,253.1,83,158.7C104.5,95.2,159.2,52,222.5,40.5l34.2-40.4C150-2.8,49.3,63.4,13.3,169.9C-31,300.6,39.1,442.5,169.9,486.7 s272.6-25.8,316.9-156.6C522.7,223.9,483.1,110.3,396.9,47.7z'/> </g> <path id='XMLID_2_' class='st0' d='M335.6,204.3l-1.8-74.2l-1.5-42.7l-1-37c0,0,0.2-17.8-0.4-22c-0.1-0.9-0.4-1.6-0.7-2.2 c0-0.1-0.1-0.2-0.1-0.3c0-0.1-0.1-0.2-0.1-0.2c-0.7-1.2-1.8-2.1-3.1-2.6c-1.4-0.5-2.9-0.4-4.2,0.2c0,0-0.1,0-0.1,0 c-0.2,0.1-0.3,0.1-0.4,0.2c-0.6,0.3-1.2,0.7-1.8,1.3c-3,3-13.7,17.2-13.7,17.2l-23.2,28.8l-27.1,33l-46.5,57.8 c0,0-21.3,26.6-16.6,59.4s29.1,48.7,48,55.1c18.9,6.4,48,8.5,71.6-14.7C336.4,238.4,335.6,204.3,335.6,204.3z'/> </g> </svg>",
}
}
/>
</div>
<div>
<h3
className="about-modal__title"
>
Mattermost
<FormattedMessage
defaultMessage="Team Edition"
id="about.teamEditiont0"
values={Object {}}
/>
</h3>
<p
className="about-modal__subtitle padding-bottom"
>
<FormattedMessage
defaultMessage="All your team communication in one place, instantly searchable and accessible anywhere."
id="about.teamEditionSt"
values={Object {}}
/>
</p>
<div
className="form-group less"
>
<div>
<FormattedMessage
defaultMessage="Version:"
id="about.version"
values={Object {}}
/>
<span
id="versionString"
>
 3.6.0  (3.6.2)
</span>
</div>
<div>
<FormattedMessage
defaultMessage="Database:"
id="about.database"
values={Object {}}
/>
 Postgres
</div>
</div>
</div>
</div>
<div
className="about-modal__footer"
>
<div>
<FormattedMessage
defaultMessage="Join the Mattermost community at "
id="about.teamEditionLearn"
values={Object {}}
/>
<a
href="http://www.mattermost.org/"
rel="noopener noreferrer"
target="_blank"
>
mattermost.org
</a>
</div>
<div
className="form-group about-modal__copyright"
>
<FormattedMessage
defaultMessage="Copyright 2016 Mattermost, Inc. All rights reserved"
id="about.copyright"
values={Object {}}
/>
</div>
</div>
<div
className="about-modal__hash form-group padding-top x2"
>
<p>
<FormattedMessage
defaultMessage="Build Hash:"
id="about.hash"
values={Object {}}
/>
 
abcdef1234567890
<br />
<FormattedMessage
defaultMessage="EE Build Hash:"
id="about.hashee"
values={Object {}}
/>
 
</p>
<p>
<FormattedMessage
defaultMessage="Build Date:"
id="about.date"
values={Object {}}
/>
 
21 January 2017
</p>
</div>
</ModalBody>
</Modal>
`;

Просмотреть файл

@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/SpinnerButton should match snapshot with children 1`] = `
<button
className="btn btn-primary"
>
<span
id="child1"
/>
<span
id="child2"
/>
</button>
`;
exports[`components/SpinnerButton should match snapshot with required props 1`] = `
<button
className="btn btn-primary"
/>
`;
exports[`components/SpinnerButton should match snapshot with spinning 1`] = `
<img
className="spinner-button__gif"
src={Object {}}
/>
`;

Просмотреть файл

@@ -0,0 +1,129 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx';
import AboutBuildModal from 'components/about_build_modal.jsx';
import {Modal} from 'react-bootstrap';
describe('components/AboutBuildModal', () => {
afterEach(() => {
global.window.mm_config = null;
global.window.mm_license = null;
});
test('should match snapshot for enterprise edition', () => {
global.window.mm_config = {
BuildEnterpriseReady: 'true',
Version: '3.6.0',
BuildNumber: '3.6.2',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildHashEnterprise: '0123456789abcdef',
BuildDate: '21 January 2017'
};
global.window.mm_license = {
isLicensed: 'true',
Company: 'Mattermost Inc'
};
const wrapper = shallow(
<AboutBuildModal
show={true}
onModalDismissed={null}
/>
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot for team edition', () => {
global.window.mm_config = {
BuildEnterpriseReady: 'false',
Version: '3.6.0',
BuildNumber: '3.6.2',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildDate: '21 January 2017'
};
global.window.mm_license = null;
const wrapper = shallow(
<AboutBuildModal
show={true}
onModalDismissed={null}
/>
);
expect(wrapper).toMatchSnapshot();
});
test('should hide the build number if it is the same as the version number', () => {
global.window.mm_config = {
BuildEnterpriseReady: 'false',
Version: '3.6.0',
BuildNumber: '3.6.0',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildDate: '21 January 2017'
};
global.window.mm_license = null;
const wrapper = shallow(
<AboutBuildModal
show={true}
onModalDismissed={null}
/>
);
expect(wrapper.find('#versionString').text()).toBe(' 3.6.0');
});
test('should show the build number if it is the different from the version number', () => {
global.window.mm_config = {
BuildEnterpriseReady: 'false',
Version: '3.6.0',
BuildNumber: '3.6.2',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildDate: '21 January 2017'
};
global.window.mm_license = null;
const wrapper = shallow(
<AboutBuildModal
show={true}
onModalDismissed={null}
/>
);
expect(wrapper.find('#versionString').text()).toBe(' 3.6.0\u00a0 (3.6.2)');
});
test('should call onModalDismissed callback when the modal is hidden', (done) => {
global.window.mm_config = {
BuildEnterpriseReady: 'false',
Version: '3.6.0',
BuildNumber: '3.6.2',
SQLDriverName: 'Postgres',
BuildHash: 'abcdef1234567890',
BuildDate: '21 January 2017'
};
global.window.mm_license = null;
function onHide() {
done();
}
const wrapper = mountWithIntl(
<AboutBuildModal
show={true}
onModalDismissed={onHide}
/>
);
wrapper.find(Modal).first().props().onHide();
});
});

Просмотреть файл

@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/backstage/components/BackstageHeader should match snapshot with children 1`] = `
<div
className="backstage-header"
>
<h1>
<div>
Child 1
</div>
<span
className="backstage-header__divider"
>
<i
className="fa fa-angle-right"
/>
</span>
<div>
Child 2
</div>
</h1>
</div>
`;
exports[`components/backstage/components/BackstageHeader should match snapshot without children 1`] = `
<div
className="backstage-header"
>
<h1 />
</div>
`;

Просмотреть файл

@@ -0,0 +1,26 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import BackstageHeader from 'components/backstage/components/backstage_header.jsx';
describe('components/backstage/components/BackstageHeader', () => {
test('should match snapshot without children', () => {
const wrapper = shallow(
<BackstageHeader/>
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot with children', () => {
const wrapper = shallow(
<BackstageHeader>
<div>{'Child 1'}</div>
<div>{'Child 2'}</div>
</BackstageHeader>
);
expect(wrapper).toMatchSnapshot();
});
});

Просмотреть файл

@@ -0,0 +1,53 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import {shallow, mount} from 'enzyme';
import SpinnerButton from 'components/spinner_button.jsx';
describe('components/SpinnerButton', () => {
test('should match snapshot with required props', () => {
const wrapper = shallow(
<SpinnerButton
spinning={false}
/>
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot with spinning', () => {
const wrapper = shallow(
<SpinnerButton
spinning={true}
/>
);
expect(wrapper).toMatchSnapshot();
});
test('should match snapshot with children', () => {
const wrapper = shallow(
<SpinnerButton
spinning={false}
>
<span id='child1'/>
<span id='child2'/>
</SpinnerButton>
);
expect(wrapper).toMatchSnapshot();
});
test('should handle onClick', (done) => {
function onClick() {
done();
}
const wrapper = mount(
<SpinnerButton
spinning={false}
onClick={onClick}
/>
);
wrapper.find('button').first().props().onClick();
});
});

Просмотреть файл

@@ -0,0 +1,16 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import SuggestionBox from 'components/suggestion/suggestion_box.jsx';
describe('components/SuggestionBox', function() {
test('findOverlap', () => {
expect(SuggestionBox.findOverlap('', 'blue')).toBe('');
expect(SuggestionBox.findOverlap('red', '')).toBe('');
expect(SuggestionBox.findOverlap('red', 'blue')).toBe('');
expect(SuggestionBox.findOverlap('red', 'dog')).toBe('d');
expect(SuggestionBox.findOverlap('red', 'education')).toBe('ed');
expect(SuggestionBox.findOverlap('red', 'reduce')).toBe('red');
expect(SuggestionBox.findOverlap('black', 'ack')).toBe('ack');
});
});

Просмотреть файл

@@ -1,47 +0,0 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import assert from 'assert';
import EmojiStore from 'stores/emoji_store.jsx';
import * as Emoticons from 'utils/emoticons.jsx';
describe('Emoticons', function() {
this.timeout(100000);
it('handleEmoticons', function(done) {
const emojis = EmojiStore.getEmojis();
assert.equal(
Emoticons.handleEmoticons(':goat: :dash:', new Map(), emojis),
'$MM_EMOTICON0 $MM_EMOTICON1',
'should replace emoticons with tokens'
);
assert.equal(
Emoticons.handleEmoticons(':goat::dash:', new Map(), emojis),
'$MM_EMOTICON0$MM_EMOTICON1',
'should replace emoticons not separated by whitespace'
);
assert.equal(
Emoticons.handleEmoticons('/:goat:..:dash:)', new Map(), emojis),
'/$MM_EMOTICON0..$MM_EMOTICON1)',
'should replace emoticons separated by punctuation'
);
assert.equal(
Emoticons.handleEmoticons('asdf:goat:asdf:dash:asdf', new Map(), emojis),
'asdf$MM_EMOTICON0asdf$MM_EMOTICON1asdf',
'should replace emoticons separated by text'
);
assert.equal(
Emoticons.handleEmoticons(':asdf: :goat : : dash:', new Map(), emojis),
':asdf: :goat : : dash:',
'shouldn\'t replace invalid emoticons'
);
done();
});
});

Просмотреть файл

@@ -103,11 +103,11 @@ class TestHelperClass {
return post; return post;
} }
initBasic = (callback, connectWS) => { initBasic = (done, callback, connectWS) => {
this.basicc = this.createClient(); this.basicc = this.createClient();
function throwerror(err) { function throwerror(err) {
throw err; done.fail(new Error(err.message));
} }
var d1 = jqd.Deferred(); var d1 = jqd.Deferred();

22
webapp/tests/helpers/intl-test-helper.jsx Обычный файл
Просмотреть файл

@@ -0,0 +1,22 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {mount, shallow} from 'enzyme';
import React from 'react';
import {IntlProvider, intlShape} from 'react-intl';
const intlProvider = new IntlProvider({locale: 'en'}, {});
const {intl} = intlProvider.getChildContext();
export function shallowWithIntl(node, {context} = {}) {
return shallow(React.cloneElement(node, {intl}), {
context: Object.assign({}, context, {intl})
});
}
export function mountWithIntl(node, {context, childContextTypes} = {}) {
return mount(React.cloneElement(node, {intl}), {
context: Object.assign({}, context, {intl}),
childContextTypes: Object.assign({}, {intl: intlShape}, childContextTypes)
});
}

Просмотреть файл

@@ -1,19 +0,0 @@
var jsdom = require('mocha-jsdom');
var assert = require('assert');
import TestUtils from 'react-addons-test-utils';
import SpinnerButton from '../components/spinner_button.jsx';
import React from 'react';
describe('SpinnerButton', function() {
this.timeout(10000);
jsdom();
it('check props', function() {
const spinner = TestUtils.renderIntoDocument(
<SpinnerButton spinning={false}/>
);
assert.equal(spinner.props.spinning, false, 'should start in the default false state');
});
});

Просмотреть файл

@@ -1,20 +0,0 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import assert from 'assert';
import SuggestionBox from 'components/suggestion/suggestion_box.jsx';
describe('SuggestionBox', function() {
it('findOverlap', function(done) {
assert.equal(SuggestionBox.findOverlap('', 'blue'), '');
assert.equal(SuggestionBox.findOverlap('red', ''), '');
assert.equal(SuggestionBox.findOverlap('red', 'blue'), '');
assert.equal(SuggestionBox.findOverlap('red', 'dog'), 'd');
assert.equal(SuggestionBox.findOverlap('red', 'education'), 'ed');
assert.equal(SuggestionBox.findOverlap('red', 'reduce'), 'red');
assert.equal(SuggestionBox.findOverlap('black', 'ack'), 'ack');
done();
});
});

36
webapp/tests/utils/emoticons.test.jsx Обычный файл
Просмотреть файл

@@ -0,0 +1,36 @@
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import EmojiStore from 'stores/emoji_store.jsx';
import * as Emoticons from 'utils/emoticons.jsx';
describe('Emoticons', () => {
describe('handleEmoticons', () => {
const emojis = EmojiStore.getEmojis();
test('should replace emoticons with tokens', () => {
expect(Emoticons.handleEmoticons(':goat: :dash:', new Map(), emojis)).
toEqual('$MM_EMOTICON0 $MM_EMOTICON1');
});
test('should replace emoticons not separated by whitespace', () => {
expect(Emoticons.handleEmoticons(':goat::dash:', new Map(), emojis)).
toEqual('$MM_EMOTICON0$MM_EMOTICON1');
});
test('should replace emoticons separated by punctuation', () => {
expect(Emoticons.handleEmoticons('/:goat:..:dash:)', new Map(), emojis)).
toEqual('/$MM_EMOTICON0..$MM_EMOTICON1)');
});
test('should replace emoticons separated by text', () => {
expect(Emoticons.handleEmoticons('asdf:goat:asdf:dash:asdf', new Map(), emojis)).
toEqual('asdf$MM_EMOTICON0asdf$MM_EMOTICON1asdf');
});
test('shouldn\'t replace invalid emoticons', () => {
expect(Emoticons.handleEmoticons(':asdf: :goat : : dash:', new Map(), emojis)).
toEqual(':asdf: :goat : : dash:');
});
});
});

Просмотреть файл

@@ -6,8 +6,6 @@ import assert from 'assert';
import * as TextFormatting from 'utils/text_formatting.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx';
describe('TextFormatting.AtMentions', function() { describe('TextFormatting.AtMentions', function() {
this.timeout(10000);
it('At mentions', function() { it('At mentions', function() {
assert.equal( assert.equal(
TextFormatting.autolinkAtMentions('@user', new Map(), {user: {}}), TextFormatting.autolinkAtMentions('@user', new Map(), {user: {}}),

Просмотреть файл

@@ -6,8 +6,6 @@ import assert from 'assert';
import * as TextFormatting from 'utils/text_formatting.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx';
describe('TextFormatting.Hashtags', function() { describe('TextFormatting.Hashtags', function() {
this.timeout(10000);
it('Not hashtags', function(done) { it('Not hashtags', function(done) {
assert.equal( assert.equal(
TextFormatting.formatText('# hashtag').trim(), TextFormatting.formatText('# hashtag').trim(),

Просмотреть файл

@@ -6,8 +6,6 @@ import assert from 'assert';
import * as Markdown from 'utils/markdown.jsx'; import * as Markdown from 'utils/markdown.jsx';
describe('Markdown.Imgs', function() { describe('Markdown.Imgs', function() {
this.timeout(10000);
it('Inline mage', function(done) { it('Inline mage', function(done) {
assert.equal( assert.equal(
Markdown.format('![Mattermost](/images/icon.png)').trim(), Markdown.format('![Mattermost](/images/icon.png)').trim(),

Просмотреть файл

@@ -7,8 +7,6 @@ import * as Markdown from 'utils/markdown.jsx';
import * as TextFormatting from 'utils/text_formatting.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx';
describe('Markdown.Links', function() { describe('Markdown.Links', function() {
this.timeout(10000);
it('Not links', function(done) { it('Not links', function(done) {
assert.equal( assert.equal(
Markdown.format('example.com').trim(), Markdown.format('example.com').trim(),

Просмотреть файл

@@ -1,9 +1,7 @@
import assert from 'assert';
import * as CommonUtils from 'utils/commons.jsx'; import * as CommonUtils from 'utils/commons.jsx';
describe('CommonUtils.getNearestPoint', function() { describe('CommonUtils.getNearestPoint', function() {
this.timeout(10000); test('should return nearest point', function() {
it('should return nearest point', function() {
for (const data of [ for (const data of [
{ {
points: [{x: 30, y: 40}, {x: 50, y: 50}, {x: 100, y: 2}, {x: 500, y: 200}, {x: 110, y: 20}, {x: 10, y: 20}], points: [{x: 30, y: 40}, {x: 50, y: 50}, {x: 100, y: 2}, {x: 500, y: 200}, {x: 110, y: 20}, {x: 10, y: 20}],
@@ -26,8 +24,8 @@ describe('CommonUtils.getNearestPoint', function() {
]) { ]) {
const nearestPoint = CommonUtils.getNearestPoint(data.pivotPoint, data.points); const nearestPoint = CommonUtils.getNearestPoint(data.pivotPoint, data.points);
assert.equal(nearestPoint.x, data.nearestPoint.x); expect(nearestPoint.x).toEqual(data.nearestPoint.x);
assert.equal(nearestPoint.y, data.nearestPoint.y); expect(nearestPoint.y).toEqual(data.nearestPoint.y);
} }
}); });
}); });