# Copyright 2022 Daniel Herzog # Use of this source code is governed by an MIT # license that can be found in the LICENSE.md file. # frozen_string_literal: true require 'spec_helper' describe DeepL::Requests::Glossary::List do subject(:glossary_list) { described_class.new(api, options) } around do |tests| tmp_env = replace_env_preserving_deepl_vars_except_mock_server tests.call ENV.replace(tmp_env) end let(:api) { build_deepl_api } let(:options) { {} } describe '#initialize' do context 'when building a request' do it 'creates a request object' do expect(glossary_list).to be_a(described_class) end end end describe '#request' do around do |example| VCR.use_cassette('glossaries') { example.call } end context 'when requesting a list of all glossaries' do it 'returns a glossaries object' do glossaries = glossary_list.request expect(glossaries).to be_an(Array) end end context 'when performing a bad request' do context 'when using an invalid token' do let(:api) do api = build_deepl_api api.configuration.auth_key = 'invalid' api end it 'raises an unauthorized error' do expect { glossary_list.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed) end end end end end