-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add Ruby test [TSI-2103] (#419)
- Loading branch information
Showing
6 changed files
with
395 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <a href=\"#overview--conditional-get-requests--http-caching\">Conditional GET requests / HTTP Caching</a> (optional) | ||
# @option opts [String] :if_none_match ETag condition, see <a href=\"#overview--conditional-get-requests--http-caching\">Conditional GET requests / HTTP Caching</a> (optional) | ||
# @option opts [String] :branch specify the branch to use | ||
# @option opts [String] :file_format File format name. See the <a href=\"https://support.phrase.com/hc/en-us/sections/6111343326364\">format guide</a> 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 \"tags\" 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 <a href=\"https://support.phrase.com/hc/en-us/sections/6111343326364\">format guide</a> for a list of options available for each format. Specify format options like this: <code>...&format_options[foo]=bar</code> | ||
# @option opts [String] :encoding Enforces a specific encoding on the file contents. Valid options are \"UTF-8\", \"UTF-16\" and \"ISO-8859-1\". | ||
# @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 <code>include_unverified_translations</code>. | ||
# @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 <code>true</code>. | ||
# @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. | ||
# @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 \"name_asc\", \"name_desc\", \"default_asc\", \"default_desc\". | ||
# @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 |
Oops, something went wrong.