This commit is contained in:
Guillermo 2018-11-26 15:09:34 -03:00
parent 1bc30240bd
commit d2b6f1cc30
3 changed files with 52 additions and 6 deletions

View File

@ -57,7 +57,7 @@ class EditTopicController extends Controller {
if(Controller::request('icon')) {
$topic->icon = Controller::request('icon');
}
if(Controller::request('private') || Controller::request('private') == 0) {
if (Controller::request('private') !== null) {
$topic->private = Controller::request('private');
}

View File

@ -35,7 +35,11 @@ class GetAllArticlesController extends Controller {
$topicsArray = [];
foreach($topics as $topic) {
Controller::isStaffLogged() ? $topicsArray[] = $topic->toArray() : ($topic->private*1 ? null : $topicsArray[] = $topic->toArray()) ;
if (Controller::isStaffLogged()) {
$topicsArray[] = $topic->toArray();
} else if (!$topic->private) {
$topicsArray[] = $topic->toArray();
}
}
Response::respondSuccess($topicsArray);

View File

@ -6,10 +6,26 @@ describe 'Article path' do
icon: 'cogs',
iconColor: 'red',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
csrf_token: $csrf_token,
private: 0
})
@topic_id = topic['data']['topicId']
it 'should create a private topic' do
result = request('/article/add-topic', {
name: 'Private Topic',
icon: 'cogs',
iconColor: 'green',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
private: 1
})
row = $database.getRow('topic', 'Private Topic', 'name')
result['status'].should.equal('success')
(row['private']).should.equal('1')
end
it 'should create article' do
result = request('/article/add', {
title: 'Some article',
@ -108,13 +124,39 @@ describe 'Article path' do
(result['data'][0]['name']).should.equal('Server management')
(result['data'][0]['icon']).should.equal('cogs')
(result['data'][0]['iconColor']).should.equal('red')
(result['data'][1]['name']).should.equal('Software installation')
(result['data'][1]['icon']).should.equal('photo')
(result['data'][1]['iconColor']).should.equal('blue')
(result['data'][0]['private']).should.equal('0')
(result['data'][1]['name']).should.equal('Private Topic')
(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'][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')
end
it 'should retrieve public departments' do
request('/user/logout')
Scripts.login('tyrion@opensupports.com', 'tyrionl')
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('Software installation')
(result['data'][1]['icon']).should.equal('photo')
(result['data'][1]['iconColor']).should.equal('blue')
(result['data'][1]['private']).should.equal('0')
end
end