From f041321497e9bfe78f26480f1cbb63ac9851a8cc Mon Sep 17 00:00:00 2001 From: "karel.picman@lbcfree.net" Date: Wed, 7 Apr 2021 14:26:18 +0200 Subject: [PATCH] API doesn't respond like described in the docs #1231 --- app/views/dmsf/show.api.rsb | 8 +- test/integration/rest_api/dmsf_api_test.rb | 112 +++++++++++++++++++++ test/integration_test.rb | 1 + 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 test/integration/rest_api/dmsf_api_test.rb diff --git a/app/views/dmsf/show.api.rsb b/app/views/dmsf/show.api.rsb index e2422d0e..755123b4 100644 --- a/app/views/dmsf/show.api.rsb +++ b/app/views/dmsf/show.api.rsb @@ -6,7 +6,13 @@ api.dmsf do api.id node.id api.title node.title api.type node.type - api.filename node.filename + case node.type + when 'file', 'url-link' + api.filename node.filename + when 'file-link', 'folder-link' + api.target_id node.revision_id + api.target_project_id node.project_id + end end end end diff --git a/test/integration/rest_api/dmsf_api_test.rb b/test/integration/rest_api/dmsf_api_test.rb new file mode 100644 index 00000000..4cf9a511 --- /dev/null +++ b/test/integration/rest_api/dmsf_api_test.rb @@ -0,0 +1,112 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-21 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../test_helper', __FILE__) + +class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest + include Redmine::I18n + + fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :dmsf_links, :dmsf_locks + + def setup + super + Setting.rest_api_enabled = '1' + @token = Token.create!(user: @jsmith_user, action: 'api') + end + + def test_get + # curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/projects/12/dmsf.xml + get "/projects/#{@project1.id}/dmsf.xml?key=#{@token.value}" + assert_response :success + assert_equal 'application/xml', @response.content_type + # + # + # + # + # 1 + # folder1 + # folder + # + # + # 1 + # folder1_link + # folder-link + # 1 + # 1 + # + # + # 6 + # folder6 + # folder + # + # + # 7 + # folder7 + # folder + # + # + # 6 + # file1_link + # file-link + # 1 + # 1 + # + # + # 9 + # My File + # file + # myfile.txt + # + # + # 8 + # PDF + # file + # test.pdf + # + # + # 1 + # Test File + # file + # test5.txt + # + # + # 4 + # test_link + # file-link + # 4 + # 1 + # + # + # 10 + # Zero Size File + # file + # zero.txt + # + # + # + assert_select 'node > id', text: @folder1.id.to_s + assert_select 'node > title', text: @folder1.title + assert_select 'node > type', text: 'folder' + assert_select 'node > filename', text: @file9.last_revision.name + assert_select 'node > target_id', text: @folder_link1.target_id.to_s + assert_select 'node > target_project_id', text: @folder_link1.target_project_id.to_s + end +end \ No newline at end of file diff --git a/test/integration_test.rb b/test/integration_test.rb index c5855231..d99629cc 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -52,6 +52,7 @@ module RedmineDmsf @folder6 = DmsfFolder.find 6 @folder7 = DmsfFolder.find 7 @folder10 = DmsfFolder.find 10 + @folder_link1 = DmsfLink.find 1 @role = Role.find_by(name: 'Manager') @role.add_permission! :view_dmsf_folders @role.add_permission! :folder_manipulation