Skip to content

Commit

Permalink
improve locale spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jablan committed Oct 10, 2023
1 parent ba84c3a commit c8b5807
Showing 1 changed file with 89 additions and 3 deletions.
92 changes: 89 additions & 3 deletions clients/ruby/spec/api/locales_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
let(:id) { 'id_example' }
let(:opts) { {
branch: 'branch_example',
format_options: {foo: 'bar'},
} }

before do
Expand All @@ -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

Expand Down Expand Up @@ -156,8 +158,92 @@
# @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
# 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

Expand Down

0 comments on commit c8b5807

Please sign in to comment.