Sha256: b692abecad1c35308cc406182266b4d3bb7936ba7c46cf9214d969d7e5d922a9

Contents?: true

Size: 1.72 KB

Versions: 5

Compression:

Stored size: 1.72 KB

Contents

describe Bisu::Source::Tolgee do
  subject(:to_i18) { Bisu::Source::Tolgee.new(api_key).to_i18 }

  let(:api_key)    { "a123" }
  let(:os_response) { File.read("spec/fixtures/sample_tolgee_response.zip") }

  def stub_url(status:, response:, host: "app.tolgee.io")
    stub_request(:get, "https://#{host}/v2/projects/export?format=JSON&structureDelimiter=").
      to_return(:status => status, :body => response, :headers => {})
  end

  before { stub_url(status: 200, response: os_response) }

  it { expect { to_i18 }.not_to raise_error }

  it "returns an hash in i18 format" do
    expect(to_i18).to eq({
      "en" => { "kConnectFacebook" => "Connect with Facebook", "kNoNoNoMr" => "No, no, no. Mr %{name} not here" },
      "ja" => { "kConnectFacebook" => "フェイスブックへ接続" },
      "fr" => { "kConnectFacebook" => "Connexion par Facebook" },
      "de" => { "kConnectFacebook" => "Mit Facebook verbinden" },
      "ko" => { "kConnectFacebook" => "페이스북으로 접속", "kTwitterServer" => "트위터 서버연결 실패. \\n잠시 후 재시도." }
    })
  end

  context "when get request to that URL raises an error" do
    before { stub_url(status: 400, response: { error: "ups... not allowed!" }.to_json) }

    it "raises that same error" do
      expect { to_i18 }.to raise_error /not allowed/
    end
  end

  context "with a custom host" do
    let(:host) { "translations.example.com" }
    subject(:to_i18) { Bisu::Source::Tolgee.new(api_key, host).to_i18 }

    before { stub_url(status: 200, response: os_response, host: host) }

    it "uses that host" do
      to_i18
      expect(WebMock).to have_requested(:get, "https://translations.example.com/v2/projects/export?format=JSON&structureDelimiter=")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bisu-2.4.0 spec/lib/bisu/source/tolgee_spec.rb
bisu-2.3.0 spec/lib/bisu/source/tolgee_spec.rb
bisu-2.2.0 spec/lib/bisu/source/tolgee_spec.rb
bisu-2.1.0 spec/lib/bisu/source/tolgee_spec.rb
bisu-2.0.0 spec/lib/bisu/source/tolgee_spec.rb