|
146 | 146 | # rubocop:todo RSpec/MultipleMemoizedHelpers
|
147 | 147 | context 'as admin' do # rubocop:todo RSpec/ContextWording, RSpec/MultipleMemoizedHelpers
|
148 | 148 | let(:admin) { token.admin }
|
| 149 | + let(:ctid) { "ce-#{SecureRandom.uuid}" } |
149 | 150 | let(:description) { Faker::Lorem.sentence }
|
150 | 151 | let(:name) { Faker::Company.name }
|
151 | 152 | let(:token) { create(:auth_token, :admin) }
|
152 | 153 |
|
153 | 154 | before do
|
154 | 155 | post '/metadata/organizations',
|
155 | 156 | {
|
| 157 | + _ctid: ctid, |
156 | 158 | name: name,
|
157 | 159 | description: description
|
158 | 160 | },
|
|
172 | 174 | end
|
173 | 175 | # rubocop:enable RSpec/MultipleMemoizedHelpers
|
174 | 176 |
|
| 177 | + context 'invalid CTID' do # rubocop:todo RSpec/ContextWording, RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups |
| 178 | + let(:ctid) { SecureRandom.uuid } |
| 179 | + |
| 180 | + it 'returns 422' do |
| 181 | + expect_status(:unprocessable_entity) |
| 182 | + expect_json('error', 'Ctid is invalid') |
| 183 | + end |
| 184 | + end |
| 185 | + |
175 | 186 | # rubocop:todo RSpec/MultipleMemoizedHelpers
|
176 | 187 | # rubocop:todo RSpec/NestedGroups
|
177 | 188 | context 'valid params' do # rubocop:todo RSpec/ContextWording, RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups
|
178 |
| - # rubocop:enable RSpec/NestedGroups |
179 |
| - it do |
180 |
| - organization = Organization.order(:created_at).last |
181 |
| - expect(organization.admin).to eq(admin) |
182 |
| - expect(organization.description).to eq(description) |
183 |
| - expect(organization.name).to eq(name) |
184 |
| - expect_status(:created) |
185 |
| - expect_json('id', organization.id) |
186 |
| - expect_json('description', organization.description) |
187 |
| - expect_json('name', organization.name) |
| 189 | + context 'without CTID' do |
| 190 | + let(:ctid) { nil } |
| 191 | + # rubocop:enable RSpec/NestedGroups |
| 192 | + |
| 193 | + it 'creates an organization with a generated CTID' do |
| 194 | + organization = Organization.order(:created_at).last |
| 195 | + expect(organization.admin).to eq(admin) |
| 196 | + expect(organization.description).to eq(description) |
| 197 | + expect(organization.name).to eq(name) |
| 198 | + expect_status(:created) |
| 199 | + expect_json('_ctid', organization._ctid) |
| 200 | + expect_json('id', organization.id) |
| 201 | + expect_json('description', organization.description) |
| 202 | + expect_json('name', organization.name) |
| 203 | + end |
| 204 | + end |
| 205 | + |
| 206 | + context 'with CTID' do # rubocop:todo RSpec/NestedGroups |
| 207 | + it 'creates an organization' do # rubocop:todo RSpec/MultipleExpectations |
| 208 | + organization = Organization.order(:created_at).last |
| 209 | + expect(organization._ctid).to eq(ctid) |
| 210 | + expect(organization.admin).to eq(admin) |
| 211 | + expect(organization.description).to eq(description) |
| 212 | + expect(organization.name).to eq(name) |
| 213 | + expect_status(:created) |
| 214 | + expect_json('_ctid', organization._ctid) |
| 215 | + expect_json('id', organization.id) |
| 216 | + expect_json('description', organization.description) |
| 217 | + expect_json('name', organization.name) |
| 218 | + end |
188 | 219 | end
|
189 | 220 | end
|
190 | 221 | # rubocop:enable RSpec/MultipleMemoizedHelpers
|
|
0 commit comments