|
77 | 77 | end
|
78 | 78 | end
|
79 | 79 |
|
80 |
| - describe 'POST /organizations/:organization_id/users' do |
81 |
| - let(:michael) { create(:user, first_name: 'Michael') } |
82 |
| - |
83 |
| - let(:new_organization_user_params) do |
84 |
| - { |
85 |
| - organization_id: good_place.id, |
86 |
| - id: michael.id |
87 |
| - } |
88 |
| - end |
89 |
| - |
90 |
| - it 'renders 401 if unauthenticated' do |
91 |
| - post :create, params: new_organization_user_params |
92 |
| - expect(response).to have_http_status(401) |
93 |
| - end |
94 |
| - |
95 |
| - it 'renders 401 if organization does not exist' do |
96 |
| - set_auth_header(chidi) |
97 |
| - post :create, params: { |
98 |
| - **new_organization_user_params, |
99 |
| - organization_id: '37e485b8-65e5-4502-a8aa-5217dd3160c3' |
100 |
| - } |
101 |
| - |
102 |
| - expect(response).to have_http_status(401) |
103 |
| - end |
104 |
| - |
105 |
| - it 'renders 401 if user does not exist' do |
106 |
| - set_auth_header(chidi) |
107 |
| - post :create, params: { |
108 |
| - **new_organization_user_params, |
109 |
| - id: 'dc846e2f-a86a-4e78-b217-6517a8bbca00' |
110 |
| - } |
111 |
| - |
112 |
| - expect(response).to have_http_status(401) |
113 |
| - end |
114 |
| - |
115 |
| - it 'renders 401 if not member of organization' do |
116 |
| - shawn = User.find_by!(first_name: 'Shawn') |
117 |
| - set_auth_header(shawn) |
118 |
| - post :create, params: new_organization_user_params |
119 |
| - |
120 |
| - expect(response).to have_http_status(401) |
121 |
| - end |
122 |
| - |
123 |
| - it 'renders 201 with added organization user' do |
124 |
| - set_auth_header(chidi) |
125 |
| - post :create, params: new_organization_user_params |
126 |
| - |
127 |
| - expect(response).to have_http_status(201) |
128 |
| - expect(JSON.parse(response.body).keys).to contain_exactly(*user_fields) |
129 |
| - expect(JSON.parse(response.body)).to match( |
130 |
| - a_hash_including( |
131 |
| - 'id' => michael.id, |
132 |
| - 'created_at' => michael.created_at.iso8601(3), |
133 |
| - 'updated_at' => michael.updated_at.iso8601(3), |
134 |
| - 'email' => michael.email, |
135 |
| - 'first_name' => michael.first_name, |
136 |
| - 'last_name' => michael.last_name |
137 |
| - ) |
138 |
| - ) |
139 |
| - end |
140 |
| - |
141 |
| - it 'renders 200 when user is already in organization' do |
142 |
| - set_auth_header(chidi) |
143 |
| - |
144 |
| - post :create, params: new_organization_user_params |
145 |
| - expect(response).to have_http_status(201) |
146 |
| - |
147 |
| - post :create, params: new_organization_user_params |
148 |
| - expect(response).to have_http_status(200) |
149 |
| - |
150 |
| - expect(OrganizationUser.where(organization_id: good_place.id).count).to eq(3) |
151 |
| - end |
152 |
| - end |
153 |
| - |
154 |
| - describe 'GET /organizations/:organization_id/users/:id' do |
155 |
| - it 'renders 401 if unauthenticated' do |
156 |
| - get :show, params: { organization_id: good_place.id, id: chidi.id } |
157 |
| - expect(response).to have_http_status(401) |
158 |
| - end |
159 |
| - |
160 |
| - it 'renders 401 if organization does not exist' do |
161 |
| - set_auth_header(chidi) |
162 |
| - get :show, params: { organization_id: '43698687-16b4-4c23-939d-a2a8e8b8b6b1', id: chidi.id } |
163 |
| - |
164 |
| - expect(response).to have_http_status(401) |
165 |
| - end |
166 |
| - |
167 |
| - it 'renders 401 if user does not exist' do |
168 |
| - set_auth_header(chidi) |
169 |
| - get :show, params: { organization_id: good_place, id: '351b7cbe-c753-445f-a4dc-c24597ab923e' } |
170 |
| - |
171 |
| - expect(response).to have_http_status(401) |
172 |
| - end |
173 |
| - |
174 |
| - it 'renders 401 if requested user is not member of organization' do |
175 |
| - shawn = User.find_by!(first_name: 'Shawn') |
176 |
| - set_auth_header(chidi) |
177 |
| - get :show, params: { organization_id: good_place, id: shawn.id } |
178 |
| - |
179 |
| - expect(response).to have_http_status(401) |
180 |
| - end |
181 |
| - |
182 |
| - it 'renders 401 if authenticated user is not member of organization' do |
183 |
| - shawn = User.find_by!(first_name: 'Shawn') |
184 |
| - set_auth_header(shawn) |
185 |
| - get :show, params: { organization_id: good_place.id, id: chidi.id } |
186 |
| - |
187 |
| - expect(response).to have_http_status(401) |
188 |
| - end |
189 |
| - |
190 |
| - it 'renders 200 with organization user' do |
191 |
| - set_auth_header(chidi) |
192 |
| - get :show, params: { organization_id: good_place.id, id: chidi.id } |
193 |
| - |
194 |
| - expect(response).to have_http_status(200) |
195 |
| - expect(JSON.parse(response.body).keys).to contain_exactly(*user_fields) |
196 |
| - expect(JSON.parse(response.body)).to match( |
197 |
| - a_hash_including( |
198 |
| - 'id' => chidi.id, |
199 |
| - 'created_at' => chidi.created_at.iso8601(3), |
200 |
| - 'updated_at' => chidi.updated_at.iso8601(3), |
201 |
| - 'email' => chidi.email, |
202 |
| - 'first_name' => chidi.first_name, |
203 |
| - 'last_name' => chidi.last_name |
204 |
| - ) |
205 |
| - ) |
206 |
| - end |
207 |
| - end |
208 |
| - |
209 | 80 | describe 'DELETE /organizations/:organization_id/users/:id' do
|
210 | 81 | before do
|
211 | 82 | allow_any_instance_of(OrganizationUserPolicy).to receive(:destroy?).and_return(true)
|
|
0 commit comments