From 0649086c3662bca16b15de71b277a2cfe066fa1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mladen=20Jablanovi=C4=87?= Date: Tue, 10 Oct 2023 13:39:21 +0200 Subject: [PATCH] test: Add Ruby test [TSI-2103] (#419) --- .github/workflows/test.yml | 22 ++ .gitignore | 27 +- clients/ruby/spec/api/locales_api_spec.rb | 250 ++++++++++++++++++ clients/ruby/spec/api/uploads_api_spec.rb | 97 +++++++ .../templates/ruby-client/Gemfile.mustache | 1 + .../ruby-client/spec_helper.mustache | 1 + 6 files changed, 395 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 clients/ruby/spec/api/locales_api_spec.rb create mode 100644 clients/ruby/spec/api/uploads_api_spec.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..010d81cb --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/.gitignore b/.gitignore index 1049b813..7bcc9c19 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/clients/ruby/spec/api/locales_api_spec.rb b/clients/ruby/spec/api/locales_api_spec.rb new file mode 100644 index 00000000..83924908 --- /dev/null +++ b/clients/ruby/spec/api/locales_api_spec.rb @@ -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] + 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] + 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 diff --git a/clients/ruby/spec/api/uploads_api_spec.rb b/clients/ruby/spec/api/uploads_api_spec.rb new file mode 100644 index 00000000..82f4ce21 --- /dev/null +++ b/clients/ruby/spec/api/uploads_api_spec.rb @@ -0,0 +1,97 @@ +require 'spec_helper' +require 'json' + +# Unit tests for Phrase::UploadsApi +# Automatically generated by openapi-generator (https://openapi-generator.tech) +# Please update as you see appropriate +describe 'UploadsApi' do + before do + # run before each test + @api_instance = Phrase::UploadsApi.new + end + + after do + # run after each test + end + + describe 'test an instance of UploadsApi' do + it 'should create an instance of UploadsApi' do + expect(@api_instance).to be_instance_of(Phrase::UploadsApi) + end + end + + # unit tests for upload_create + # Upload a new file + # Upload a new language file. Creates necessary resources in your 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 [String] :branch specify the branch to use + # @option opts [File] :file File to be imported + # @option opts [String] :file_format File format. Auto-detected when possible and not specified. + # @option opts [String] :locale_id Locale of the file's content. Can be the name or public id of the locale. Preferred is the public id. + # @option opts [String] :tags List of tags separated by comma to be associated with the new keys contained in the upload. + # @option opts [Boolean] :update_translations Indicates whether existing translations should be updated with the file content. + # @option opts [Boolean] :update_descriptions Existing key descriptions will be updated with the file content. Empty descriptions overwrite existing descriptions. + # @option opts [Boolean] :convert_emoji This option is obsolete. Providing the option will cause a bad request error. + # @option opts [Boolean] :skip_upload_tags Indicates whether the upload should not create upload tags. + # @option opts [Boolean] :skip_unverification Indicates whether the upload should unverify updated translations. + # @option opts [String] :file_encoding Enforces a specific encoding on the file contents. Valid options are \\\"UTF-8\\\", \\\"UTF-16\\\" and \\\"ISO-8859-1\\\". + # @option opts [Object] :locale_mapping Optional, format specific mapping between locale names and the columns the translations to those locales are contained in. + # @option opts [Object] :format_options Additional options available for specific formats. See our format guide for complete list. + # @option opts [Boolean] :autotranslate If set, translations for the uploaded language will be fetched automatically. + # @option opts [Boolean] :mark_reviewed Indicated whether the imported translations should be marked as reviewed. This setting is available if the review workflow is enabled for the project. + # @option opts [Boolean] :tag_only_affected_keys Indicates whether only keys affected (created or updated) by the upload should be tagged. The default is `false` + # @return [Upload] + describe 'upload_create test' do + let(:response_body) { { data: {} }.to_json } + before do + stub_request(:any, /.*phrase.com/) + .to_return(status: 200, body: response_body, headers: { + 'Content-Type' => 'application/json' + }) + end + + it 'should work' do + @api_instance.upload_create('project_id', file: File.new('Gemfile')) + + expect(a_request(:post, 'https://api.phrase.com/v2/projects/project_id/uploads') + .with { |req| + expect(req.headers['Content-Type']).to eq('multipart/form-data') + # expect(req.body).to include('Gemfile') + }).to have_been_made + end + end + + # unit tests for upload_show + # Get a single upload + # View details and summary for a single upload. + # @param project_id Project ID + # @param id ID + # @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 [Upload] + describe 'upload_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 uploads_list + # List uploads + # List all uploads 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] :branch specify the branch to use + # @return [Array] + describe 'uploads_list test' do + it 'should work' do + # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + end + end + +end diff --git a/openapi-generator/templates/ruby-client/Gemfile.mustache b/openapi-generator/templates/ruby-client/Gemfile.mustache index c2e3127c..794aff39 100644 --- a/openapi-generator/templates/ruby-client/Gemfile.mustache +++ b/openapi-generator/templates/ruby-client/Gemfile.mustache @@ -6,4 +6,5 @@ group :development, :test do gem 'rake', '~> 13.0.1' gem 'pry-byebug' gem 'rubocop', '~> 0.66.0' + gem 'webmock' end diff --git a/openapi-generator/templates/ruby-client/spec_helper.mustache b/openapi-generator/templates/ruby-client/spec_helper.mustache index bc4187c3..14ed7368 100644 --- a/openapi-generator/templates/ruby-client/spec_helper.mustache +++ b/openapi-generator/templates/ruby-client/spec_helper.mustache @@ -1,5 +1,6 @@ # load the gem require '{{{gemName}}}' +require 'webmock/rspec' # The following was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.