File: actors_spec.rb

package info (click to toggle)
ruby-flipper 0.26.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,288 kB
  • sloc: ruby: 16,377; sh: 61; javascript: 24; makefile: 14
file content (103 lines) | stat: -rw-r--r-- 2,508 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
RSpec.describe Flipper::Api::V1::Actions::Actors do
  let(:app) { build_api(flipper) }
  let(:actor) { Flipper::Actor.new('User123') }

  describe 'GET /actors/:flipper_id' do
    before do
      flipper[:my_feature_1].enable
      flipper[:my_feature_2].disable
      flipper[:my_feature_3].enable_actor(actor)
    end

    context 'when no feature is specified' do
      before do
        get "/actors/#{actor.flipper_id}"
      end

      it 'responds with success' do
        expect(last_response.status).to eq(200)
      end

      it 'returns all features' do
        expected_response = {
          'flipper_id' => 'User123',
          'features' => {
            'my_feature_1' => {
              'enabled' => true,
            },
            'my_feature_2' => {
              'enabled' => false,
            },
            'my_feature_3' => {
              'enabled' => true,
            },
          },
        }

        expect(json_response).to eq(expected_response)
      end
    end

    context 'when features are specified' do
      before do
        get "/actors/#{actor.flipper_id}", keys: "my_feature_2,my_feature_3"
      end

      it 'responds with success' do
        expect(last_response.status).to eq(200)
      end

      it 'returns all specified features' do
        expected_response = {
          'flipper_id' => 'User123',
          'features' => {
            'my_feature_2' => {
              'enabled' => false,
            },
            'my_feature_3' => {
              'enabled' => true,
            },
          },
        }

        expect(json_response).to eq(expected_response)
      end
    end

    context 'when non-existent features are specified' do
      before do
        get "/actors/#{actor.flipper_id}", keys: "my_feature_3,not_a_feature"
      end

      it 'responds with success' do
        expect(last_response.status).to eq(200)
      end

      it 'returns false for a non-existent feature' do
        expected_response = {
          'flipper_id' => 'User123',
          'features' => {
            'my_feature_3' => {
              'enabled' => true,
            },
            'not_a_feature' => {
              'enabled' => false,
            },
          },
        }

        expect(json_response).to eq(expected_response)
      end
    end

    context 'when flipper id is missing' do
      before do
        get "/actors"
      end

      it 'responds with a 404' do
        expect(last_response.status).to eq(404)
      end
    end
  end
end