forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslations_spec.rb
61 lines (46 loc) · 1.93 KB
/
translations_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
require 'rails_helper'
RSpec.describe 'System Assets', type: :request do
let(:admin) { create(:admin) }
describe 'GET /translations/customized', authenticated_as: :admin do
before do
create(:translation, locale: 'de-de', source: 'A example', target: 'Ein Beispiel')
end
it 'returns the customized list of translations' do
get '/api/v1/translations/customized'
expect(json_response.count).to eq(1)
end
end
describe 'GET /translations/search/:locale', authenticated_as: :admin do
let(:query) { SecureRandom.uuid }
before do
create(:translation, locale: 'de-de', source: 'A example', target: "Ein Beispiel #{query}", is_synchronized_from_codebase: true)
end
it 'returns the filtered translations' do
get '/api/v1/translations/search/de-de', params: { query: }
expect(json_response['items'].count).to eq(1)
end
end
describe 'POST /translations/upsert', :aggregate_failures, authenticated_as: :admin do
let(:locale) { 'de-de' }
let(:source) { SecureRandom.uuid }
let(:target) { 'Other' }
it 'creates a new translation record' do
expect do
post '/api/v1/translations/upsert', params: { source:, locale:, target: }
end.to change(Translation, :count).by(1)
expect(json_response).to include('locale' => locale, 'source' => source, 'target' => target)
end
end
describe 'PUT /translations/reset/:id', :aggregate_failures, authenticated_as: :admin do
let(:translation) { Translation.find_by(locale: 'de-de', source: 'New') }
before do
translation.update!(target: 'Neu!')
end
it 'resets translation record' do
expect do
put "/api/v1/translations/reset/#{translation.id}"
end.to change { translation.reload.target }.to(translation.target_initial)
end
end
end