From 950439bf4776168e7e075c7b944efa7323dfa7e6 Mon Sep 17 00:00:00 2001 From: Guillermo Giuliana Date: Mon, 13 Dec 2021 09:57:20 -0300 Subject: [PATCH] add last files (#1110) --- .../src/app-components/article-add-modal.js | 14 +- client/src/app-components/topic-edit-modal.js | 15 +- .../articles/admin-panel-view-article.js | 13 +- client/src/data/languages/en.js | 2 + server/controllers/article/add-topic.php | 28 +++- server/controllers/article/add.php | 18 ++- server/controllers/article/edit-topic.php | 28 ++-- server/controllers/article/edit.php | 42 +++-- server/controllers/system/edit-department.php | 11 +- server/data/ERRORS.php | 12 +- .../libs/validations/validArticleContent.php | 13 ++ server/libs/validations/validArticleName.php | 13 ++ server/libs/validations/validTopicName.php | 13 ++ tests/article/article.rb | 147 +++++++++++++++--- tests/article/topic.rb | 54 +++++++ tests/scripts.rb | 5 +- tests/system/edit-department.rb | 30 +++- 17 files changed, 383 insertions(+), 75 deletions(-) create mode 100644 server/libs/validations/validArticleContent.php create mode 100644 server/libs/validations/validArticleName.php create mode 100644 server/libs/validations/validTopicName.php diff --git a/client/src/app-components/article-add-modal.js b/client/src/app-components/article-add-modal.js index 36a160e2..2ffe368e 100644 --- a/client/src/app-components/article-add-modal.js +++ b/client/src/app-components/article-add-modal.js @@ -12,6 +12,7 @@ import FormField from 'core-components/form-field'; import SubmitButton from 'core-components/submit-button'; import Button from 'core-components/button'; import TextEditor from 'core-components/text-editor'; +import Message from 'core-components/message'; class ArticleAddModal extends React.Component { static propTypes = { @@ -22,7 +23,8 @@ class ArticleAddModal extends React.Component { }; state = { - loading: false + loading: false, + errorMessage: false }; render() { @@ -31,6 +33,7 @@ class ArticleAddModal extends React.Component {
+ {this.state.errorMessage ? {i18n(this.state.errorMessage)} : null} {i18n('SAVE')} + {this.state.errorMessage ? {i18n(this.state.errorMessage)} : null} @@ -139,7 +143,12 @@ class AdminPanelViewArticle extends React.Component { }).then(() => { this.props.dispatch(ArticlesActions.retrieveArticles()); this.setState({ - editable: false + editable: false, + errorMessage: false + }) + }).catch((e) => { + this.setState({ + errorMessage: e.message }); }); } diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index cc7e7c8b..5f338e78 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -410,6 +410,8 @@ export default { 'INVALID_SUPERVISED_USERS': 'Invalid supervised users', 'SUPERVISOR_CAN_NOT_SUPERVISE_HIMSELF': 'Supervisor can not supervise himself', 'NAME_ALREADY_USED': 'Name already used', + 'CONTENT_ALREADY_USED': 'Content already used', + 'TITLE_ALREADY_USED': 'Title already used', //MESSAGES 'SIGNUP_SUCCESS': 'You have registered successfully in our support system.', diff --git a/server/controllers/article/add-topic.php b/server/controllers/article/add-topic.php index c0446d32..3e8b30ae 100755 --- a/server/controllers/article/add-topic.php +++ b/server/controllers/article/add-topic.php @@ -19,9 +19,10 @@ DataValidator::with('CustomValidations', true); * @apiParam {String} iconColor Icon's color of the new topic. * @apiParam {Boolean} private Indicates if the topic is not shown to users. * - * @apiUse NO_PERMISSION - * @apiUse INVALID_NAME - * + * @apiUse NO_PERMISSION + * @apiUse INVALID_TITLE + * @apiUse NAME_ALREADY_USED + * * @apiSuccess {Object} data Topic info * @apiSuccess {Number} data.topicId Topic id * @@ -37,19 +38,30 @@ class AddTopicController extends Controller { 'requestData' => [ 'name' => [ 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), - 'error' => ERRORS::INVALID_NAME + 'error' => ERRORS::INVALID_TITLE ], ] ]; } public function handler() { + + $name = Controller::request('name', true); + $icon = Controller::request('icon'); + $iconColor = Controller::request('iconColor'); + $private = Controller::request('private') ? 1 : 0; + $CreatedTopic = Topic::getDataStore($name, 'name'); + + if(!$CreatedTopic->isNull()){ + throw new RequestException(ERRORS::NAME_ALREADY_USED); + } + $topic = new Topic(); $topic->setProperties([ - 'name' => Controller::request('name', true), - 'icon' => Controller::request('icon'), - 'iconColor' => Controller::request('iconColor'), - 'private' => Controller::request('private') ? 1 : 0 + 'name' => $name, + 'icon' => $icon, + 'iconColor' => $iconColor, + 'private' => $private ]); Log::createLog('ADD_TOPIC', $topic->name); diff --git a/server/controllers/article/add.php b/server/controllers/article/add.php index c0433c6e..31fad345 100755 --- a/server/controllers/article/add.php +++ b/server/controllers/article/add.php @@ -25,6 +25,8 @@ DataValidator::with('CustomValidations', true); * @apiUse INVALID_TITLE * @apiUse INVALID_CONTENT * @apiUse INVALID_TOPIC + * @apiUse TITLE_ALREADY_USED + * @apiUse CONTENT_ALREADY_USED * * @apiSuccess {Object} data Article info * @apiSuccess {Number} data.articleId Article id @@ -39,7 +41,7 @@ class AddArticleController extends Controller { 'permission' => 'staff_2', 'requestData' => [ 'title' => [ - 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TITLE, LengthConfig::MAX_LENGTH_TITLE), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_TITLE ], 'content' => [ @@ -56,14 +58,26 @@ class AddArticleController extends Controller { public function handler() { $content = Controller::request('content', true); + $title = Controller::request('title', true); + $createdArticleTookByTitle = Article::getDataStore($title,'title'); + $createdArticleTookByContent = Article::getDataStore($content,'content'); + if(!$createdArticleTookByTitle->isNull()){ + throw new RequestException(ERRORS::TITLE_ALREADY_USED); + } + + if(!$createdArticleTookByContent->isNull()){ + throw new RequestException(ERRORS::CONTENT_ALREADY_USED); + } + + $fileUploader = FileUploader::getInstance(); $fileUploader->setPermission(FileManager::PERMISSION_ARTICLE); $imagePaths = $this->uploadImages(true); $article = new Article(); $article->setProperties([ - 'title' => Controller::request('title', true), + 'title' => $title, 'content' => $this->replaceWithImagePaths($imagePaths, $content), 'lastEdited' => Date::getCurrentDate(), 'position' => Controller::request('position') || 1 diff --git a/server/controllers/article/edit-topic.php b/server/controllers/article/edit-topic.php index 9090ecc9..cc61d653 100755 --- a/server/controllers/article/edit-topic.php +++ b/server/controllers/article/edit-topic.php @@ -22,7 +22,8 @@ DataValidator::with('CustomValidations', true); * * @apiUse NO_PERMISSION * @apiUse INVALID_TOPIC - * @apiUse INVALID_NAME + * @apiUse INVALID_TITLE + * @apiUse NAME_ALREADY_USED * * @apiSuccess {Object} data Empty object * @@ -42,7 +43,7 @@ class EditTopicController extends Controller { ], 'name' => [ 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), - 'error' => ERRORS::INVALID_NAME + 'error' => ERRORS::INVALID_TITLE ] ] ]; @@ -50,20 +51,29 @@ class EditTopicController extends Controller { public function handler() { $topic = Topic::getDataStore(Controller::request('topicId')); + $name = Controller::request('name'); + $iconColor = Controller::request('iconColor'); + $private = Controller::request('private'); + $icon = Controller::request('icon'); + $createdArticleTookByName = Topic::getDataStore($name, 'name'); - if(Controller::request('name')) { + if(!$createdArticleTookByName->isNull() && $topic->id !== $createdArticleTookByName->id){ + throw new RequestException(ERRORS::NAME_ALREADY_USED); + } + + if($name) { $topic->name = Controller::request('name', true); } - if(Controller::request('iconColor')) { - $topic->iconColor = Controller::request('iconColor'); + if($iconColor) { + $topic->iconColor = $iconColor; } - if(Controller::request('icon')) { - $topic->icon = Controller::request('icon'); + if($icon) { + $topic->icon = $icon; } - if (Controller::request('private') !== null) { - $topic->private = Controller::request('private'); + if ($private !== null) { + $topic->private = $private; } $topic->store(); diff --git a/server/controllers/article/edit.php b/server/controllers/article/edit.php index cc46458a..a2b8fe60 100755 --- a/server/controllers/article/edit.php +++ b/server/controllers/article/edit.php @@ -26,7 +26,9 @@ DataValidator::with('CustomValidations', true); * @apiUse INVALID_TOPIC * @apiUse INVALID_FILE * @apiUse INVALID_TITLE - * + * @apiUse CONTENT_ALREADY_USED + * @apiUse TITLE_ALREADY_USED + * * @apiSuccess {Object} data Empty object * */ @@ -44,14 +46,17 @@ class EditArticleController extends Controller { 'error' => ERRORS::INVALID_TOPIC ], 'title' => [ - 'validation' => DataValidator::oneOf( - DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TITLE, LengthConfig::MAX_LENGTH_TITLE), - DataValidator::nullType() - ), + 'validation' => DataValidator::OneOf( + DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), + DataValidator::nullType() + ), 'error' => ERRORS::INVALID_TITLE ], 'content' => [ - 'validation' => DataValidator::oneOf(DataValidator::content(),DataValidator::nullType()), + 'validation' => DataValidator::oneOf( + DataValidator::content(), + DataValidator::nullType() + ), 'error' => ERRORS::INVALID_CONTENT ] ] @@ -59,10 +64,24 @@ class EditArticleController extends Controller { } public function handler() { + $topicId = Controller::request('topicId'); + $content = Controller::request('content', true); + $title = Controller::request('title'); + $article = Article::getDataStore(Controller::request('articleId')); + $createdArticleTookByTitle = Article::getDataStore($title, 'title'); + $createdArticleTookByContent = Article::getDataStore($content, 'content'); - if (Controller::request('topicId')) { - $newArticleTopic = Topic::getDataStore(Controller::request('topicId')); + if(!$createdArticleTookByTitle->isNull() && $article->title !== $createdArticleTookByTitle->title){ + throw new RequestException(ERRORS::TITLE_ALREADY_USED); + } + + if(!$createdArticleTookByContent->isNull() && $article->content !== $createdArticleTookByContent->content){ + throw new RequestException(ERRORS::CONTENT_ALREADY_USED); + } + + if ($topicId) { + $newArticleTopic = Topic::getDataStore($topicId); if (!$newArticleTopic->isNull()) { $article->topic = $newArticleTopic; @@ -72,18 +91,17 @@ class EditArticleController extends Controller { } } - if(Controller::request('content')) { + if($content) { $fileUploader = FileUploader::getInstance(); $fileUploader->setPermission(FileManager::PERMISSION_ARTICLE); - $content = Controller::request('content', true); $imagePaths = $this->uploadImages(true); $article->content = $this->replaceWithImagePaths($imagePaths, $content); } - if(Controller::request('title')) { - $article->title = Controller::request('title'); + if($title) { + $article->title = $title; } if(Controller::request('position')) { diff --git a/server/controllers/system/edit-department.php b/server/controllers/system/edit-department.php index 7d96e81a..3b2279e4 100755 --- a/server/controllers/system/edit-department.php +++ b/server/controllers/system/edit-department.php @@ -21,6 +21,7 @@ DataValidator::with('CustomValidations', true); * @apiUse NO_PERMISSION * @apiUse INVALID_NAME * @apiUse INVALID_DEPARTMENT + * @apiUse NAME_ALREADY_USED * * @apiSuccess {Object} data Empty object * @@ -39,10 +40,7 @@ class EditDepartmentController extends Controller { 'error' => ERRORS::INVALID_DEPARTMENT ], 'name' => [ - 'validation' => DataValidator::AllOf( - DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), - DataValidator::ValidDepartmentName() - ), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], ] @@ -55,6 +53,11 @@ class EditDepartmentController extends Controller { $private = Controller::request('private'); $departmentInstance = Department::getDataStore($departmentId); + $createdDepartment = Department::getDataStore($newName, 'name'); + + if(!$createdDepartment->isNull() && $createdDepartment->name !== $departmentInstance->name){ + throw new RequestException(ERRORS::NAME_ALREADY_USED); + } if($private && $departmentId == Setting::getSetting('default-department-id')->getValue()){ throw new RequestException(ERRORS::DEFAULT_DEPARTMENT_CAN_NOT_BE_PRIVATE); diff --git a/server/data/ERRORS.php b/server/data/ERRORS.php index 90c61321..5c77a446 100755 --- a/server/data/ERRORS.php +++ b/server/data/ERRORS.php @@ -24,9 +24,17 @@ * @apiError {String} INVALID_TITLE The title is invalid, probably too short. */ /** - * @apiDefine INVALID_CONTENT + * @apiDefine TITLE_ALREADY_USED + * @apiError {String} TITLE_ALREADY_USED The title is already in use. + */ +/** + * @apiDefine INVALID_CONTENT * @apiError {String} INVALID_CONTENT The content is invalid, probably to short. */ +/** + * @apiDefine CONTENT_ALREADY_USED + * @apiError {String} CONTENT_ALREADY_USED The content is already in use. + */ /** * @apiDefine INVALID_EMAIL * @apiError {String} INVALID_EMAIL The email is invalid or already exists. @@ -335,7 +343,9 @@ class ERRORS { const TAG_EXISTS = 'TAG_EXISTS'; const NO_PERMISSION = 'NO_PERMISSION'; const INVALID_TITLE = 'INVALID_TITLE'; + const TITLE_ALREADY_USED = 'TITLE_ALREADY_USED'; const INVALID_CONTENT = 'INVALID_CONTENT'; + const CONTENT_ALREADY_USED = 'CONTENT_ALREADY_USED'; const INVALID_EMAIL = 'INVALID_EMAIL'; const INVALID_PASSWORD = 'INVALID_PASSWORD'; const INVALID_NAME = 'INVALID_NAME'; diff --git a/server/libs/validations/validArticleContent.php b/server/libs/validations/validArticleContent.php new file mode 100644 index 00000000..0dc5e1bb --- /dev/null +++ b/server/libs/validations/validArticleContent.php @@ -0,0 +1,13 @@ +isNull(); + } +} diff --git a/server/libs/validations/validArticleName.php b/server/libs/validations/validArticleName.php new file mode 100644 index 00000000..1a9d17a0 --- /dev/null +++ b/server/libs/validations/validArticleName.php @@ -0,0 +1,13 @@ +isNull(); + } +} diff --git a/server/libs/validations/validTopicName.php b/server/libs/validations/validTopicName.php new file mode 100644 index 00000000..158d730f --- /dev/null +++ b/server/libs/validations/validTopicName.php @@ -0,0 +1,13 @@ +isNull(); + } +} diff --git a/tests/article/article.rb b/tests/article/article.rb index 5eb06bc1..9116ddb3 100644 --- a/tests/article/article.rb +++ b/tests/article/article.rb @@ -48,6 +48,32 @@ describe 'Article path' do (lastLog['type']).should.equal('ADD_ARTICLE') end + it 'should fail if articles data already exists' do + + result = request('/article/add', { + title: 'Some article', + content: 'this content is unique', + topicId: @topic_id, + position: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + (result['status']).should.equal('fail') + (result['message']).should.equal('TITLE_ALREADY_USED') + + result = request('/article/add', { + title: 'unique title', + content: 'This is an article about server management.', + topicId: @topic_id, + position: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('fail') + (result['message']).should.equal('CONTENT_ALREADY_USED') + end + it 'should edit article' do result = request('/article/edit', { articleId: @article_id, @@ -67,6 +93,77 @@ describe 'Article path' do (lastLog['type']).should.equal('EDIT_ARTICLE') end + it 'should fail if edit article has already used data' do + result = request('/article/add', { + title: 'unique title1.5', + content: 'This is an article about server management1.5.', + topicId: @topic_id, + position: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + + result = request('/article/add', { + title: 'unique title2', + content: 'This is an article about server management22.', + topicId: @topic_id, + position: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + lastArticle = $database.getLastRow('article') + + result = request('/article/edit', { + articleId: lastArticle['id'], + content: 'This is an article about server management1.5.', + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('fail') + (result['message']).should.equal('CONTENT_ALREADY_USED') + + result = request('/article/edit', { + articleId: lastArticle['id'], + title: 'unique title1.5', + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('fail') + (result['message']).should.equal('TITLE_ALREADY_USED') + + end + + it 'should success if change for the same date' do + result = request('/article/add', { + title: 'unique article', + content: 'this content is unique pt2', + topicId: @topic_id, + position: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + + lastArticle = $database.getLastRow('article') + + result = request('/article/edit', { + articleId: lastArticle['id'], + title: 'unique article', + content: 'this content is unique pt2', + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + end + it 'should edit article topic' do request('/article/add-topic', { name: 'Software installation', @@ -107,38 +204,44 @@ describe 'Article path' do end it 'should retrieve all articles' do - request('/article/add', { - title: 'Some article', - content: 'This is an article about server management.', - topicId: @topic_id, - position: 1, - csrf_userid: $csrf_userid, - csrf_token: $csrf_token - }) + result = request('/article/get-all', { csrf_userid: $csrf_userid, csrf_token: $csrf_token }) (result['status']).should.equal('success') - (result['data'][0]['name']).should.equal('Server management') - (result['data'][0]['icon']).should.equal('cogs') - (result['data'][0]['iconColor']).should.equal('red') - (result['data'][0]['private']).should.equal('0') - (result['data'][1]['name']).should.equal('Private Topic') + (result['data'][0]['name']).should.equal('Valid name') + (result['data'][0]['icon']).should.equal('flag') + (result['data'][0]['iconColor']).should.equal('pink') + (result['data'][0]['private']).should.equal('1') + + (result['data'][1]['name']).should.equal('Server management') (result['data'][1]['icon']).should.equal('cogs') - (result['data'][1]['iconColor']).should.equal('green') - (result['data'][1]['private']).should.equal('1') - (result['data'][2]['name']).should.equal('Software installation') - (result['data'][2]['icon']).should.equal('photo') - (result['data'][2]['iconColor']).should.equal('blue') - (result['data'][2]['private']).should.equal('0') + (result['data'][1]['iconColor']).should.equal('red') + (result['data'][1]['private']).should.equal('0') - (result['data'][0]['articles'][0]['title']).should.equal('Some article') - (result['data'][0]['articles'][0]['content']).should.equal('This is an article about server management.') - (result['data'][0]['articles'][0]['position']).should.equal('1') + (result['data'][2]['name']).should.equal('Private Topic') + (result['data'][2]['icon']).should.equal('cogs') + (result['data'][2]['iconColor']).should.equal('green') + (result['data'][2]['private']).should.equal('1') + + (result['data'][3]['name']).should.equal('Software installation') + (result['data'][3]['icon']).should.equal('photo') + (result['data'][3]['iconColor']).should.equal('blue') + (result['data'][3]['private']).should.equal('0') + (result['data'][1]['articles'][0]['title']).should.equal('unique title1.5') + (result['data'][1]['articles'][0]['content']).should.equal('This is an article about server management1.5.') + (result['data'][1]['articles'][0]['position']).should.equal('1') + (result['data'][1]['articles'][1]['title']).should.equal('unique title2') + (result['data'][1]['articles'][1]['content']).should.equal('This is an article about server management22.') + (result['data'][1]['articles'][1]['position']).should.equal('1') + (result['data'][1]['articles'][2]['title']).should.equal('unique article') + (result['data'][1]['articles'][2]['content']).should.equal('this content is unique pt2') + (result['data'][1]['articles'][2]['position']).should.equal('1') end + it 'should retrieve public departments' do Scripts.logout() Scripts.login('tyrion@opensupports.com', 'tyrionl') diff --git a/tests/article/topic.rb b/tests/article/topic.rb index 3510b99b..07fb48f5 100644 --- a/tests/article/topic.rb +++ b/tests/article/topic.rb @@ -24,6 +24,19 @@ describe 'Topic paths' do (lastLog['type']).should.equal('ADD_TOPIC') end + it 'should success if topic has same name' do + result = request('/article/edit-topic', { + topicId: 1, + name: 'Server management', + iconColor: 'blue', + private: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + end + it 'should edit topic correctly' do result = request('/article/edit-topic', { topicId: 1, @@ -43,6 +56,47 @@ describe 'Topic paths' do (topic['private']).should.equal(1) end + it 'should fail if data is already in use' do + result = request('/article/add-topic', { + name: 'Installation issues', + icon: 'cogs', + iconColor: 'red', + private: 0, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('fail') + (result['message']).should.equal('NAME_ALREADY_USED') + end + + it 'should edit topic if data is right without name' do + result = request('/article/add-topic', { + name: 'Valid name', + icon: 'cogs', + iconColor: 'red', + private: 0, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + + topic = $database.getLastRow('topic') + + result = request('/article/edit-topic', { + name: 'Valid name', + topicId: topic['id'], + iconColor: 'pink', + icon: 'flag', + private: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + end + it 'should delete topic correctly' do result = request('/article/delete-topic', { topicId: 1, diff --git a/tests/scripts.rb b/tests/scripts.rb index 925e0e47..a7afbbee 100644 --- a/tests/scripts.rb +++ b/tests/scripts.rb @@ -162,11 +162,12 @@ class Scripts }) end - def self.createDepartment(nameDepartment = 'validnameDepartment') + def self.createDepartment(nameDepartment, private = 0) request('/system/add-department', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: nameDepartment + name: nameDepartment, + private: private }) end diff --git a/tests/system/edit-department.rb b/tests/system/edit-department.rb index 85700e40..ec748053 100644 --- a/tests/system/edit-department.rb +++ b/tests/system/edit-department.rb @@ -44,19 +44,39 @@ describe'system/edit-department' do result['status'].should.equal('fail') result['message'].should.equal('INVALID_NAME') + end + + it 'should success if you change for the same name' do + Scripts.createDepartment('thisisAnewName') + department = $database.getLastRow('department') + + result = request('/system/edit-department', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + name: department['name'], + departmentId: department['id'], + private:1 + }) + + result['status'].should.equal('success') + + end + + it 'shouild fail if you use an used name' do + Scripts.createDepartment('thistitleisunique') + lastDepartment = $database.getLastRow('department') result = request('/system/edit-department', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: lastDepartment['name'], - departmentId: 4 + name: 'thisisAnewName', + departmentId: lastDepartment['id'], + private:1 }) - result['status'].should.equal('fail') - result['message'].should.equal('INVALID_NAME') - + result['message'].should.equal('NAME_ALREADY_USED') end end