1# frozen_string_literal: true
2
3require 'spec_helper'
4
5RSpec.describe ClusterSerializer do
6  let(:cluster) { create(:cluster, :project, provider_type: :user) }
7
8  describe '#represent_list' do
9    subject { described_class.new(current_user: nil).represent_list(cluster).keys }
10
11    it 'serializes attrs correctly' do
12      is_expected.to contain_exactly(
13        :cluster_type,
14        :enabled,
15        :environment_scope,
16        :id,
17        :gitlab_managed_apps_logs_path,
18        :enable_advanced_logs_querying,
19        :kubernetes_errors,
20        :name,
21        :nodes,
22        :path,
23        :provider_type,
24        :status)
25    end
26  end
27
28  describe '#represent_status' do
29    subject { described_class.new(current_user: nil).represent_status(cluster).keys }
30
31    context 'when provider type is gcp and cluster is errored' do
32      let(:cluster) do
33        errored_provider = create(:cluster_provider_gcp, :errored)
34
35        create(:cluster, provider_type: :gcp, provider_gcp: errored_provider)
36      end
37
38      it 'serializes attrs correctly' do
39        is_expected.to contain_exactly(:status, :status_reason, :applications)
40      end
41    end
42
43    context 'when provider type is user' do
44      it 'serializes attrs correctly' do
45        is_expected.to contain_exactly(:status, :status_reason, :applications)
46      end
47    end
48  end
49end
50