crowdin-api 1.1.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test-and-lint.yml +1 -1
  3. data/.gitignore +2 -2
  4. data/.rubocop_todo.yml +114 -42
  5. data/README.md +26 -13
  6. data/bin/crowdin-console +5 -5
  7. data/crowdin-api.gemspec +1 -2
  8. data/lib/crowdin-api/api_resources/dictionaries.rb +32 -0
  9. data/lib/crowdin-api/api_resources/distributions.rb +92 -0
  10. data/lib/crowdin-api/api_resources/glossaries.rb +199 -0
  11. data/lib/crowdin-api/api_resources/labels.rb +98 -0
  12. data/lib/crowdin-api/api_resources/languages.rb +61 -0
  13. data/lib/crowdin-api/api_resources/machine_translation_engines.rb +79 -0
  14. data/lib/crowdin-api/api_resources/projects.rb +124 -0
  15. data/lib/crowdin-api/api_resources/reports.rb +120 -0
  16. data/lib/crowdin-api/api_resources/screenshots.rb +172 -0
  17. data/lib/crowdin-api/{api-resources → api_resources}/source_files.rb +68 -130
  18. data/lib/crowdin-api/{api-resources → api_resources}/source_strings.rb +19 -24
  19. data/lib/crowdin-api/api_resources/storages.rb +54 -0
  20. data/lib/crowdin-api/api_resources/string_comments.rb +68 -0
  21. data/lib/crowdin-api/api_resources/string_translations.rb +193 -0
  22. data/lib/crowdin-api/api_resources/tasks.rb +102 -0
  23. data/lib/crowdin-api/api_resources/teams.rb +135 -0
  24. data/lib/crowdin-api/api_resources/translation_memory.rb +131 -0
  25. data/lib/crowdin-api/{api-resources → api_resources}/translation_status.rb +24 -30
  26. data/lib/crowdin-api/{api-resources → api_resources}/translations.rb +41 -59
  27. data/lib/crowdin-api/api_resources/users.rb +161 -0
  28. data/lib/crowdin-api/api_resources/vendors.rb +21 -0
  29. data/lib/crowdin-api/api_resources/webhooks.rb +68 -0
  30. data/lib/crowdin-api/api_resources/workflows.rb +59 -0
  31. data/lib/crowdin-api/client/client.rb +72 -50
  32. data/lib/crowdin-api/client/configuration.rb +16 -12
  33. data/lib/crowdin-api/client/version.rb +1 -1
  34. data/lib/crowdin-api/core/errors.rb +2 -1
  35. data/lib/crowdin-api/core/{api_errors_raiser.rb → errors_raisers.rb} +21 -11
  36. data/lib/crowdin-api/core/request.rb +53 -88
  37. data/lib/crowdin-api/core/send_request.rb +67 -0
  38. data/lib/crowdin-api.rb +20 -11
  39. data/spec/api_resources/dictionaries_spec.rb +23 -0
  40. data/spec/api_resources/distributions_spec.rb +71 -0
  41. data/spec/api_resources/glossaries_spec.rb +167 -0
  42. data/spec/api_resources/labels_spec.rb +71 -0
  43. data/spec/api_resources/languages_spec.rb +51 -0
  44. data/spec/api_resources/machine_translation_engines_spec.rb +63 -0
  45. data/spec/api_resources/projects_spec.rb +215 -0
  46. data/spec/api_resources/reports_spec.rb +95 -0
  47. data/spec/api_resources/screenshots_spec.rb +134 -0
  48. data/spec/api_resources/source_files_spec.rb +13 -0
  49. data/spec/api_resources/source_strings_spec.rb +51 -0
  50. data/spec/api_resources/storages_spec.rb +13 -0
  51. data/spec/api_resources/string_comments_spec.rb +13 -0
  52. data/spec/api_resources/string_translations_spec.rb +13 -0
  53. data/spec/api_resources/tasks_spec.rb +79 -0
  54. data/spec/api_resources/teams_spec.rb +13 -0
  55. data/spec/api_resources/translation_memory_spec.rb +13 -0
  56. data/spec/api_resources/translation_status_spec.rb +15 -0
  57. data/spec/api_resources/translations_spec.rb +107 -0
  58. data/spec/api_resources/users_spec.rb +117 -0
  59. data/spec/api_resources/vendors_spec.rb +13 -0
  60. data/spec/api_resources/webhooks_spec.rb +51 -0
  61. data/spec/api_resources/workflows_spec.rb +41 -0
  62. data/spec/spec_helper.rb +20 -2
  63. data/spec/unit/client_spec.rb +85 -0
  64. metadata +65 -28
  65. data/bin/setup +0 -6
  66. data/lib/crowdin-api/api-resources/languages.rb +0 -81
  67. data/lib/crowdin-api/api-resources/projects.rb +0 -134
  68. data/lib/crowdin-api/api-resources/storages.rb +0 -102
  69. data/lib/crowdin-api/api-resources/workflows.rb +0 -59
  70. data/spec/core/config-instance_spec.rb +0 -72
  71. data/spec/crowdin-api_spec.rb +0 -7
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Crowdin::ApiResources::Glossaries do
4
+ describe 'Default endpoints' do
5
+ describe '#list_glossaries' do
6
+ it 'when request are valid', :default do
7
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries")
8
+ list_glossaries = @crowdin.list_glossaries
9
+ expect(list_glossaries).to eq(200)
10
+ end
11
+ end
12
+
13
+ describe '#add_glossary' do
14
+ it 'when request are valid', :default do
15
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries")
16
+ add_glossary = @crowdin.add_glossary
17
+ expect(add_glossary).to eq(200)
18
+ end
19
+ end
20
+
21
+ describe '#get_glossary' do
22
+ let(:glossary_id) { 1 }
23
+
24
+ it 'when request are valid', :default do
25
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
26
+ get_glossary = @crowdin.get_glossary(glossary_id)
27
+ expect(get_glossary).to eq(200)
28
+ end
29
+ end
30
+
31
+ describe '#delete_glossary' do
32
+ let(:glossary_id) { 1 }
33
+
34
+ it 'when request are valid', :default do
35
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
36
+ delete_glossary = @crowdin.delete_glossary(glossary_id)
37
+ expect(delete_glossary).to eq(200)
38
+ end
39
+ end
40
+
41
+ describe '#edit_glossary' do
42
+ let(:glossary_id) { 1 }
43
+
44
+ it 'when request are valid', :default do
45
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}")
46
+ edit_glossary = @crowdin.edit_glossary(glossary_id)
47
+ expect(edit_glossary).to eq(200)
48
+ end
49
+ end
50
+
51
+ describe '#export_glossary' do
52
+ let(:glossary_id) { 1 }
53
+
54
+ it 'when request are valid', :default do
55
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports")
56
+ export_glossary = @crowdin.export_glossary({}, glossary_id)
57
+ expect(export_glossary).to eq(200)
58
+ end
59
+ end
60
+
61
+ describe '#check_glossary_export_status' do
62
+ let(:glossary_id) { 1 }
63
+ let(:export_id) { 1 }
64
+
65
+ it 'when request are valid', :default do
66
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}")
67
+ check_glossary_export_status = @crowdin.check_glossary_export_status(glossary_id, export_id)
68
+ expect(check_glossary_export_status).to eq(200)
69
+ end
70
+ end
71
+
72
+ describe '#download_glossary' do
73
+ let(:glossary_id) { 1 }
74
+ let(:export_id) { 1 }
75
+
76
+ it 'when request are valid', :default do
77
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}/download")
78
+ download_glossary = @crowdin.download_glossary(glossary_id, export_id)
79
+ expect(download_glossary).to eq(200)
80
+ end
81
+ end
82
+
83
+ describe '#import_glossary' do
84
+ let(:glossary_id) { 1 }
85
+
86
+ it 'when request are valid', :default do
87
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports")
88
+ import_glossary = @crowdin.import_glossary(glossary_id)
89
+ expect(import_glossary).to eq(200)
90
+ end
91
+ end
92
+
93
+ describe '#check_glossary_import_status' do
94
+ let(:glossary_id) { 1 }
95
+ let(:import_id) { 1 }
96
+
97
+ it 'when request are valid', :default do
98
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports/#{import_id}")
99
+ check_glossary_import_status = @crowdin.check_glossary_import_status(glossary_id, import_id)
100
+ expect(check_glossary_import_status).to eq(200)
101
+ end
102
+ end
103
+
104
+ describe '#list_terms' do
105
+ let(:glossary_id) { 1 }
106
+
107
+ it 'when request are valid', :default do
108
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
109
+ list_terms = @crowdin.list_terms(glossary_id)
110
+ expect(list_terms).to eq(200)
111
+ end
112
+ end
113
+
114
+ describe '#add_term' do
115
+ let(:glossary_id) { 1 }
116
+
117
+ it 'when request are valid', :default do
118
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
119
+ add_term = @crowdin.add_term(glossary_id)
120
+ expect(add_term).to eq(200)
121
+ end
122
+ end
123
+
124
+ describe '#clear_glossary' do
125
+ let(:glossary_id) { 1 }
126
+
127
+ it 'when request are valid', :default do
128
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms")
129
+ clear_glossary = @crowdin.clear_glossary(glossary_id)
130
+ expect(clear_glossary).to eq(200)
131
+ end
132
+ end
133
+
134
+ describe '#get_term' do
135
+ let(:glossary_id) { 1 }
136
+ let(:term_id) { 1 }
137
+
138
+ it 'when request are valid', :default do
139
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
140
+ get_term = @crowdin.get_term(glossary_id, term_id)
141
+ expect(get_term).to eq(200)
142
+ end
143
+ end
144
+
145
+ describe '#delete_term' do
146
+ let(:glossary_id) { 1 }
147
+ let(:term_id) { 1 }
148
+
149
+ it 'when request are valid', :default do
150
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
151
+ delete_term = @crowdin.delete_term(glossary_id, term_id)
152
+ expect(delete_term).to eq(200)
153
+ end
154
+ end
155
+
156
+ describe '#edit_term' do
157
+ let(:glossary_id) { 1 }
158
+ let(:term_id) { 1 }
159
+
160
+ it 'when request are valid', :default do
161
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}")
162
+ edit_term = @crowdin.edit_term(glossary_id, term_id)
163
+ expect(edit_term).to eq(200)
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Crowdin::ApiResources::Labels do
4
+ describe 'Default endpoints' do
5
+ describe '#list_labels' do
6
+ it 'when request are valid', :default do
7
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels")
8
+ list_labels = @crowdin.list_labels({}, project_id)
9
+ expect(list_labels).to eq(200)
10
+ end
11
+ end
12
+
13
+ describe '#add_label' do
14
+ it 'when request are valid', :default do
15
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels")
16
+ add_label = @crowdin.add_label({}, project_id)
17
+ expect(add_label).to eq(200)
18
+ end
19
+ end
20
+
21
+ describe '#get_label' do
22
+ let(:label_id) { 1 }
23
+
24
+ it 'when request are valid', :default do
25
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
26
+ get_label = @crowdin.get_label(label_id, project_id)
27
+ expect(get_label).to eq(200)
28
+ end
29
+ end
30
+
31
+ describe '#delete_label' do
32
+ let(:label_id) { 1 }
33
+
34
+ it 'when request are valid', :default do
35
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
36
+ delete_label = @crowdin.delete_label(label_id, project_id)
37
+ expect(delete_label).to eq(200)
38
+ end
39
+ end
40
+
41
+ describe '#edit_label' do
42
+ let(:label_id) { 1 }
43
+
44
+ it 'when request are valid', :default do
45
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
46
+ edit_label = @crowdin.edit_label(label_id, {}, project_id)
47
+ expect(edit_label).to eq(200)
48
+ end
49
+ end
50
+
51
+ describe '#assign_label_to_strings' do
52
+ let(:label_id) { 1 }
53
+
54
+ it 'when request are valid', :default do
55
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/strings")
56
+ assign_label_to_strings = @crowdin.assign_label_to_strings(label_id, {}, project_id)
57
+ expect(assign_label_to_strings).to eq(200)
58
+ end
59
+ end
60
+
61
+ describe '#unassign_label_from_strings' do
62
+ let(:label_id) { 1 }
63
+
64
+ it 'when request are valid', :default do
65
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
66
+ unassign_label_from_strings = @crowdin.unassign_label_from_strings(label_id, {}, project_id)
67
+ expect(unassign_label_from_strings).to eq(200)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Crowdin::ApiResources::Languages do
4
+ describe 'Default endpoints' do
5
+ describe '#list_languages' do
6
+ it 'when request are valid', :default do
7
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/languages")
8
+ list_languages = @crowdin.list_languages
9
+ expect(list_languages).to eq(200)
10
+ end
11
+ end
12
+
13
+ describe '#add_custom_language' do
14
+ it 'when request are valid', :default do
15
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/languages")
16
+ add_custom_language = @crowdin.add_custom_language
17
+ expect(add_custom_language).to eq(200)
18
+ end
19
+ end
20
+
21
+ describe '#get_language' do
22
+ let(:language_id) { 1 }
23
+
24
+ it 'when request are valid', :default do
25
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/languages/#{language_id}")
26
+ get_language = @crowdin.get_language(language_id)
27
+ expect(get_language).to eq(200)
28
+ end
29
+ end
30
+
31
+ describe '#delete_custom_language' do
32
+ let(:language_id) { 1 }
33
+
34
+ it 'when request are valid', :default do
35
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/languages/#{language_id}")
36
+ delete_custom_language = @crowdin.delete_custom_language(language_id)
37
+ expect(delete_custom_language).to eq(200)
38
+ end
39
+ end
40
+
41
+ describe '#edit_custom_language' do
42
+ let(:language_id) { 1 }
43
+
44
+ it 'when request are valid', :default do
45
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/languages/#{language_id}")
46
+ edit_custom_language = @crowdin.edit_custom_language(language_id)
47
+ expect(edit_custom_language).to eq(200)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Crowdin::ApiResources::MachineTranslationEngines do
4
+ describe 'Default endpoints' do
5
+ describe '#list_mts' do
6
+ it 'when request are valid', :default do
7
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/mts")
8
+ list_mts = @crowdin.list_mts
9
+ expect(list_mts).to eq(200)
10
+ end
11
+ end
12
+
13
+ describe '#get_mt' do
14
+ let(:mt_id) { 1 }
15
+
16
+ it 'when request are valid', :default do
17
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/mts/#{mt_id}")
18
+ get_mt = @crowdin.get_mt(mt_id)
19
+ expect(get_mt).to eq(200)
20
+ end
21
+ end
22
+
23
+ describe '#translate_via_mt' do
24
+ let(:mt_id) { 1 }
25
+
26
+ it 'when request are valid', :default do
27
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/mts/#{mt_id}/translations")
28
+ translate_via_mt = @crowdin.translate_via_mt(mt_id)
29
+ expect(translate_via_mt).to eq(200)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'Enterprise endpoints' do
35
+ describe '#edit_mt' do
36
+ let(:mt_id) { 1 }
37
+
38
+ it 'when request are valid', :enterprise do
39
+ stub_request(:patch, "https://domain.api.crowdin.com/#{target_api_url}/mts/#{mt_id}")
40
+ edit_mt = @crowdin.edit_mt(mt_id)
41
+ expect(edit_mt).to eq(200)
42
+ end
43
+ end
44
+
45
+ describe '#add_mt' do
46
+ it 'when request are valid', :enterprise do
47
+ stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/mts")
48
+ add_mt = @crowdin.add_mt
49
+ expect(add_mt).to eq(200)
50
+ end
51
+ end
52
+
53
+ describe '#delete_mt' do
54
+ let(:mt_id) { 1 }
55
+
56
+ it 'when request are valid', :enterprise do
57
+ stub_request(:delete, "https://domain.api.crowdin.com/#{target_api_url}/mts/#{mt_id}")
58
+ delete_mt = @crowdin.delete_mt(mt_id)
59
+ expect(delete_mt).to eq(200)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,215 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Crowdin::ApiResources::Projects do
4
+ describe 'Default endpoints' do
5
+ describe '#list_projects' do
6
+ let(:limit) { 1 }
7
+ let(:offset) { 1 }
8
+
9
+ it 'when request are valid', :default do
10
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects")
11
+ list_projects = @crowdin.list_projects
12
+ expect(list_projects).to eq(200)
13
+ end
14
+
15
+ it 'when request are valid and includes query parameters', :default do
16
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects")
17
+ .with(query: { limit: limit, offset: offset })
18
+ list_projects = @crowdin.list_projects({ limit: limit, offset: offset })
19
+ expect(list_projects).to eq(200)
20
+ end
21
+ end
22
+
23
+ describe '#add_project' do
24
+ let(:project_name) { 'test_project' }
25
+ let(:source_language_id) { 'en' }
26
+
27
+ it 'when request are valid', :default do
28
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects")
29
+ .with(body: { name: project_name, sourceLanguageId: source_language_id })
30
+ add_project = @crowdin.add_project(name: project_name, sourceLanguageId: source_language_id)
31
+ expect(add_project).to eq(200)
32
+ end
33
+
34
+ let(:body) do
35
+ { "data" => { "id" => 1, "name" => "test_project" } }
36
+ end
37
+
38
+ it 'when request are valid and returns body', :default do
39
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects")
40
+ .with(body: { name: project_name, sourceLanguageId: source_language_id })
41
+ .to_return(body: body.to_json)
42
+ add_project = @crowdin.add_project(name: project_name, sourceLanguageId: source_language_id)
43
+ expect(add_project).to eq(body)
44
+ end
45
+ end
46
+
47
+ describe '#get_project' do
48
+ before do
49
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}")
50
+ end
51
+
52
+ let(:project_id) { 1 }
53
+
54
+ it 'when request are valid', :default do
55
+ get_project = @crowdin.get_project(project_id)
56
+ expect(get_project).to eq(200)
57
+ end
58
+
59
+ it 'when request are invalid', :default do
60
+ expect { @crowdin.get_project }.to raise_error(ArgumentError)
61
+ end
62
+ end
63
+
64
+ describe '#delete_project' do
65
+ before do
66
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}")
67
+ end
68
+
69
+ let(:project_id) { 1 }
70
+
71
+ it 'when request are valid', :default do
72
+ delete_project = @crowdin.delete_project(project_id)
73
+ expect(delete_project).to eq(200)
74
+ end
75
+
76
+ it 'when request are invalid', :default do
77
+ expect { @crowdin.delete_project }.to raise_error(ArgumentError)
78
+ end
79
+ end
80
+
81
+ describe '#edit_project' do
82
+ let(:project_id) { 1 }
83
+ let(:body) { [{ op: 'replace', path: '/name', value: 'project_name' }] }
84
+
85
+ it 'when request are valid', :default do
86
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}")
87
+ .with(body: body.to_json)
88
+ edit_project = @crowdin.edit_project(project_id, body)
89
+ expect(edit_project).to eq(200)
90
+ end
91
+
92
+ it 'when request are invalid', :default do
93
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}")
94
+ expect { @crowdin.edit_project }.to raise_error(ArgumentError)
95
+ end
96
+ end
97
+ end
98
+
99
+ describe 'Enterprise endpoints' do
100
+ describe '#list_groups' do
101
+ let(:limit) { 1 }
102
+ let(:offset) { 1 }
103
+
104
+ it 'when Enterprise mode is not enabled', :default do
105
+ stub_request(:get, "https://domain.api.crowdin.com/#{target_api_url}/groups")
106
+ expect { @crowdin.list_groups }.to raise_error(Crowdin::Errors::OnlyForEnterpriseModeError)
107
+ end
108
+
109
+ it 'when request are valid', :enterprise do
110
+ stub_request(:get, "https://domain.api.crowdin.com/#{target_api_url}/groups")
111
+ list_groups = @crowdin.list_groups
112
+ expect(list_groups).to eq(200)
113
+ end
114
+
115
+ it 'when request are valid and includes query parameters', :enterprise do
116
+ stub_request(:get, "https://domain.api.crowdin.com/#{target_api_url}/groups")
117
+ .with(query: { limit: limit, offset: offset })
118
+ list_groups = @crowdin.list_groups({ limit: limit, offset: offset })
119
+ expect(list_groups).to eq(200)
120
+ end
121
+ end
122
+
123
+ describe '#add_group' do
124
+ let(:group_name) { 'test_group' }
125
+
126
+ it 'when Enterprise mode is not enabled', :default do
127
+ stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/groups")
128
+ expect { @crowdin.add_group(name: group_name) }.to raise_error(Crowdin::Errors::OnlyForEnterpriseModeError)
129
+ end
130
+
131
+ it 'when request are valid', :enterprise do
132
+ stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/groups")
133
+ .with(body: { name: group_name })
134
+ add_group = @crowdin.add_group(name: group_name)
135
+ expect(add_group).to eq(200)
136
+ end
137
+
138
+ let(:body) do
139
+ { "data"=> { "id"=>1, "name"=>"test_group" } }
140
+ end
141
+
142
+ it 'when request are valid and returns body', :enterprise do
143
+ stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/groups")
144
+ .with(body: { name: group_name })
145
+ .to_return(body: body.to_json)
146
+ add_group = @crowdin.add_group(name: group_name)
147
+ expect(add_group).to eq(body)
148
+ end
149
+ end
150
+
151
+ describe '#get_group' do
152
+ before do
153
+ stub_request(:get, "https://domain.api.crowdin.com/#{target_api_url}/groups/#{group_id}")
154
+ end
155
+
156
+ let(:group_id) { 1 }
157
+
158
+ it 'when Enterprise mode is not enabled', :default do
159
+ expect { @crowdin.get_group(group_id) }.to raise_error(Crowdin::Errors::OnlyForEnterpriseModeError)
160
+ end
161
+
162
+ it 'when request are valid', :enterprise do
163
+ get_group = @crowdin.get_group(group_id)
164
+ expect(get_group).to eq(200)
165
+ end
166
+
167
+ it 'when request are invalid', :enterprise do
168
+ expect { @crowdin.get_group }.to raise_error(ArgumentError)
169
+ end
170
+ end
171
+
172
+ describe '#delete_group' do
173
+ before do
174
+ stub_request(:delete, "https://domain.api.crowdin.com/#{target_api_url}/groups/#{group_id}")
175
+ end
176
+
177
+ let(:group_id) { 1 }
178
+
179
+ it 'when Enterprise mode is not enabled', :default do
180
+ expect { @crowdin.delete_group(group_id) }.to raise_error(Crowdin::Errors::OnlyForEnterpriseModeError)
181
+ end
182
+
183
+ it 'when request are valid', :enterprise do
184
+ delete_group = @crowdin.delete_group(group_id)
185
+ expect(delete_group).to eq(200)
186
+ end
187
+
188
+ it 'when request are invalid', :enterprise do
189
+ expect { @crowdin.delete_group }.to raise_error(ArgumentError)
190
+ end
191
+ end
192
+
193
+ describe '#edit_group' do
194
+ let(:group_id) { 1 }
195
+ let(:body) { [{ op: 'replace', path: '/name', value: 'group_name' }] }
196
+
197
+ it 'when Enterprise mode is not enabled', :default do
198
+ stub_request(:patch, "https://domain.api.crowdin.com/#{target_api_url}/groups/#{group_id}")
199
+ expect { @crowdin.edit_group(group_id, body) }.to raise_error(Crowdin::Errors::OnlyForEnterpriseModeError)
200
+ end
201
+
202
+ it 'when request are valid', :enterprise do
203
+ stub_request(:patch, "https://domain.api.crowdin.com/#{target_api_url}/groups/#{group_id}")
204
+ .with(body: body.to_json)
205
+ edit_group = @crowdin.edit_group(group_id, body)
206
+ expect(edit_group).to eq(200)
207
+ end
208
+
209
+ it 'when request are invalid', :enterprise do
210
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/groups/#{group_id}")
211
+ expect { @crowdin.edit_group }.to raise_error(ArgumentError)
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Crowdin::ApiResources::Reports do
4
+ describe 'Default endpoints' do
5
+ describe '#generate_report' do
6
+ it 'when request are valid', :default do
7
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/reports")
8
+ generate_report = @crowdin.generate_report({}, project_id)
9
+ expect(generate_report).to eq(200)
10
+ end
11
+ end
12
+
13
+ describe '#check_report_generation_status' do
14
+ let(:report_id) { 1 }
15
+
16
+ it 'when request are valid', :default do
17
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/reports/#{report_id}")
18
+ check_report_generation_status = @crowdin.check_report_generation_status(report_id, project_id)
19
+ expect(check_report_generation_status).to eq(200)
20
+ end
21
+ end
22
+
23
+ describe '#download_report' do
24
+ let(:report_id) { 1 }
25
+
26
+ it 'when request are valid', :default do
27
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/reports/#{report_id}/download")
28
+ download_report = @crowdin.download_report(report_id, nil, project_id)
29
+ expect(download_report).to eq(200)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'Enterprise endpoints' do
35
+ describe '#generate_group_report' do
36
+ let(:group_id) { 1 }
37
+
38
+ it 'when request are valid', :enterprise do
39
+ stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/groups/#{group_id}/reports")
40
+ generate_group_report = @crowdin.generate_group_report(group_id, project_id)
41
+ expect(generate_group_report).to eq(200)
42
+ end
43
+ end
44
+
45
+ describe '#check_group_report_generation_status' do
46
+ let(:group_id) { 1 }
47
+ let(:report_id) { 1 }
48
+
49
+ it 'when request are valid', :enterprise do
50
+ stub_request(:get, "https://domain.api.crowdin.com/#{target_api_url}/groups/#{group_id}/reports/#{report_id}")
51
+ check_group_report_generation_status = @crowdin.check_group_report_generation_status(group_id, report_id)
52
+ expect(check_group_report_generation_status).to eq(200)
53
+ end
54
+ end
55
+
56
+ describe '#download_group_report' do
57
+ let(:group_id) { 1 }
58
+ let(:report_id) { 1 }
59
+
60
+ it 'when request are valid', :enterprise do
61
+ stub_request(:get, "https://domain.api.crowdin.com/#{target_api_url}/groups/#{group_id}/reports/#{report_id}/download")
62
+ download_group_report = @crowdin.download_group_report(group_id, project_id)
63
+ expect(download_group_report).to eq(200)
64
+ end
65
+ end
66
+
67
+ describe '#generate_organization_report' do
68
+ it 'when request are valid', :enterprise do
69
+ stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/reports")
70
+ generate_organization_report = @crowdin.generate_organization_report
71
+ expect(generate_organization_report).to eq(200)
72
+ end
73
+ end
74
+
75
+ describe '#check_organization_report_generation_status' do
76
+ let(:report_id) { 1 }
77
+
78
+ it 'when request are valid', :enterprise do
79
+ stub_request(:get, "https://domain.api.crowdin.com/#{target_api_url}/reports/#{report_id}")
80
+ check_organization_report_generation_status = @crowdin.check_organization_report_generation_status(report_id)
81
+ expect(check_organization_report_generation_status).to eq(200)
82
+ end
83
+ end
84
+
85
+ describe '#download_organization_report' do
86
+ let(:report_id) { 1 }
87
+
88
+ it 'when request are valid', :enterprise do
89
+ stub_request(:get, "https://domain.api.crowdin.com/#{target_api_url}/reports/#{report_id}/download")
90
+ download_organization_report = @crowdin.download_organization_report(report_id)
91
+ expect(download_organization_report).to eq(200)
92
+ end
93
+ end
94
+ end
95
+ end