Skip to content

Commit 52cd9fd

Browse files
author
Phrase
committed
Deploying from phrase/openapi@0649086c
1 parent ef25044 commit 52cd9fd

File tree

4 files changed

+125
-5
lines changed

4 files changed

+125
-5
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ group :development, :test do
66
gem 'rake', '~> 13.0.1'
77
gem 'pry-byebug'
88
gem 'rubocop', '~> 0.66.0'
9+
gem 'webmock'
910
end

spec/api/locales_api_spec.rb

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# Create a locale
4040
# Create a new locale.
4141
# @param project_id Project ID
42-
# @param locale_create_parameters
42+
# @param locale_create_parameters
4343
# @param [Hash] opts the optional parameters
4444
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
4545
# @return [LocaleDetails]
@@ -91,8 +91,28 @@
9191
# @option opts [String] :source_locale_id Provides the source language of a corresponding job as the source language of the generated locale file. This parameter will be ignored unless used in combination with a <code>tag</code> parameter indicating a specific job.
9292
# @return [File]
9393
describe 'locale_download test' do
94+
let(:project_id) { 'project_id_example' }
95+
let(:id) { 'id_example' }
96+
let(:opts) { {
97+
branch: 'branch_example',
98+
format_options: {foo: 'bar'},
99+
} }
100+
101+
before do
102+
stub_request(:any, /.*phrase.com/)
103+
.to_return(status: 200, body: "foo", headers: {
104+
'Content-Type' => 'application/octet-stream',
105+
'Content-Disposition' => 'attachment; filename="test.txt"',
106+
})
107+
end
108+
94109
it 'should work' do
95-
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
110+
locale = @api_instance.locale_download(project_id, id, opts)
111+
expect(a_request(:get, "https://api.phrase.com/v2/projects/project_id_example/locales/id_example/download").with(query: {branch: "branch_example", format_options: {foo: "bar"}})).
112+
to have_been_made
113+
114+
expect(locale).to be_instance_of(Phrase::Response)
115+
expect(File.read(locale.data)).to eq("foo")
96116
end
97117
end
98118

@@ -116,7 +136,7 @@
116136
# Update an existing locale.
117137
# @param project_id Project ID
118138
# @param id Locale ID or locale name
119-
# @param locale_update_parameters
139+
# @param locale_update_parameters
120140
# @param [Hash] opts the optional parameters
121141
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
122142
# @return [LocaleDetails]
@@ -138,8 +158,92 @@
138158
# @option opts [String] :branch specify the branch to use
139159
# @return [Array<Locale>]
140160
describe 'locales_list test' do
161+
let(:project_id) { 'project_id_example' }
162+
let(:opts) { {
163+
branch: 'branch_example',
164+
} }
165+
let(:response_body) {
166+
<<-EOF
167+
[
168+
{
169+
"id": "ae0ce77b64dbf7e8315b5da8ecbb42c0",
170+
"name": "de-DE",
171+
"code": "de-DE",
172+
"default": false,
173+
"main": false,
174+
"rtl": false,
175+
"plural_forms": [
176+
"zero",
177+
"one",
178+
"other"
179+
],
180+
"created_at": "2022-10-27T11:03:39Z",
181+
"updated_at": "2023-10-05T09:49:28Z",
182+
"source_locale": null,
183+
"fallback_locale": null
184+
},
185+
{
186+
"id": "95060c3b178252e0c5d1936493e93108",
187+
"name": "en-US",
188+
"code": "en-US",
189+
"default": true,
190+
"main": false,
191+
"rtl": false,
192+
"plural_forms": [
193+
"zero",
194+
"one",
195+
"other"
196+
],
197+
"created_at": "2022-10-27T11:03:39Z",
198+
"updated_at": "2023-10-05T09:50:20Z",
199+
"source_locale": null,
200+
"fallback_locale": null
201+
},
202+
{
203+
"id": "97b4b258d9000f256a97276561294b5b",
204+
"name": "sh",
205+
"code": "sr-Latn-RS",
206+
"default": false,
207+
"main": false,
208+
"rtl": false,
209+
"plural_forms": [
210+
"zero",
211+
"one",
212+
"few",
213+
"other"
214+
],
215+
"created_at": "2022-10-27T11:03:39Z",
216+
"updated_at": "2023-05-10T08:22:18Z",
217+
"source_locale": null,
218+
"fallback_locale": null
219+
}
220+
]
221+
EOF
222+
}
223+
224+
before do
225+
stub_request(:any, /.*phrase.com/)
226+
.to_return(status: 200, body: response_body, headers: {
227+
'Content-Type' => 'application/json'
228+
})
229+
end
230+
141231
it 'should work' do
142-
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
232+
locales = @api_instance.locales_list(project_id, opts)
233+
expect(a_request(:get, "https://api.phrase.com/v2/projects/project_id_example/locales").with(query: {branch: "branch_example"})).
234+
to have_been_made
235+
236+
expect(locales).to be_instance_of(Phrase::Response)
237+
expect(locales.data).to be_instance_of(Array)
238+
expect(locales.data.length).to eq(3)
239+
expect(locales.data[0]).to be_instance_of(Phrase::Locale)
240+
expect(locales.data[0].id).to eq("ae0ce77b64dbf7e8315b5da8ecbb42c0")
241+
expect(locales.data[0].name).to eq("de-DE")
242+
expect(locales.data[0].code).to eq("de-DE")
243+
expect(locales.data[0].default).to eq(false)
244+
expect(locales.data[0].plural_forms).to eq(["zero", "one", "other"])
245+
expect(locales.data[0].created_at).to eq(DateTime.parse("2022-10-27T11:03:39Z"))
246+
expect(locales.data[0].updated_at).to eq(DateTime.parse("2023-10-05T09:49:28Z"))
143247
end
144248
end
145249

spec/api/uploads_api_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,22 @@
4444
# @option opts [Boolean] :tag_only_affected_keys Indicates whether only keys affected (created or updated) by the upload should be tagged. The default is &#x60;false&#x60;
4545
# @return [Upload]
4646
describe 'upload_create test' do
47+
let(:response_body) { { data: {} }.to_json }
48+
before do
49+
stub_request(:any, /.*phrase.com/)
50+
.to_return(status: 200, body: response_body, headers: {
51+
'Content-Type' => 'application/json'
52+
})
53+
end
54+
4755
it 'should work' do
48-
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
56+
@api_instance.upload_create('project_id', file: File.new('Gemfile'))
57+
58+
expect(a_request(:post, 'https://api.phrase.com/v2/projects/project_id/uploads')
59+
.with { |req|
60+
expect(req.headers['Content-Type']).to eq('multipart/form-data')
61+
# expect(req.body).to include('Gemfile')
62+
}).to have_been_made
4963
end
5064
end
5165

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# load the gem
22
require 'phrase'
3+
require 'webmock/rspec'
34

45
# The following was generated by the `rspec --init` command. Conventionally, all
56
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.

0 commit comments

Comments
 (0)