github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/clients/ruby/spec/api/locales_api_spec.rb (about)

     1  require 'spec_helper'
     2  require 'json'
     3  
     4  # Unit tests for Phrase::LocalesApi
     5  # Automatically generated by openapi-generator (https://openapi-generator.tech)
     6  # Please update as you see appropriate
     7  describe 'LocalesApi' do
     8    before do
     9      # run before each test
    10      @api_instance = Phrase::LocalesApi.new
    11    end
    12  
    13    after do
    14      # run after each test
    15    end
    16  
    17    describe 'test an instance of LocalesApi' do
    18      it 'should create an instance of LocalesApi' do
    19        expect(@api_instance).to be_instance_of(Phrase::LocalesApi)
    20      end
    21    end
    22  
    23    # unit tests for account_locales
    24    # List locales used in account
    25    # List all locales unique by locale code used across all projects within an account.
    26    # @param id ID
    27    # @param [Hash] opts the optional parameters
    28    # @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
    29    # @option opts [Integer] :page Page number
    30    # @option opts [Integer] :per_page Limit on the number of objects to be returned, between 1 and 100. 25 by default
    31    # @return [Array<LocalePreview1>]
    32    describe 'account_locales test' do
    33      it 'should work' do
    34        # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
    35      end
    36    end
    37  
    38    # unit tests for locale_create
    39    # Create a locale
    40    # Create a new locale.
    41    # @param project_id Project ID
    42    # @param locale_create_parameters
    43    # @param [Hash] opts the optional parameters
    44    # @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
    45    # @return [LocaleDetails]
    46    describe 'locale_create test' do
    47      it 'should work' do
    48        # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
    49      end
    50    end
    51  
    52    # unit tests for locale_delete
    53    # Delete a locale
    54    # Delete an existing locale.
    55    # @param project_id Project ID
    56    # @param id Locale ID or locale name
    57    # @param [Hash] opts the optional parameters
    58    # @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
    59    # @option opts [String] :branch specify the branch to use
    60    # @return [nil]
    61    describe 'locale_delete test' do
    62      it 'should work' do
    63        # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
    64      end
    65    end
    66  
    67    # unit tests for locale_download
    68    # Download a locale
    69    # Download a locale in a specific file format.
    70    # @param project_id Project ID
    71    # @param id Locale ID or locale name
    72    # @param [Hash] opts the optional parameters
    73    # @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
    74    # @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)
    75    # @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)
    76    # @option opts [String] :branch specify the branch to use
    77    # @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.
    78    # @option opts [String] :tags Limit results to keys tagged with a list of comma separated tag names.
    79    # @option opts [String] :tag Limit download to tagged keys. This parameter is deprecated. Please use the \&quot;tags\&quot; parameter instead
    80    # @option opts [Boolean] :include_empty_translations Indicates whether keys without translations should be included in the output as well.
    81    # @option opts [Boolean] :exclude_empty_zero_forms Indicates whether zero forms should be included when empty in pluralized keys.
    82    # @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.
    83    # @option opts [Boolean] :keep_notranslate_tags Indicates whether [NOTRANSLATE] tags should be kept.
    84    # @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.
    85    # @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;
    86    # @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;.
    87    # @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;.
    88    # @option opts [Boolean] :include_unverified_translations if set to false unverified translations are excluded
    89    # @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.
    90    # @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 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;.
    91    # @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.
    92    # @return [File]
    93    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  
   109      it 'should work' do
   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")
   116      end
   117    end
   118  
   119    # unit tests for locale_show
   120    # Get a single locale
   121    # Get details on a single locale for a given project.
   122    # @param project_id Project ID
   123    # @param id Locale ID or locale name
   124    # @param [Hash] opts the optional parameters
   125    # @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
   126    # @option opts [String] :branch specify the branch to use
   127    # @return [LocaleDetails]
   128    describe 'locale_show test' do
   129      it 'should work' do
   130        # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
   131      end
   132    end
   133  
   134    # unit tests for locale_update
   135    # Update a locale
   136    # Update an existing locale.
   137    # @param project_id Project ID
   138    # @param id Locale ID or locale name
   139    # @param locale_update_parameters
   140    # @param [Hash] opts the optional parameters
   141    # @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
   142    # @return [LocaleDetails]
   143    describe 'locale_update test' do
   144      it 'should work' do
   145        # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
   146      end
   147    end
   148  
   149    # unit tests for locales_list
   150    # List locales
   151    # List all locales for the given project.
   152    # @param project_id Project ID
   153    # @param [Hash] opts the optional parameters
   154    # @option opts [String] :x_phrase_app_otp Two-Factor-Authentication token (optional)
   155    # @option opts [Integer] :page Page number
   156    # @option opts [Integer] :per_page Limit on the number of objects to be returned, between 1 and 100. 25 by default
   157    # @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;.
   158    # @option opts [String] :branch specify the branch to use
   159    # @return [Array<Locale>]
   160    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  
   231      it 'should work' do
   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"))
   247      end
   248    end
   249  
   250  end