Skip to content

Commit

Permalink
test: Add Ruby test [TSI-2103] (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
jablan authored Oct 10, 2023
1 parent 991bf33 commit 0649086
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run RSpec tests
on: [push]
jobs:
run-rspec-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: |
npm install
npm run generate.ruby
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.1
# runs 'bundle install' and caches installed gems automatically
bundler-cache: true
working-directory: ./clients/ruby
- name: Run tests
run: |
cd ./clients/ruby
bundle exec rspec
27 changes: 24 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
clients/
!clients/cli/
clients/cli/api_*.go
clients/go/
clients/java/
clients/php/
clients/python/

clients/ruby/.*
clients/ruby/Gemfile*
clients/ruby/Rakefile
clients/ruby/README.md
clients/ruby/git_push.sh
clients/ruby/openapitools.json
clients/ruby/*.gemspec
clients/ruby/spec/*.rb
clients/ruby/spec/api/*
clients/ruby/spec/models/
clients/ruby/docs
clients/ruby/lib
clients/ruby/spec/api/*
!clients/ruby/spec/api/locales_api_spec.rb
!clients/ruby/spec/api/uploads_api_spec.rb

clients/typescript/
clients/cli/cmd/api_*.go
clients/cli/phrase-cli

doc/*.css
doc/*.css.map
Expand Down
250 changes: 250 additions & 0 deletions clients/ruby/spec/api/locales_api_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
require 'spec_helper'
require 'json'

# Unit tests for Phrase::LocalesApi
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
describe 'LocalesApi' do
before do
# run before each test
@api_instance = Phrase::LocalesApi.new
end

after do
# run after each test
end

describe 'test an instance of LocalesApi' do
it 'should create an instance of LocalesApi' do
expect(@api_instance).to be_instance_of(Phrase::LocalesApi)
end
end

# unit tests for account_locales
# List locales used in account
# List all locales unique by locale code used across all projects within an account.
# @param id ID
# @param [Hash] opts the optional parameters
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
# @option opts [Integer] :page Page number
# @option opts [Integer] :per_page Limit on the number of objects to be returned, between 1 and 100. 25 by default
# @return [Array<LocalePreview1>]
describe 'account_locales test' do
it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
end
end

# unit tests for locale_create
# Create a locale
# Create a new locale.
# @param project_id Project ID
# @param locale_create_parameters
# @param [Hash] opts the optional parameters
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
# @return [LocaleDetails]
describe 'locale_create test' do
it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
end
end

# unit tests for locale_delete
# Delete a locale
# Delete an existing locale.
# @param project_id Project ID
# @param id Locale ID or locale name
# @param [Hash] opts the optional parameters
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
# @option opts [String] :branch specify the branch to use
# @return [nil]
describe 'locale_delete test' do
it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
end
end

# unit tests for locale_download
# Download a locale
# Download a locale in a specific file format.
# @param project_id Project ID
# @param id Locale ID or locale name
# @param [Hash] opts the optional parameters
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
# @option opts [String] :if_modified_since Last modified condition, see &lt;a href&#x3D;\&quot;#overview--conditional-get-requests--http-caching\&quot;&gt;Conditional GET requests / HTTP Caching&lt;/a&gt; (optional)
# @option opts [String] :if_none_match ETag condition, see &lt;a href&#x3D;\&quot;#overview--conditional-get-requests--http-caching\&quot;&gt;Conditional GET requests / HTTP Caching&lt;/a&gt; (optional)
# @option opts [String] :branch specify the branch to use
# @option opts [String] :file_format File format name. See the &lt;a href&#x3D;\&quot;https://support.phrase.com/hc/en-us/sections/6111343326364\&quot;&gt;format guide&lt;/a&gt; for all supported file formats.
# @option opts [String] :tags Limit results to keys tagged with a list of comma separated tag names.
# @option opts [String] :tag Limit download to tagged keys. This parameter is deprecated. Please use the \&quot;tags\&quot; parameter instead
# @option opts [Boolean] :include_empty_translations Indicates whether keys without translations should be included in the output as well.
# @option opts [Boolean] :exclude_empty_zero_forms Indicates whether zero forms should be included when empty in pluralized keys.
# @option opts [Boolean] :include_translated_keys Include translated keys in the locale file. Use in combination with include_empty_translations to obtain only untranslated keys.
# @option opts [Boolean] :keep_notranslate_tags Indicates whether [NOTRANSLATE] tags should be kept.
# @option opts [Boolean] :convert_emoji This option is obsolete. Projects that were created on or after Nov 29th 2019 or that did not contain emoji by then will not require this flag any longer since emoji are now supported natively.
# @option opts [Object] :format_options Additional formatting and render options. See the &lt;a href&#x3D;\&quot;https://support.phrase.com/hc/en-us/sections/6111343326364\&quot;&gt;format guide&lt;/a&gt; for a list of options available for each format. Specify format options like this: &lt;code&gt;...&amp;format_options[foo]&#x3D;bar&lt;/code&gt;
# @option opts [String] :encoding Enforces a specific encoding on the file contents. Valid options are \&quot;UTF-8\&quot;, \&quot;UTF-16\&quot; and \&quot;ISO-8859-1\&quot;.
# @option opts [Boolean] :skip_unverified_translations Indicates whether the locale file should skip all unverified translations. This parameter is deprecated and should be replaced with &lt;code&gt;include_unverified_translations&lt;/code&gt;.
# @option opts [Boolean] :include_unverified_translations if set to false unverified translations are excluded
# @option opts [Boolean] :use_last_reviewed_version If set to true the last reviewed version of a translation is used. This is only available if the review workflow is enabled for the project.
# @option opts [String] :fallback_locale_id If a key has no translation in the locale being downloaded the translation in the fallback locale will be used. Provide the public ID of the locale that should be used as the fallback. Requires include_empty_translations to be set to &lt;code&gt;true&lt;/code&gt;.
# @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 &lt;code&gt;tag&lt;/code&gt; parameter indicating a specific job.
# @return [File]
describe 'locale_download test' do
let(:project_id) { 'project_id_example' }
let(:id) { 'id_example' }
let(:opts) { {
branch: 'branch_example',
format_options: {foo: 'bar'},
} }

before do
stub_request(:any, /.*phrase.com/)
.to_return(status: 200, body: "foo", headers: {
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="test.txt"',
})
end

it 'should work' do
locale = @api_instance.locale_download(project_id, id, opts)
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"}})).
to have_been_made

expect(locale).to be_instance_of(Phrase::Response)
expect(File.read(locale.data)).to eq("foo")
end
end

# unit tests for locale_show
# Get a single locale
# Get details on a single locale for a given project.
# @param project_id Project ID
# @param id Locale ID or locale name
# @param [Hash] opts the optional parameters
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
# @option opts [String] :branch specify the branch to use
# @return [LocaleDetails]
describe 'locale_show test' do
it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
end
end

# unit tests for locale_update
# Update a locale
# Update an existing locale.
# @param project_id Project ID
# @param id Locale ID or locale name
# @param locale_update_parameters
# @param [Hash] opts the optional parameters
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
# @return [LocaleDetails]
describe 'locale_update test' do
it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
end
end

# unit tests for locales_list
# List locales
# List all locales for the given project.
# @param project_id Project ID
# @param [Hash] opts the optional parameters
# @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
# @option opts [Integer] :page Page number
# @option opts [Integer] :per_page Limit on the number of objects to be returned, between 1 and 100. 25 by default
# @option opts [String] :sort_by Sort locales. Valid options are \&quot;name_asc\&quot;, \&quot;name_desc\&quot;, \&quot;default_asc\&quot;, \&quot;default_desc\&quot;.
# @option opts [String] :branch specify the branch to use
# @return [Array<Locale>]
describe 'locales_list test' do
let(:project_id) { 'project_id_example' }
let(:opts) { {
branch: 'branch_example',
} }
let(:response_body) {
<<-EOF
[
{
"id": "ae0ce77b64dbf7e8315b5da8ecbb42c0",
"name": "de-DE",
"code": "de-DE",
"default": false,
"main": false,
"rtl": false,
"plural_forms": [
"zero",
"one",
"other"
],
"created_at": "2022-10-27T11:03:39Z",
"updated_at": "2023-10-05T09:49:28Z",
"source_locale": null,
"fallback_locale": null
},
{
"id": "95060c3b178252e0c5d1936493e93108",
"name": "en-US",
"code": "en-US",
"default": true,
"main": false,
"rtl": false,
"plural_forms": [
"zero",
"one",
"other"
],
"created_at": "2022-10-27T11:03:39Z",
"updated_at": "2023-10-05T09:50:20Z",
"source_locale": null,
"fallback_locale": null
},
{
"id": "97b4b258d9000f256a97276561294b5b",
"name": "sh",
"code": "sr-Latn-RS",
"default": false,
"main": false,
"rtl": false,
"plural_forms": [
"zero",
"one",
"few",
"other"
],
"created_at": "2022-10-27T11:03:39Z",
"updated_at": "2023-05-10T08:22:18Z",
"source_locale": null,
"fallback_locale": null
}
]
EOF
}

before do
stub_request(:any, /.*phrase.com/)
.to_return(status: 200, body: response_body, headers: {
'Content-Type' => 'application/json'
})
end

it 'should work' do
locales = @api_instance.locales_list(project_id, opts)
expect(a_request(:get, "https://api.phrase.com/v2/projects/project_id_example/locales").with(query: {branch: "branch_example"})).
to have_been_made

expect(locales).to be_instance_of(Phrase::Response)
expect(locales.data).to be_instance_of(Array)
expect(locales.data.length).to eq(3)
expect(locales.data[0]).to be_instance_of(Phrase::Locale)
expect(locales.data[0].id).to eq("ae0ce77b64dbf7e8315b5da8ecbb42c0")
expect(locales.data[0].name).to eq("de-DE")
expect(locales.data[0].code).to eq("de-DE")
expect(locales.data[0].default).to eq(false)
expect(locales.data[0].plural_forms).to eq(["zero", "one", "other"])
expect(locales.data[0].created_at).to eq(DateTime.parse("2022-10-27T11:03:39Z"))
expect(locales.data[0].updated_at).to eq(DateTime.parse("2023-10-05T09:49:28Z"))
end
end

end
Loading

0 comments on commit 0649086

Please sign in to comment.