Skip to content

Commit

Permalink
Merge 694e266 into fa1a63d
Browse files Browse the repository at this point in the history
  • Loading branch information
gburgett committed Nov 5, 2019
2 parents fa1a63d + 694e266 commit f2e3d3c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
15 changes: 13 additions & 2 deletions wcc-contentful/lib/wcc/contentful/downloads_schema.rb
Expand Up @@ -61,7 +61,7 @@ def editor_interfaces
@editor_interfaces ||=
content_types
.map { |ct| @client.editor_interface(ct.dig('sys', 'id')).raw }
.map { |i| strip_sys(i) }
.map { |i| sort_controls(strip_sys(i)) }
.sort_by { |i| i.dig('sys', 'contentType', 'sys', 'id') }
end

Expand All @@ -73,6 +73,15 @@ def strip_sys(obj)
})
end

def sort_controls(editor_interface)
{
'sys' => editor_interface['sys'],
'controls' => editor_interface['controls']
.sort_by { |c| c['fieldId'] }
.map { |c| c.slice('fieldId', 'settings', 'widgetId') }
}
end

def deep_contains_all(expected, actual)
if expected.is_a? Array
expected.each_with_index do |val, i|
Expand All @@ -96,6 +105,8 @@ def format_json(hash)

# The pretty_generate format differs from contentful-shell and nodejs formats
# only in its treatment of empty arrays in the "validations" field.
json_string.gsub(/\[\n\n\s+\]/, '[]')
json_string = json_string.gsub(/\[\n\n\s+\]/, '[]')
# contentful-shell also adds a newline at the end.
json_string + "\n"
end
end
Expand Up @@ -220,6 +220,9 @@
"controls": [
{
"fieldId": "name",
"settings": {
"helpText": "This is the name"
},
"widgetId": "singleLine"
},
{
Expand Down Expand Up @@ -274,11 +277,13 @@
"controls": [
{
"fieldId": "name",
"widgetId": "singleLine"
"widgetId": "singleLine",
"widgetNamespace": "builtin"
},
{
"fieldId": "photo",
"widgetId": "assetLinkEditor"
"widgetId": "assetLinkEditor",
"widgetNamespace": "builtin"
}
]
}
Expand Down
13 changes: 8 additions & 5 deletions wcc-contentful/spec/fixtures/contentful/contentful-schema.json
Expand Up @@ -97,13 +97,16 @@
}
},
"controls": [
{
"fieldId": "name",
"widgetId": "singleLine"
},
{
"fieldId": "items",
"widgetId": "entryLinksEditor"
},
{
"fieldId": "name",
"settings": {
"helpText": "This is the name"
},
"widgetId": "singleLine"
}
]
},
Expand Down Expand Up @@ -131,4 +134,4 @@
]
}
]
}
}
7 changes: 3 additions & 4 deletions wcc-contentful/spec/wcc/contentful/downloads_schema_spec.rb
Expand Up @@ -66,14 +66,13 @@
Dir.chdir(dir) do
FileUtils.mkdir_p('db')
FileUtils.cp(
File.join(fixture_root, 'contentful/contentful-schema-from-export.json'),
File.join(fixture_root, 'contentful/contentful-schema.json'),
'db/contentful-schema.json'
)

subject.call
expect(File).to_not receive(:write)

expect(File.read('db/contentful-schema.json'))
.to eq(load_fixture('contentful/contentful-schema-from-export.json'))
subject.call
end
end
end
Expand Down

0 comments on commit f2e3d3c

Please sign in to comment.