validate provided json in contract

pull/7914/head
ulferts 5 years ago
parent fb965ca52d
commit 8dc0845002
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 223
      modules/bcf/app/contracts/bcf/viewpoints/create_contract.rb
  2. 16
      modules/bcf/config/locales/en.yml
  3. 847
      modules/bcf/spec/contracts/bcf/viewpoints/create_contract_spec.rb
  4. 6
      modules/bcf/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb
  5. 2
      modules/bcf/spec/services/bcf/viewpoints/set_attributes_service_spec.rb

@ -32,16 +32,235 @@ module Bcf::Viewpoints
class CreateContract < ::ModelContract
include Bcf::Concerns::ManageBcfGuarded
WHITELISTED_PROPERTIES = %w(index
snapshot
orthogonal_camera
perspective_camera
clipping_planes
bitmaps
lines
components).freeze
ORTHOGONAL_CAMERA_PROPERTIES = %w(camera_view_point
camera_direction
camera_up_vector
view_to_world_scale).freeze
PERSPECTIVE_CAMERA_PROPERTIES = %w(camera_view_point
camera_direction
camera_up_vector
field_of_view).freeze
LINES_PROPERTIES = %w(start_point
end_point).freeze
CLIPPING_PLANES_PROPERTIES = %w(location
direction).freeze
COMPONENTS_PROPERTIES = %w(visibility
selection
coloring).freeze
COMPONENT_PROPERTIES = %w(ifc_guid
originating_system
authoring_tool_id).freeze
COLORING_PROPERTIES = %w(color
components).freeze
VISIBILITY_PROPERTIES = %w(default_visibility
exceptions
view_setup_hints).freeze
VIEW_SETUP_HINTS_PROPERTIES = %w(spaces_visible
space_boundaries_visible
openings_visible).freeze
COLOR_REGEXP = /#([0-9a-f]{2})?[0-9a-f]{6}/.freeze
WHITELISTED_DIMENSIONS = %w(x y z).freeze
attribute :uuid
attribute :issue
attribute :json_viewpoint do
validate_json_viewpoint_present
validate_json_viewpoint_hash
next if errors.any?
validate_properties
validate_snapshot
validate_index
validate_orthogonal_camera
validate_perspective_camera
validate_lines
validate_clipping_planes
validate_bitmaps
validate_components
end
def validate_json_viewpoint_present
unless model.json_viewpoint.present?
errors.add(:json_viewpoint, :blank)
errors.add(:json_viewpoint, :blank) unless viewpoint.present?
end
def validate_json_viewpoint_hash
errors.add(:base, :no_json) if viewpoint.present? && !viewpoint.is_a?(Hash)
end
def validate_properties
errors.add(:base, :unsupported_key) if viewpoint.present? && (viewpoint.keys - WHITELISTED_PROPERTIES).any?
end
def validate_snapshot
return unless (sjson = viewpoint['snapshot'])
errors.add(:base, :snapshot_type_unsupported) unless %w(jpg png).include? sjson['snapshot_type']
errors.add(:base, :snapshot_data_blank) unless sjson['snapshot_data'].present?
end
def validate_index
return unless (ijson = viewpoint['index'])
errors.add(:base, :index_not_integer) unless ijson.is_a? Integer
end
def validate_orthogonal_camera
return unless (ocjson = viewpoint['orthogonal_camera'])
if ocjson.keys != ORTHOGONAL_CAMERA_PROPERTIES ||
ocjson.except('view_to_world_scale').any? { |_, direction| invalid_direction?(direction) } ||
!ocjson['view_to_world_scale'].is_a?(Float)
errors.add(:base, :invalid_orthogonal_camera)
end
end
def validate_perspective_camera
return unless (pcjson = viewpoint['perspective_camera'])
if pcjson.keys != PERSPECTIVE_CAMERA_PROPERTIES ||
pcjson.except('field_of_view').any? { |_, direction| invalid_direction?(direction) } ||
!pcjson['field_of_view'].is_a?(Float)
errors.add(:base, :invalid_perspective_camera)
end
end
def validate_lines
return unless (ljson = viewpoint['lines'])
if !ljson.is_a?(Array) ||
ljson.any? { |line| invalid_line?(line) }
errors.add(:base, :invalid_lines)
end
end
def validate_clipping_planes
return unless (cpjson = viewpoint['clipping_planes'])
if !cpjson.is_a?(Array) ||
cpjson.any? { |cp| invalid_clipping_plane?(cp) }
errors.add(:base, :invalid_clipping_planes)
end
end
def validate_bitmaps
errors.add(:base, :bitmaps_not_writable) if viewpoint['bitmaps']
end
def validate_components
return unless (cjson = viewpoint['components'])
if !cjson.is_a?(Hash) ||
invalid_components_properties?(cjson)
errors.add(:base, :invalid_components)
end
end
def invalid_components_properties?(json)
(json.keys - COMPONENTS_PROPERTIES).any? ||
invalid_visibility?(json['visibility']) ||
invalid_components?(json['selection']) ||
invalid_colorings?(json['coloring'])
end
def invalid_line?(line)
invalid_hash_point?(line, LINES_PROPERTIES)
end
def invalid_clipping_plane?(line)
invalid_hash_point?(line, CLIPPING_PLANES_PROPERTIES)
end
def invalid_hash_point?(hash, whitelist)
!hash.is_a?(Hash) ||
hash.keys != whitelist ||
hash.values.any? { |v| invalid_point?(v) }
end
def invalid_visibility?(visibility)
visibility.nil? ||
!visibility.is_a?(Hash) ||
(visibility.keys - VISIBILITY_PROPERTIES).any? ||
invalid_default_visibility?(visibility['default_visibility']) ||
invalid_components?(visibility['exceptions']) ||
invalid_view_setup_hints?(visibility['view_setup_hints'])
end
def invalid_components?(components)
return false unless components.present?
!components.is_a?(Array) || components.any? { |component| invalid_component?(component) }
end
def invalid_colorings?(colorings)
return false unless colorings.present?
!colorings.is_a?(Array) || colorings.any? { |coloring| invalid_coloring?(coloring) }
end
def invalid_component?(component)
!component.is_a?(Hash) ||
component.empty? ||
(component.keys - COMPONENT_PROPERTIES).any? ||
component.values.any? { |v| !v.is_a?(String) }
end
def invalid_coloring?(coloring)
!coloring.is_a?(Hash) ||
coloring.keys != COLORING_PROPERTIES ||
invalid_color?(coloring['color']) ||
invalid_components?(coloring['components'])
end
def invalid_color?(color)
!(color.is_a?(String) && color.match?(COLOR_REGEXP))
end
def invalid_direction?(direction)
!direction.is_a?(Hash) ||
direction.keys != WHITELISTED_DIMENSIONS ||
direction.values.any? { |v| !v.is_a? Float }
end
alias_method :invalid_point?, :invalid_direction?
def invalid_default_visibility?(visibility)
visibility.present? &&
no_boolean?(visibility)
end
def invalid_view_setup_hints?(hints)
return false if hints.nil?
!hints.is_a?(Hash) ||
(hints.keys - VIEW_SETUP_HINTS_PROPERTIES).any? ||
hints.values.any? { |v| no_boolean?(v) }
end
def no_boolean?(property)
!(property.is_a?(TrueClass) || property.is_a?(FalseClass))
end
def viewpoint
model.json_viewpoint
end
end
end

@ -72,3 +72,19 @@ en:
scopes:
bcf_v2_1: "Full access to the BCF v2.1 API"
bcf_v2_1_text: "Application will receive full read & write access to the OpenProject BCF API v2.1 to perform actions on your behalf."
activerecord:
errors:
models:
bcf/viewpoint:
bitmaps_not_writable: "'bitmaps' is not writable as it is not yet implemented"
index_not_integer: "'index' is not an integer."
invalid_clipping_planes: "'clipping_planes' is invalid."
invalid_components: "'components' is invalid."
invalid_lines: "'lines' is invalid."
invalid_orthogonal_camera: "'orthogonal_camera' is invalid."
invalid_perspective_camera: "'perspective_camera' is invalid."
no_json: "Is not a well structured json."
snapshot_type_unsupported: "'snapshot_type' needs to be either 'png' or 'jpg'."
snapshot_data_blank: "'snapshot_data' needs to be provided."
unsupported_key: "An unsupported json property is included."

@ -48,7 +48,14 @@ describe Bcf::Viewpoints::CreateContract do
end
end
let(:viewpoint_uuid) { 'issue uuid' }
let(:viewpoint_json_viewpoint) { 'some json' }
let(:viewpoint_json_viewpoint) do
{
'snapshot' => {
'snapshot_data' => 'some contents',
'snapshot_type' => 'jpg'
}
}
end
let(:viewpoint_issue) do
FactoryBot.build_stubbed(:bcf_issue).tap do |issue|
allow(issue)
@ -103,4 +110,842 @@ describe Bcf::Viewpoints::CreateContract do
expect_valid(false, base: %i(error_unauthorized))
end
end
context 'json_viewpoint' do
context 'with somethin different that a hash' do
let(:viewpoint_json_viewpoint) do
'some non hash'
end
it 'is invalid' do
expect_valid(false, base: %i(no_json))
end
end
context 'with an unsupported key' do
let(:viewpoint_json_viewpoint) do
{
'some_key' => true
}
end
it 'is invalid' do
expect_valid(false, base: %i(unsupported_key))
end
end
describe 'snapshot' do
let(:viewpoint_json_viewpoint) do
{
'snapshot' => {
'snapshot_data' => 'some content',
'snapshot_type' => 'jpg'
}
}
end
it_behaves_like 'is valid'
context 'with a type other than png or jpg' do
let(:viewpoint_json_viewpoint) do
{
'snapshot' => {
'snapshot_data' => 'some content',
'snapshot_type' => 'some'
}
}
end
it 'is invalid' do
expect_valid(false, base: %i(snapshot_type_unsupported))
end
end
context 'without a type' do
let(:viewpoint_json_viewpoint) do
{
'snapshot' => {
'snapshot_data' => 'some content'
}
}
end
it 'is invalid' do
expect_valid(false, base: %i(snapshot_type_unsupported))
end
end
context 'without data' do
let(:viewpoint_json_viewpoint) do
{
'snapshot' => {
'snapshot_type' => 'jpg'
}
}
end
it 'is invalid' do
expect_valid(false, base: %i(snapshot_data_blank))
end
end
context 'without snapshot' do
let(:viewpoint_json_viewpoint) do
{
"index": 10
}
end
it_behaves_like 'is valid'
end
end
describe 'index' do
context 'with a non integer value' do
let(:viewpoint_json_viewpoint) do
{
'index' => 'something'
}
end
it 'is invalid' do
expect_valid(false, base: %i(index_not_integer))
end
end
end
describe 'orthogonal_camera' do
let(:valid_json) do
{
"orthogonal_camera": {
"camera_view_point": {
"x": 12.3456789,
"y": 1.2345,
"z": -1234.1234
},
"camera_direction": {
"x": -1.0,
"y": -2.0,
"z": -3.0
},
"camera_up_vector": {
"x": 0.223629,
"y": 0.209889,
"z": 0.951807
},
"view_to_world_scale": 2.0
}
}.stringify_keys
end
let(:viewpoint_json_viewpoint) do
valid_json
end
it_behaves_like 'is valid'
context 'with an additional property' do
let(:viewpoint_json_viewpoint) do
valid_json['orthogonal_camera']
.merge!("superfluous_property" => 123)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_orthogonal_camera))
end
end
context 'with a missing property' do
let(:viewpoint_json_viewpoint) do
valid_json['orthogonal_camera'].delete(:camera_direction)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_orthogonal_camera))
end
end
context 'with a missing dimension in one of the directions' do
let(:viewpoint_json_viewpoint) do
valid_json['orthogonal_camera'][:camera_direction].delete(:y)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_orthogonal_camera))
end
end
context 'with a non number in one of the directions' do
let(:viewpoint_json_viewpoint) do
valid_json['orthogonal_camera'][:camera_direction][:z] = "sdfjsdkf"
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_orthogonal_camera))
end
end
context 'with a non number in for view_to_world_scale' do
let(:viewpoint_json_viewpoint) do
valid_json['orthogonal_camera'][:view_to_world_scale] = "sdfjsdkf"
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_orthogonal_camera))
end
end
end
describe 'perspective_camera' do
let(:valid_json) do
{
"perspective_camera": {
"camera_view_point": {
"x": 12.3456789,
"y": 1.2345,
"z": -1234.1234
},
"camera_direction": {
"x": -1.0,
"y": -2.0,
"z": -3.0
},
"camera_up_vector": {
"x": 0.223629,
"y": 0.209889,
"z": 0.951807
},
"field_of_view": 180.0
}
}.stringify_keys
end
let(:viewpoint_json_viewpoint) do
valid_json
end
it_behaves_like 'is valid'
context 'with an additional property' do
let(:viewpoint_json_viewpoint) do
valid_json['perspective_camera']
.merge!("superfluous_property" => 123)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_perspective_camera))
end
end
context 'with a missing property' do
let(:viewpoint_json_viewpoint) do
valid_json['perspective_camera'].delete(:camera_direction)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_perspective_camera))
end
end
context 'with a missing dimension in one of the directions' do
let(:viewpoint_json_viewpoint) do
valid_json['perspective_camera'][:camera_direction].delete(:y)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_perspective_camera))
end
end
context 'with a non number in one of the directions' do
let(:viewpoint_json_viewpoint) do
valid_json['perspective_camera'][:camera_direction][:z] = "sdfjsdkf"
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_perspective_camera))
end
end
context 'with a non number in for view_to_world_scale' do
let(:viewpoint_json_viewpoint) do
valid_json['perspective_camera'][:field_of_view] = "sdfjsdkf"
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_perspective_camera))
end
end
end
describe 'lines' do
let(:valid_json) do
{
"lines": [
{
"start_point": {
"x": 1.0,
"y": 1.0,
"z": 1.0
},
"end_point": {
"x": 0.0,
"y": 0.0,
"z": 0.0
}
},
{
"start_point": {
"x": 2.0,
"y": 3.0,
"z": 4.0
},
"end_point": {
"x": -1.0,
"y": -2.0,
"z": -3.0
}
}
]
}.stringify_keys
end
let(:viewpoint_json_viewpoint) do
valid_json
end
it_behaves_like 'is valid'
context 'with a non array for lines' do
let(:viewpoint_json_viewpoint) do
{
"lines" => { "some" => "value" }
}
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_lines))
end
end
context 'with an additional property for one line' do
let(:viewpoint_json_viewpoint) do
valid_json['lines'][1]
.merge!("superfluous_property" => 123)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_lines))
end
end
context 'with a missing property' do
let(:viewpoint_json_viewpoint) do
valid_json['lines'][1].delete(:start_point)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_lines))
end
end
context 'with a missing dimension in one of the lines' do
let(:viewpoint_json_viewpoint) do
valid_json['lines'][1][:end_point].delete(:y)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_lines))
end
end
context 'with a non number in one of the points' do
let(:viewpoint_json_viewpoint) do
valid_json['lines'][1][:start_point][:z] = "sdfjsdkf"
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_lines))
end
end
end
describe 'clipping_planes' do
let(:valid_json) do
{
"clipping_planes": [
{
"location": {
"x": 0.5,
"y": 0.5,
"z": 0.5
},
"direction": {
"x": 1.0,
"y": 0.0,
"z": 0.0
}
},
{
"location": {
"x": 4.5,
"y": 0.5,
"z": 1.5
},
"direction": {
"x": 1.0,
"y": -5.5,
"z": 0.6
}
}
]
}.stringify_keys
end
let(:viewpoint_json_viewpoint) do
valid_json
end
it_behaves_like 'is valid'
context 'with a non array for lines' do
let(:viewpoint_json_viewpoint) do
{
"clipping_planes" => { "some" => "value" }
}
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_clipping_planes))
end
end
context 'with an additional property for one line' do
let(:viewpoint_json_viewpoint) do
valid_json['clipping_planes'][1]
.merge!("superfluous_property" => 123)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_clipping_planes))
end
end
context 'with a missing property' do
let(:viewpoint_json_viewpoint) do
valid_json['clipping_planes'][1].delete(:direction)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_clipping_planes))
end
end
context 'with a missing dimension in one of the lines' do
let(:viewpoint_json_viewpoint) do
valid_json['clipping_planes'][1][:direction].delete(:y)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_clipping_planes))
end
end
context 'with a non number in one of the points' do
let(:viewpoint_json_viewpoint) do
valid_json['clipping_planes'][1][:location][:z] = "sdfjsdkf"
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_clipping_planes))
end
end
end
describe 'bitmaps' do
let(:viewpoint_json_viewpoint) do
{
"bitmaps": [
"something"
]
}.stringify_keys
end
it 'is invalid' do
expect_valid(false, base: %i(bitmaps_not_writable))
end
end
describe 'components' do
let(:valid_json) do
{
"components":
{
"selection": [
{
"ifc_guid": "2MF28NhmDBiRVyFakgdbCT",
"originating_system": "Example CAD Application",
"authoring_tool_id": "EXCAD/v1.0"
},
{
"ifc_guid": "4MF28NhmDBiRVyFakgdbCT",
"originating_system": "Example CAD Application",
"authoring_tool_id": "EXCAD/v1.0"
}
],
"coloring": [
{
"color": "#ff0000",
"components": [
{
"ifc_guid": "3$cshxZO9AJBebsni$z9Yk"
},
{
"ifc_guid": "4$cshxZO9AJBebsni$z9Yk"
}
]
},
{
"color": "#ff0333",
"components": [
{
"ifc_guid": "3$cshxZO9AJBebsni$z9Y8"
},
{
"ifc_guid": "4$cshxZO9AJBebsni$z9Y8"
}
]
}
],
"visibility": {
"default_visibility": false,
"exceptions": [
{
"ifc_guid": "4$cshxZO9AJBebsni$z9Yk"
}
],
"view_setup_hints": {
"spaces_visible": true,
"space_boundaries_visible": false,
"openings_visible": true
}
}
}
}.stringify_keys
end
let(:viewpoint_json_viewpoint) do
valid_json
end
it_behaves_like 'is valid'
context 'with a non hash' do
let(:viewpoint_json_viewpoint) do
{
"components" => 534
}
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with an additional property' do
let(:viewpoint_json_viewpoint) do
valid_json['components']
.merge!("superfluous_property" => 123)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with missing visibility property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'].delete(:visibility)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with missing selection property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'].delete(:selection)
valid_json
end
it_behaves_like 'is valid'
end
context 'with missing coloring property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'].delete(:coloring)
valid_json
end
it_behaves_like 'is valid'
end
context 'with selection property not being an array of hashes' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:selection] = ["blubs"]
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with a property of the selection property not being string' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:selection][1][:ifcguid] = 345
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with a component of the selection property having an unkonwn property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:selection][1]['superfluous'] = "sdsdsf"
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with a component of the selection property being empty' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:selection][1] = {}
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with coloring property not being an array of hashes' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:coloring] = ["blubs"]
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with a coloring of the coloring property lacking a property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:coloring][1].delete(:color)
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with having an invalid color for coloring property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:coloring][1][:color] = '#ff54zzzz'
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with having a non string for color of a coloring property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:coloring][1][:color] = 123456
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with having a non array of hashes for components of a coloring property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:coloring][1][:components] = ['blubs']
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with having an invalid property in for a components of a coloring property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:coloring][1][:components][0]['superfluous'] = 'blubs'
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with visibility property not being a hashes' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility] = 'blubs'
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with visibility property having an unknown property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility]['superfluous'] = 'blubs'
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with visibility property being an empty hash' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility] = {}
valid_json
end
it_behaves_like 'is valid'
end
context 'with visibility property lacking a property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility].delete(:exceptions)
valid_json
end
it_behaves_like 'is valid'
end
context 'with default_visibility of the visibility property being a non boolean' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility][:default_visibility] = 'blubs'
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with components of the visibility property not being an array of hashes' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility][:exceptions] = ['blubs']
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with components of the visibility property having an invalid property' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility][:exceptions][0]['superfluous'] = 'blubs'
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with on property of a components of the visibility property being a non string' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility][:exceptions][0][:originating_system] = 124
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with view_setup_hints not being a hash' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility][:view_setup_hints] = []
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with view_setup_hints being an empty hash' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility][:view_setup_hints] = {}
valid_json
end
it_behaves_like 'is valid'
end
context 'with view_setup_hints having an unknown parameter' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility][:view_setup_hints]['superfluous'] = 'blubs'
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
context 'with a property of view_setup_hints being a non boolean' do
let(:viewpoint_json_viewpoint) do
valid_json['components'][:visibility][:view_setup_hints][:openings_visible] = 'blubs'
valid_json
end
it 'is invalid' do
expect_valid(false, base: %i(invalid_components))
end
end
end
end
end

@ -56,7 +56,11 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, wit
FactoryBot.create(:user)
end
shared_let(:work_package) { FactoryBot.create(:work_package, project: project) }
shared_let(:work_package) do
User.execute_as create_user do
FactoryBot.create(:work_package, project: project)
end
end
shared_let(:bcf_issue) { FactoryBot.create(:bcf_issue_with_viewpoint, work_package: work_package) }
let(:viewpoint) { bcf_issue.viewpoints.first }

@ -111,7 +111,7 @@ describe Bcf::Viewpoints::SetAttributesService, type: :model do
.to eql 1
expect(viewpoint.attachments.first.file.read)
.to eql call_attributes[:json_viewpoint]['snapshot']['snapshot_data']
.to eql 'Hello World!'
expect(viewpoint.attachments.first.file.filename)
.to eql 'snapshot.png'

Loading…
Cancel
Save