Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Adds a test to the more common not found case and error handling on delete folder

Marcello Rochaf6ae5c78f8db
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
index b422a57aaaf..cb32b61a8f6 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command.rb
@@ -46,7 +46,25 @@ module Storages
Util.using_admin_token(@storage) do |http|
response = http.delete("/v1.0/drives/#{@storage.drive_id}/items/#{location}")
- ServiceResult.success(result: response.body)
+ data = ::Storages::StorageErrorData.new(source: self.class, payload: response)
+
+ case response.status
+ when 200..299
+ # The service returns a 204 with an empty body
+ ServiceResult.success
+ when 401
+ ServiceResult.failure(result: :unauthorized,
+ errors: ::Storages::StorageError.new(code: :unauthorized, data:))
+ when 404
+ ServiceResult.failure(result: :not_found,
+ errors: ::Storages::StorageError.new(code: :not_found, data:))
+ when 409
+ ServiceResult.failure(result: :conflict,
+ errors: ::Storages::StorageError.new(code: :conflict, data:))
+ else
+ ServiceResult.failure(result: :error,
+ errors: ::Storages::StorageError.new(code: :error, data:))
+ end
end
end
end
diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command_spec.rb
index ffd528c51cd..44fce63906a 100644
--- a/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/one_drive/delete_folder_command_spec.rb
@@ -54,4 +54,10 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::DeleteFolder
expect(described_class.call(storage:, location: folder.id)).to be_success
end
+
+ it 'when the folder is not found, returns a failure', vcr: 'one_drive/delete_folder_not_found' do
+ result = described_class.call(storage:, location: 'NOT_HERE')
+ expect(result).to be_failure
+ expect(result.result).to eq(:not_found)
+ end
end
diff --git a/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/delete_folder_not_found.yml b/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/delete_folder_not_found.yml
new file mode 100644
index 00000000000..fdf72a3d925
--- /dev/null
+++ b/modules/storages/spec/support/fixtures/vcr_cassettes/one_drive/delete_folder_not_found.yml
@@ -0,0 +1,106 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://login.microsoftonline.com/4d44bf36-9b56-45c0-8807-bbf386dd047f/oauth2/v2.0/token
+ body:
+ encoding: UTF-8
+ string: grant_type=client_credentials&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
+ headers:
+ User-Agent:
+ - Rack::OAuth2 (2.2.1)
+ Authorization:
+ - Basic NDI2MmRmMmItNzdiYi00OWMyLWE1ZGYtMjgzNTVkYTY3NmQyOlZ3azhRJTdFSlR1UGgucEFqdlBpV0JRQmRURk1ESyU3RUFJd3hiajlfYXhC
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Cache-Control:
+ - no-store, no-cache
+ Pragma:
+ - no-cache
+ Content-Type:
+ - application/json; charset=utf-8
+ Expires:
+ - "-1"
+ Strict-Transport-Security:
+ - max-age=31536000; includeSubDomains
+ X-Content-Type-Options:
+ - nosniff
+ P3p:
+ - CP="DSP CUR OTPi IND OTRi ONL FIN"
+ X-Ms-Request-Id:
+ - ede6e341-03a6-4171-b0cf-a72b9e8f7000
+ X-Ms-Ests-Server:
+ - 2.1.16986.9 - NEULR1 ProdSlices
+ X-Xss-Protection:
+ - '0'
+ Set-Cookie:
+ - fpc=Am31HFdf2i9Fo6HBZdFTWdWkbDoXAQAAABKQOd0OAAAA; expires=Fri, 16-Feb-2024
+ 09:08:35 GMT; path=/; secure; HttpOnly; SameSite=None
+ - stsservicecookie=estsfd; path=/; secure; samesite=none; httponly
+ - x-ms-gateway-slice=estsfd; path=/; secure; samesite=none; httponly
+ Date:
+ - Wed, 17 Jan 2024 09:08:35 GMT
+ Content-Length:
+ - '1708'
+ body:
+ encoding: UTF-8
+ string: '{"token_type":"Bearer","expires_in":3599,"ext_expires_in":3599,"access_token":"eyJ0eXAiOiJKV1QiLCJub25jZSI6IlZwX0xlWk5JNklnQlhLSXoyMktldEg2Tkt4Q2JJZll2MWdiZlkyLVVjQkEiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVCM25SeHRRN2ppOGVORGMzRnkwNUtmOTdaRSIsImtpZCI6IjVCM25SeHRRN2ppOGVORGMzRnkwNUtmOTdaRSJ9.eyJhdWQiOiJodHRwczovL2dyYXBoLm1pY3Jvc29mdC5jb20iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC80ZDQ0YmYzNi05YjU2LTQ1YzAtODgwNy1iYmYzODZkZDA0N2YvIiwiaWF0IjoxNzA1NDgyMjE1LCJuYmYiOjE3MDU0ODIyMTUsImV4cCI6MTcwNTQ4NjExNSwiYWlvIjoiRTJWZ1lFZzhPamsvOWVQRW16TmI1OTJmZGVSWUFBQT0iLCJhcHBfZGlzcGxheW5hbWUiOiJPcGVuUHJvamVjdCBEZXYgQXBwIiwiYXBwaWQiOiI0MjYyZGYyYi03N2JiLTQ5YzItYTVkZi0yODM1NWRhNjc2ZDIiLCJhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC80ZDQ0YmYzNi05YjU2LTQ1YzAtODgwNy1iYmYzODZkZDA0N2YvIiwiaWR0eXAiOiJhcHAiLCJvaWQiOiI0NGJjNzc5MC1iNjM4LTRlMTYtOWE5Mi04YWJjNDY1MGYyMDYiLCJyaCI6IjAuQVFrQU5yOUVUVmFid0VXSUI3dnpodDBFZndNQUFBQUFBQUFBd0FBQUFBQUFBQUFKQUFBLiIsInJvbGVzIjpbIlNpdGVzLlJlYWQuQWxsIiwiU2l0ZXMuUmVhZFdyaXRlLkFsbCIsIkZpbGVzLlJlYWRXcml0ZS5BbGwiXSwic3ViIjoiNDRiYzc3OTAtYjYzOC00ZTE2LTlhOTItOGFiYzQ2NTBmMjA2IiwidGVuYW50X3JlZ2lvbl9zY29wZSI6IkVVIiwidGlkIjoiNGQ0NGJmMzYtOWI1Ni00NWMwLTg4MDctYmJmMzg2ZGQwNDdmIiwidXRpIjoiUWVQbTdhWURjVUd3ejZjcm5vOXdBQSIsInZlciI6IjEuMCIsIndpZHMiOlsiMDk5N2ExZDAtMGQxZC00YWNiLWI0MDgtZDVjYTczMTIxZTkwIl0sInhtc190Y2R0IjoxNDA1NTE0ODYxLCJ4bXNfdGRiciI6IkVVIn0.a--cDV-rux1foREv6pNSHEdJnzu4z2m8yFdRLgJCkkoh-lhkV4PMhjJI6sMMeT20dt0qqzoE2zJlADdXGPRW6yB3ohNecxzXPlJ4L_GotNSJ8YaMkUekSyJMP9aM2i3ZpxYLcPMVn1jxSAyOQG2-TplBFmC6a3lTYmpbw6IHIzqNWHx71aEeAPjYsfDip6aYuszgx0xRs9kbgXS_sgmII40ZQ7APzaKB7VlWECaW5jxPKGxdFFWVe3uumk-48xMcO3XKuaJmdzRZrTnZy5dJNBJ_ROyE-XLJ-FwZpd_rGyAlefxxua6jbviTChHXC6M2ZWaXaPKGEVlc0hFwe4GJew"}'
+ recorded_at: Wed, 17 Jan 2024 09:08:36 GMT
+- request:
+ method: delete
+ uri: https://graph.microsoft.com/v1.0/drives/b!dmVLG22QlE2PSW0AqVB7UOhZ8n7tjkVGkgqLNnuw2OBb-brzKzZAR4DYT1k9KPXs/items/NOT_HERE
+ body:
+ encoding: US-ASCII
+ string: ''
+ headers:
+ Authorization:
+ - Bearer eyJ0e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NGJmMzYtOWI1Ni00NWMwLTg4MDctYmJmMzg2ZGQwNDdmIiwidXRpIjoiUWVQbTdhWURjVUd3ejZjcm5vOXdBQSIsInZlciI6IjEuMCIsIndpZHMiOlsiMDk5N2ExZDAtMGQxZC00YWNiLWI0MDgtZDVjYTczMTIxZTkwIl0sInhtc190Y2R0IjoxNDA1NTE0ODYxLCJ4bXNfdGRiciI6IkVVIn0.a--cDV-rux1foREv6pNSHEdJnzu4z2m8yFdRLgJCkkoh-lhkV4PMhjJI6sMMeT20dt0qqzoE2zJlADdXGPRW6yB3ohNecxzXPlJ4L_GotNSJ8YaMkUekSyJMP9aM2i3ZpxYLcPMVn1jxSAyOQG2-TplBFmC6a3lTYmpbw6IHIzqNWHx71aEeAPjYsfDip6aYuszgx0xRs9kbgXS_sgmII40ZQ7APzaKB7VlWECaW5jxPKGxdFFWVe3uumk-48xMcO3XKuaJmdzRZrTnZy5dJNBJ_ROyE-XLJ-FwZpd_rGyAlefxxua6jbviTChHXC6M2ZWaXaPKGEVlc0hFwe4GJew
+ Accept:
+ - application/json
+ Content-Type:
+ - application/json
+ User-Agent:
+ - httpx.rb/1.2.1
+ Accept-Encoding:
+ - gzip, deflate
+ response:
+ status:
+ code: 404
+ message: Not Found
+ headers:
+ Cache-Control:
+ - no-store, no-cache
+ Transfer-Encoding:
+ - chunked
+ Content-Type:
+ - application/json
+ Content-Encoding:
+ - gzip
+ Vary:
+ - Accept-Encoding
+ Strict-Transport-Security:
+ - max-age=31536000
+ Request-Id:
+ - 0c9bcad9-6728-4891-a7d1-e42e2d6f59b3
+ Client-Request-Id:
+ - 0c9bcad9-6728-4891-a7d1-e42e2d6f59b3
+ X-Ms-Ags-Diagnostic:
+ - '{"ServerInfo":{"DataCenter":"Germany West Central","Slice":"E","Ring":"5","ScaleUnit":"005","RoleInstance":"FR3PEPF00000315"}}'
+ Date:
+ - Wed, 17 Jan 2024 09:08:35 GMT
+ Connection:
+ - close
+ body:
+ encoding: UTF-8
+ string: '{"error":{"code":"itemNotFound","message":"Item not found","innerError":{"date":"2024-01-17T09:08:36","request-id":"0c9bcad9-6728-4891-a7d1-e42e2d6f59b3","client-request-id":"0c9bcad9-6728-4891-a7d1-e42e2d6f59b3"}}}'
+ recorded_at: Wed, 17 Jan 2024 09:08:36 GMT
+recorded_with: VCR 6.2.0