From c8b5807bf1ece6182763efcab8439036edf61d74 Mon Sep 17 00:00:00 2001 From: Mladen Jablanovic Date: Tue, 10 Oct 2023 09:25:56 +0200 Subject: [PATCH] improve locale spec --- clients/ruby/spec/api/locales_api_spec.rb | 92 ++++++++++++++++++++++- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/clients/ruby/spec/api/locales_api_spec.rb b/clients/ruby/spec/api/locales_api_spec.rb index 49662f54..83924908 100644 --- a/clients/ruby/spec/api/locales_api_spec.rb +++ b/clients/ruby/spec/api/locales_api_spec.rb @@ -95,6 +95,7 @@ let(:id) { 'id_example' } let(:opts) { { branch: 'branch_example', + format_options: {foo: 'bar'}, } } before do @@ -107,10 +108,11 @@ 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") - expect(a_request(:get, "https://api.phrase.com/v2/projects/project_id_example/locales/id_example/download").with(query: {branch: "branch_example"})). - to have_been_made end end @@ -156,8 +158,92 @@ # @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 - # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + 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