translations_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'System Assets', type: :request do
  4. let(:admin) { create(:admin) }
  5. describe 'GET /translations/customized', authenticated_as: :admin do
  6. before do
  7. create(:translation, locale: 'de-de', source: 'A example', target: 'Ein Beispiel')
  8. end
  9. it 'returns the customized list of translations' do
  10. get '/api/v1/translations/customized'
  11. expect(json_response.count).to eq(1)
  12. end
  13. end
  14. describe 'GET /translations/search/:locale', authenticated_as: :admin do
  15. let(:query) { SecureRandom.uuid }
  16. before do
  17. create(:translation, locale: 'de-de', source: 'A example', target: "Ein Beispiel #{query}", is_synchronized_from_codebase: true)
  18. end
  19. it 'returns the filtered translations' do
  20. get '/api/v1/translations/search/de-de', params: { query: }
  21. expect(json_response['items'].count).to eq(1)
  22. end
  23. end
  24. describe 'POST /translations/upsert', :aggregate_failures, authenticated_as: :admin do
  25. let(:locale) { 'de-de' }
  26. let(:source) { SecureRandom.uuid }
  27. let(:target) { 'Other' }
  28. it 'creates a new translation record' do
  29. expect do
  30. post '/api/v1/translations/upsert', params: { source:, locale:, target: }
  31. end.to change(Translation, :count).by(1)
  32. expect(json_response).to include('locale' => locale, 'source' => source, 'target' => target)
  33. end
  34. end
  35. describe 'PUT /translations/reset/:id', :aggregate_failures, authenticated_as: :admin do
  36. let(:translation) { Translation.find_by(locale: 'de-de', source: 'New') }
  37. before do
  38. translation.update!(target: 'Neu!')
  39. end
  40. it 'resets translation record' do
  41. expect do
  42. put "/api/v1/translations/reset/#{translation.id}"
  43. end.to change { translation.reload.target }.to(translation.target_initial)
  44. end
  45. end
  46. end