-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfeatures_spec.rb
More file actions
118 lines (88 loc) · 2.84 KB
/
features_spec.rb
File metadata and controls
118 lines (88 loc) · 2.84 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe "Features", type: :request do
let(:headers) { { Authorization: UserProfileMock::TOKEN } }
let!(:school_class) { create(:school_class, teacher_ids: [teacher.id], school:) }
let(:school) { create(:school) }
let(:student) { create(:student, school:) }
let(:teacher) { create(:teacher, school:) }
let(:admin_user) { create(:admin_user) }
describe "Feature flag API" do
it "returns a globally-disabled feature as disabled" do
# Arrange
Flipper.disable :some_global_feature
# Act
get "/api/features"
# Assert
expect(response.body).not_to include('some_global_feature')
end
it "returns a globally-enabled feature as enabled" do
# Arrange
Flipper.enable :some_global_feature
# Act
get "/api/features"
# Assert
expect(response.body).to include('some_global_feature')
end
it "returns a school-level feature as disabled for logged-out user" do
# Arrange
Flipper.enable_actor :some_school_level_feature, school
# Act
get "/api/features"
# Assert
expect(response.body).not_to include('some_school_level_feature')
end
it "returns a school-level feature as enabled for a student in that school" do
# Arrange
authenticated_in_hydra_as(student)
Flipper.enable_actor :some_school_level_feature, school
# Act
get "/api/features", headers: headers
# Assert
expect(response.body).to include('some_school_level_feature')
end
it "returns both school-level and global features as enabled for a student in a school" do
# Arrange
authenticated_in_hydra_as(student)
Flipper.enable_actor :some_school_level_feature, school
Flipper.enable :some_global_feature
# Act
get "/api/features", headers: headers
# Assert
expect(response.body).to include('some_school_level_feature')
expect(response.body).to include('some_global_feature')
end
end
describe "Feature flag web interface" do
it "is hidden from unauthenticated users" do
# Act
get "/admin/flipper/features"
# Assert
expect(response).to have_http_status(:not_found)
end
it "is hidden from student users" do
# Arrange
sign_in student
# Act
get "/admin/flipper/features"
# Assert
expect(response).to have_http_status(:not_found)
end
it "is hidden from teacher users" do
# Arrange
sign_in teacher
# Act
get "/admin/flipper/features"
# Assert
expect(response).to have_http_status(:not_found)
end
it "is visible to admins" do
# Arrange
sign_in admin_user
# Act
get "/admin/flipper/features"
# Assert
expect(response).to have_http_status(:success)
end
end
end