|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe Crowdin::ApiResources::StringCorrections do |
| 4 | + describe 'Default endpoints' do |
| 5 | + let(:correction_id) { 35 } |
| 6 | + let(:string_id) { 2 } |
| 7 | + |
| 8 | + describe '#list_corrections' do |
| 9 | + it 'when request is valid', :default do |
| 10 | + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections") |
| 11 | + .with(query: { stringId: string_id }) |
| 12 | + list_corrections = @crowdin.list_corrections({ stringId: string_id }, project_id) |
| 13 | + expect(list_corrections).to eq(200) |
| 14 | + end |
| 15 | + |
| 16 | + it 'when request is valid', :default do |
| 17 | + query = { stringId: string_id, limit: 50, offset: 10, orderBy: 'createdAt desc', denormalizePlaceholders: 1 } |
| 18 | + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections") |
| 19 | + .with(query: query) |
| 20 | + list_corrections = @crowdin.list_corrections(query, project_id) |
| 21 | + expect(list_corrections).to eq(200) |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + describe '#add_correction' do |
| 26 | + it 'when request is valid', :default do |
| 27 | + body = { stringId: 35_434, text: 'This string has been corrected', pluralCategoryName: 'few' } |
| 28 | + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections") |
| 29 | + .with(body: body) |
| 30 | + add_correction = @crowdin.add_correction(body, project_id) |
| 31 | + expect(add_correction).to eq(200) |
| 32 | + end |
| 33 | + |
| 34 | + it 'when request is valid', :default do |
| 35 | + body = { stringId: 35_434, text: 'This string has been corrected' } |
| 36 | + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections") |
| 37 | + .with(body: body) |
| 38 | + add_correction = @crowdin.add_correction(body, project_id) |
| 39 | + expect(add_correction).to eq(200) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe '#get_correction' do |
| 44 | + it 'when request is valid', :default do |
| 45 | + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections/#{correction_id}") |
| 46 | + get_correction = @crowdin.get_correction(correction_id, {}, project_id) |
| 47 | + expect(get_correction).to eq(200) |
| 48 | + end |
| 49 | + |
| 50 | + it 'when request is valid', :default do |
| 51 | + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections/#{correction_id}") |
| 52 | + .with(query: { denormalizePlaceholders: 1 }) |
| 53 | + get_correction = @crowdin.get_correction(correction_id, { denormalizePlaceholders: 1 }, project_id) |
| 54 | + expect(get_correction).to eq(200) |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + describe '#delete_corrections' do |
| 59 | + it 'when request is valid', :default do |
| 60 | + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections") |
| 61 | + .with(query: { stringId: string_id }) |
| 62 | + delete_corrections = @crowdin.delete_corrections({ stringId: string_id }, project_id) |
| 63 | + expect(delete_corrections).to eq(200) |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + describe '#delete_correction' do |
| 68 | + it 'when request is valid', :default do |
| 69 | + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections/#{correction_id}") |
| 70 | + delete_correction = @crowdin.delete_correction(correction_id, project_id) |
| 71 | + expect(delete_correction).to eq(200) |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + describe '#restore_correction' do |
| 76 | + it 'when request is valid', :default do |
| 77 | + stub_request(:put, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/corrections/#{correction_id}") |
| 78 | + restore_correction = @crowdin.restore_correction(correction_id, project_id) |
| 79 | + expect(restore_correction).to eq(200) |
| 80 | + end |
| 81 | + end |
| 82 | + end |
| 83 | +end |
0 commit comments