From d4930abe4512a5cb703ea476cef0f2e9c0740b84 Mon Sep 17 00:00:00 2001 From: Paul Vaneveld Date: Sat, 22 Jun 2024 11:31:39 +0200 Subject: [PATCH 1/7] feat: add support for condition settings --- internal/component_model.go | 159 ++++++++++++++++++++++++--------- internal/component_resource.go | 49 ++++++++++ 2 files changed, 167 insertions(+), 41 deletions(-) diff --git a/internal/component_model.go b/internal/component_model.go index d0cf912..3f994a0 100644 --- a/internal/component_model.go +++ b/internal/component_model.go @@ -32,47 +32,65 @@ type fieldModel struct { Type types.String `tfsdk:"type"` Position types.Int64 `tfsdk:"position"` - AddHttps types.Bool `tfsdk:"add_https"` - AllowTargetBlank types.Bool `tfsdk:"allow_target_blank"` - AssetFolderId types.Int64 `tfsdk:"asset_folder_id"` - CanSync types.Bool `tfsdk:"can_sync"` - ComponentWhitelist []types.String `tfsdk:"component_whitelist"` - CustomizeToolbar types.Bool `tfsdk:"customize_toolbar"` - DatasourceSlug types.String `tfsdk:"datasource_slug"` - DefaultValue types.String `tfsdk:"default_value"` - Description types.String `tfsdk:"description"` - DisableTime types.Bool `tfsdk:"disable_time"` - DisplayName types.String `tfsdk:"display_name"` - ExternalDatasource types.String `tfsdk:"external_datasource"` - FieldType types.String `tfsdk:"field_type"` - Filetypes []types.String `tfsdk:"filetypes"` - FilterContentType []types.String `tfsdk:"filter_content_type"` - FolderSlug types.String `tfsdk:"folder_slug"` - ForceLinkScope types.Bool `tfsdk:"force_link_scope"` - ImageCrop types.Bool `tfsdk:"image_crop"` - ImageHeight types.String `tfsdk:"image_height"` - ImageWidth types.String `tfsdk:"image_width"` - KeepImageSize types.Bool `tfsdk:"keep_image_size"` - Keys []types.String `tfsdk:"keys"` - LinkScope types.String `tfsdk:"link_scope"` - Maximum types.Int64 `tfsdk:"maximum"` - MaxLength types.Int64 `tfsdk:"max_length"` - MaxOptions types.Int64 `tfsdk:"max_options"` - Minimum types.Int64 `tfsdk:"minimum"` - MinOptions types.Int64 `tfsdk:"min_options"` - NoTranslate types.Bool `tfsdk:"no_translate"` - Options []optionModel `tfsdk:"options"` - Regex types.String `tfsdk:"regex"` - Required types.Bool `tfsdk:"required"` - RestrictComponents types.Bool `tfsdk:"restrict_components"` - RestrictContentTypes types.Bool `tfsdk:"restrict_content_types"` - RichMarkdown types.Bool `tfsdk:"rich_markdown"` - Rtl types.Bool `tfsdk:"rtl"` - Source types.String `tfsdk:"source"` - Toolbar []types.String `tfsdk:"toolbar"` - Tooltip types.Bool `tfsdk:"tooltip"` - Translatable types.Bool `tfsdk:"translatable"` - UseUuid types.Bool `tfsdk:"use_uuid"` + AddHttps types.Bool `tfsdk:"add_https"` + AllowTargetBlank types.Bool `tfsdk:"allow_target_blank"` + AssetFolderId types.Int64 `tfsdk:"asset_folder_id"` + CanSync types.Bool `tfsdk:"can_sync"` + ComponentWhitelist []types.String `tfsdk:"component_whitelist"` + ConditionalSettings []conditionalSettingsModel `tfsdk:"conditional_settings"` + CustomizeToolbar types.Bool `tfsdk:"customize_toolbar"` + DatasourceSlug types.String `tfsdk:"datasource_slug"` + DefaultValue types.String `tfsdk:"default_value"` + Description types.String `tfsdk:"description"` + DisableTime types.Bool `tfsdk:"disable_time"` + DisplayName types.String `tfsdk:"display_name"` + ExternalDatasource types.String `tfsdk:"external_datasource"` + FieldType types.String `tfsdk:"field_type"` + Filetypes []types.String `tfsdk:"filetypes"` + FilterContentType []types.String `tfsdk:"filter_content_type"` + FolderSlug types.String `tfsdk:"folder_slug"` + ForceLinkScope types.Bool `tfsdk:"force_link_scope"` + ImageCrop types.Bool `tfsdk:"image_crop"` + ImageHeight types.String `tfsdk:"image_height"` + ImageWidth types.String `tfsdk:"image_width"` + KeepImageSize types.Bool `tfsdk:"keep_image_size"` + Keys []types.String `tfsdk:"keys"` + LinkScope types.String `tfsdk:"link_scope"` + Maximum types.Int64 `tfsdk:"maximum"` + MaxLength types.Int64 `tfsdk:"max_length"` + MaxOptions types.Int64 `tfsdk:"max_options"` + Minimum types.Int64 `tfsdk:"minimum"` + MinOptions types.Int64 `tfsdk:"min_options"` + NoTranslate types.Bool `tfsdk:"no_translate"` + Options []optionModel `tfsdk:"options"` + Regex types.String `tfsdk:"regex"` + Required types.Bool `tfsdk:"required"` + RestrictComponents types.Bool `tfsdk:"restrict_components"` + RestrictContentTypes types.Bool `tfsdk:"restrict_content_types"` + RichMarkdown types.Bool `tfsdk:"rich_markdown"` + Rtl types.Bool `tfsdk:"rtl"` + Source types.String `tfsdk:"source"` + Toolbar []types.String `tfsdk:"toolbar"` + Tooltip types.Bool `tfsdk:"tooltip"` + Translatable types.Bool `tfsdk:"translatable"` + UseUuid types.Bool `tfsdk:"use_uuid"` +} + +type conditionalSettingsModel struct { + Modifications []modificationModel `tfsdk:"modifications"` + RuleMatch types.String `tfsdk:"rule_match"` + RuleConditions []ruleConditionModel `tfsdk:"rule_conditions"` +} + +type ruleConditionModel struct { + Validation types.String `tfsdk:"validation"` + Value types.String `tfsdk:"value"` + FieldKey types.String `tfsdk:"field_key"` +} + +type modificationModel struct { + Display types.String `tfsdk:"display"` + Required types.Bool `tfsdk:"required"` } type optionModel struct { @@ -151,6 +169,7 @@ func toFieldInput(item fieldModel) sbmgmt.FieldInput { AssetFolderId: item.AssetFolderId.ValueInt64Pointer(), CanSync: item.CanSync.ValueBoolPointer(), ComponentWhitelist: utils.ConvertToPointerStringSlice(item.ComponentWhitelist), + ConditionalSettings: deserializeConditionalSettingsModel(item.ConditionalSettings), CustomizeToolbar: item.CustomizeToolbar.ValueBoolPointer(), DatasourceSlug: item.DatasourceSlug.ValueStringPointer(), DefaultValue: item.DefaultValue.ValueStringPointer(), @@ -368,3 +387,61 @@ func deserializeOptionsModel(options []optionModel) *[]sbmgmt.FieldOption { return &optionModels } + +func deserializeConditionalSettingsModel(conditionalSettings []conditionalSettingsModel) *[]sbmgmt.ConditionalSettings { + if conditionalSettings == nil { + return nil + } + + deserializedConditionalSettings := make([]sbmgmt.ConditionalSettings, len(conditionalSettings)) + + for i, setting := range conditionalSettings { + + deserializedConditionalSettings[i] = sbmgmt.ConditionalSettings{ + RuleMatch: (*sbmgmt.ConditionalSettingsRuleMatch)(setting.RuleMatch.ValueStringPointer()), + Modifications: deserializeConditionalSettingsModificationsModel(setting.Modifications), + RuleConditions: deserializeRuleConditions(setting.RuleConditions), + } + } + + return &deserializedConditionalSettings +} + +func deserializeConditionalSettingsModificationsModel(conditionalSettingsModifications []modificationModel) *[]sbmgmt.Modification { + deserializedModifications := make([]sbmgmt.Modification, len(conditionalSettingsModifications)) + + for i, modification := range conditionalSettingsModifications { + if !modification.Display.IsNull() { + deserializedModifications[i] = sbmgmt.Modification{ + Display: (*sbmgmt.ModificationDisplay)(modification.Display.ValueStringPointer()), + } + } else { + deserializedModifications[i] = sbmgmt.Modification{ + Required: modification.Required.ValueBoolPointer(), + } + } + } + + return &deserializedModifications +} + +func deserializeRuleConditions(ruleConditions []ruleConditionModel) *[]sbmgmt.RuleCondition { + deserializedRuleConditions := make([]sbmgmt.RuleCondition, len(ruleConditions)) + + validatedObjectFieldAttrValue := sbmgmt.ValidatedObjectFieldAttr("value") + validatedValidatedObjectType := sbmgmt.ValidatedObjectType("field") + + for i, ruleCondition := range ruleConditions { + deserializedRuleConditions[i] = sbmgmt.RuleCondition{ + Validation: (*sbmgmt.RuleConditionValidation)(ruleCondition.Validation.ValueStringPointer()), + Value: ruleCondition.Validation.ValueStringPointer(), + ValidatedObject: &sbmgmt.ValidatedObject{ + FieldKey: ruleCondition.FieldKey.ValueStringPointer(), + FieldAttr: &validatedObjectFieldAttrValue, + Type: &validatedValidatedObjectType, + }, + } + } + + return &deserializedRuleConditions +} diff --git a/internal/component_resource.go b/internal/component_resource.go index dff01c9..2b4403f 100644 --- a/internal/component_resource.go +++ b/internal/component_resource.go @@ -168,6 +168,55 @@ func (r *componentResource) Schema(_ context.Context, _ resource.SchemaRequest, Optional: true, ElementType: types.StringType, }, + "conditional_settings": schema.ListNestedAttribute{ + Description: "Array containing the object with information about conditions set on the field", + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "modifications": schema.ListNestedAttribute{ + Optional: false, + Description: "List of modifications to be applied to the field. Only 1 modification can be applied at a time (display OR required)", + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "display": schema.StringAttribute{ + Optional: true, + Description: "Hide the target field if the rule conditions are met", + Validators: []validator.String{stringvalidator.OneOf("hide")}, + }, + "required": schema.BoolAttribute{ + Optional: true, + Description: "Make the target field required / optional if the rule conditions are met", + }, + }, + }, + }, + "rule_match": schema.StringAttribute{ + Description: "Define if all or any of the conditions should be met to apply the modifications", + Optional: false, + Validators: []validator.String{stringvalidator.OneOf("any", "all")}, + }, + "rule_conditions": schema.ListNestedAttribute{ + Description: "Conditional rules to be applied to the target field", + Optional: false, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "validation": schema.StringAttribute{ + Optional: false, + Validators: []validator.String{stringvalidator.OneOf("empty", "not_empty", "equals", "not_equals")}, + }, + "value": schema.StringAttribute{ + Optional: true, + Default: nil, + }, + "field_key": schema.StringAttribute{ + Optional: false, + }, + }, + }, + }, + }, + }, + }, "datasource_slug": schema.StringAttribute{ Description: "Define selectable datasources string; Effects editor only if source=internal", Optional: true, From 5492464fc28f06038026a2bfa6391f4b287a4796 Mon Sep 17 00:00:00 2001 From: Paul Vaneveld Date: Thu, 11 Jul 2024 16:02:22 +0200 Subject: [PATCH 2/7] fix: several * add serialize functions * adjust model to match actual api request * add an example --- .../resources/storyblok_component/resource.tf | 122 +++++++++++++----- internal/component_model.go | 85 +++++++++--- internal/component_resource.go | 21 ++- 3 files changed, 177 insertions(+), 51 deletions(-) diff --git a/examples/resources/storyblok_component/resource.tf b/examples/resources/storyblok_component/resource.tf index 183c3b4..ee30012 100644 --- a/examples/resources/storyblok_component/resource.tf +++ b/examples/resources/storyblok_component/resource.tf @@ -24,62 +24,126 @@ resource "storyblok_component" "banner" { // advanced example resource "storyblok_component" "advanced_component" { - name = "advanced-component" - space_id = "" - is_root = true + name = "advanced-component" + space_id = "" + is_root = true is_nestable = false schema = { title = { - type = "text" - position = 1 - required = true // The field is required. Default is false. - max_length = 200 // Set the max length of the input string + type = "text" + position = 1 + required = true // The field is required. Default is false. + max_length = 200 // Set the max length of the input string description = "Title of the component" // Description shown in the editor interface } introduction = { - type = "rich_text" - position = 2 + type = "rich_text" + position = 2 rich_markdown = true // Enable rich markdown view by default - description = "Introduction text with rich text editor" + description = "Introduction text with rich text editor" } image = { - type = "image" - position = 3 - asset_folder_id = 1 // Default asset folder numeric id to store uploaded image of that field - add_https = true // Prepends https: to stop usage of relative protocol - image_crop = true // Activate force crop for images + type = "image" + position = 3 + asset_folder_id = 1 // Default asset folder numeric id to store uploaded image of that field + add_https = true // Prepends https: to stop usage of relative protocol + image_crop = true // Activate force crop for images } release_date = { - type = "date" - position = 4 + type = "date" + position = 4 disable_time = true // Disables time selection from date picker - description = "Release date of the content" + description = "Release date of the content" } tags = { - type = "multi_option" - position = 5 + type = "multi_option" + position = 5 datasource_slug = "tags" // Define selectable datasources string - description = "Tags for the component" + description = "Tags for the component" } rating = { - type = "number" - position = 6 - description = "Rating of the content" + type = "number" + position = 6 + description = "Rating of the content" default_value = "3" // Default value for the field } content = { - type = "bloks" - position = 7 + type = "bloks" + position = 7 component_whitelist = ["text", "image", "video"] // Array of component/content type names - maximum = 10 // Maximum amount of added bloks in this blok field - description = "Content blocks" + maximum = 10 // Maximum amount of added bloks in this blok field + description = "Content blocks" } } -} \ No newline at end of file +} + +// conditional content +resource "storyblok_component" "conditional_settings_new" { + name = "conditional settings component" + space_id = "" + is_root = false + is_nestable = true + + + schema = { + content = { + position = 0 + translatable = true + display_name = "Content" + required = true + type = "text" + } + + more_content = { + position = 1 + translatable = true + display_name = "more content" + required = true + type = "text" + } + + conditionalContent = { + position = 2 + display_name = "conditinal content" + required = true + type = "text" + + conditional_settings = [ + { + modifications = [ + { + required = false + } + ] + + // make "conditional content" optional of either: + // 1. content is empty + // 2. more content equals "test" + rule_match = "any" + rule_conditions = [ + { + validation = "empty" + validated_object = { + field_key = "content" + } + }, + { + value = "test" + validation = "equals" + validated_object = { + field_key = "more_content" + } + } + ] + } + ] + } + } +} diff --git a/internal/component_model.go b/internal/component_model.go index 3f994a0..cf2d472 100644 --- a/internal/component_model.go +++ b/internal/component_model.go @@ -83,9 +83,13 @@ type conditionalSettingsModel struct { } type ruleConditionModel struct { - Validation types.String `tfsdk:"validation"` - Value types.String `tfsdk:"value"` - FieldKey types.String `tfsdk:"field_key"` + Validation types.String `tfsdk:"validation"` + Value types.String `tfsdk:"value"` + ValidatedObject validatedObjectModel `tfsdk:"validated_object"` +} + +type validatedObjectModel struct { + FieldKey types.String `tfsdk:"field_key"` } type modificationModel struct { @@ -169,7 +173,7 @@ func toFieldInput(item fieldModel) sbmgmt.FieldInput { AssetFolderId: item.AssetFolderId.ValueInt64Pointer(), CanSync: item.CanSync.ValueBoolPointer(), ComponentWhitelist: utils.ConvertToPointerStringSlice(item.ComponentWhitelist), - ConditionalSettings: deserializeConditionalSettingsModel(item.ConditionalSettings), + ConditionalSettings: deserializeConditionalSettings(item.ConditionalSettings), CustomizeToolbar: item.CustomizeToolbar.ValueBoolPointer(), DatasourceSlug: item.DatasourceSlug.ValueStringPointer(), DefaultValue: item.DefaultValue.ValueStringPointer(), @@ -285,6 +289,7 @@ func toFieldModel(field sbmgmt.FieldInput) fieldModel { Tooltip: types.BoolPointerValue(field.Tooltip), Translatable: types.BoolPointerValue(field.Translatable), UseUuid: types.BoolPointerValue(field.UseUuid), + ConditionalSettings: serializeConditionalSettings(field.ConditionalSettings), } } @@ -388,7 +393,62 @@ func deserializeOptionsModel(options []optionModel) *[]sbmgmt.FieldOption { return &optionModels } -func deserializeConditionalSettingsModel(conditionalSettings []conditionalSettingsModel) *[]sbmgmt.ConditionalSettings { +func serializeConditionalSettings(conditionalSettings *[]sbmgmt.ConditionalSettings) []conditionalSettingsModel { + if conditionalSettings == nil { + return nil + } + + serializedConditionalSettings := make([]conditionalSettingsModel, len(*conditionalSettings)) + + for i, conditionalSetting := range *conditionalSettings { + serializedConditionalSettings[i] = conditionalSettingsModel{ + RuleMatch: types.StringPointerValue((*string)(conditionalSetting.RuleMatch)), + Modifications: serializeModifications(conditionalSetting.Modifications), + RuleConditions: serializeRuleConditions(conditionalSetting.RuleConditions), + } + } + + return serializedConditionalSettings +} + +func serializeModifications(modifications *[]sbmgmt.Modification) []modificationModel { + if modifications == nil { + return nil + } + + serializedModifications := make([]modificationModel, len(*modifications)) + + for i, modification := range *modifications { + serializedModifications[i] = modificationModel{ + Required: types.BoolPointerValue(modification.Required), + Display: types.StringPointerValue((*string)(modification.Display)), + } + } + + return serializedModifications +} +func serializeRuleConditions(ruleConditions *[]sbmgmt.RuleCondition) []ruleConditionModel { + + if ruleConditions == nil { + return nil + } + + serializedRuleConditions := make([]ruleConditionModel, len(*ruleConditions)) + + for i, ruleCondition := range *ruleConditions { + serializedRuleConditions[i] = ruleConditionModel{ + Value: types.StringPointerValue(ruleCondition.Value), + Validation: types.StringPointerValue((*string)(ruleCondition.Validation)), + ValidatedObject: validatedObjectModel{ + FieldKey: types.StringPointerValue(ruleCondition.ValidatedObject.FieldKey), + }, + } + } + + return serializedRuleConditions +} + +func deserializeConditionalSettings(conditionalSettings []conditionalSettingsModel) *[]sbmgmt.ConditionalSettings { if conditionalSettings == nil { return nil } @@ -411,14 +471,9 @@ func deserializeConditionalSettingsModificationsModel(conditionalSettingsModific deserializedModifications := make([]sbmgmt.Modification, len(conditionalSettingsModifications)) for i, modification := range conditionalSettingsModifications { - if !modification.Display.IsNull() { - deserializedModifications[i] = sbmgmt.Modification{ - Display: (*sbmgmt.ModificationDisplay)(modification.Display.ValueStringPointer()), - } - } else { - deserializedModifications[i] = sbmgmt.Modification{ - Required: modification.Required.ValueBoolPointer(), - } + deserializedModifications[i] = sbmgmt.Modification{ + Required: modification.Required.ValueBoolPointer(), + Display: (*sbmgmt.ModificationDisplay)(modification.Display.ValueStringPointer()), } } @@ -434,9 +489,9 @@ func deserializeRuleConditions(ruleConditions []ruleConditionModel) *[]sbmgmt.Ru for i, ruleCondition := range ruleConditions { deserializedRuleConditions[i] = sbmgmt.RuleCondition{ Validation: (*sbmgmt.RuleConditionValidation)(ruleCondition.Validation.ValueStringPointer()), - Value: ruleCondition.Validation.ValueStringPointer(), + Value: ruleCondition.Value.ValueStringPointer(), ValidatedObject: &sbmgmt.ValidatedObject{ - FieldKey: ruleCondition.FieldKey.ValueStringPointer(), + FieldKey: ruleCondition.ValidatedObject.FieldKey.ValueStringPointer(), FieldAttr: &validatedObjectFieldAttrValue, Type: &validatedValidatedObjectType, }, diff --git a/internal/component_resource.go b/internal/component_resource.go index 2b4403f..4722d6e 100644 --- a/internal/component_resource.go +++ b/internal/component_resource.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" @@ -174,7 +175,7 @@ func (r *componentResource) Schema(_ context.Context, _ resource.SchemaRequest, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "modifications": schema.ListNestedAttribute{ - Optional: false, + Required: true, Description: "List of modifications to be applied to the field. Only 1 modification can be applied at a time (display OR required)", NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ @@ -192,24 +193,30 @@ func (r *componentResource) Schema(_ context.Context, _ resource.SchemaRequest, }, "rule_match": schema.StringAttribute{ Description: "Define if all or any of the conditions should be met to apply the modifications", - Optional: false, + Required: true, Validators: []validator.String{stringvalidator.OneOf("any", "all")}, }, "rule_conditions": schema.ListNestedAttribute{ Description: "Conditional rules to be applied to the target field", - Optional: false, + Required: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ "validation": schema.StringAttribute{ - Optional: false, + Required: true, Validators: []validator.String{stringvalidator.OneOf("empty", "not_empty", "equals", "not_equals")}, }, "value": schema.StringAttribute{ Optional: true, - Default: nil, + Computed: true, + Default: stringdefault.StaticString("empty"), }, - "field_key": schema.StringAttribute{ - Optional: false, + "validated_object": schema.SingleNestedAttribute{ + Required: true, + Attributes: map[string]schema.Attribute{ + "field_key": schema.StringAttribute{ + Required: true, + }, + }, }, }, }, From cfc507bef95cfc9d5a2f5e2865bf7e9ee4b477b0 Mon Sep 17 00:00:00 2001 From: Paul Vaneveld Date: Thu, 11 Jul 2024 16:07:56 +0200 Subject: [PATCH 3/7] chore: change file --- .changes/unreleased/Added-20240711-160714.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changes/unreleased/Added-20240711-160714.yaml diff --git a/.changes/unreleased/Added-20240711-160714.yaml b/.changes/unreleased/Added-20240711-160714.yaml new file mode 100644 index 0000000..82a744d --- /dev/null +++ b/.changes/unreleased/Added-20240711-160714.yaml @@ -0,0 +1,3 @@ +kind: Added +body: add support for conditional_settings in component schema +time: 2024-07-11T16:07:14.380066+02:00 From aafd7f06b76da493a2f5f9af97c78a44e2281f46 Mon Sep 17 00:00:00 2001 From: Paul Vaneveld Date: Thu, 11 Jul 2024 16:08:10 +0200 Subject: [PATCH 4/7] chore: update resource name --- examples/resources/storyblok_component/resource.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/resources/storyblok_component/resource.tf b/examples/resources/storyblok_component/resource.tf index ee30012..175f8d8 100644 --- a/examples/resources/storyblok_component/resource.tf +++ b/examples/resources/storyblok_component/resource.tf @@ -85,7 +85,7 @@ resource "storyblok_component" "advanced_component" { } // conditional content -resource "storyblok_component" "conditional_settings_new" { +resource "storyblok_component" "conditional_settings" { name = "conditional settings component" space_id = "" is_root = false From 2827cb3229b8b37370caa355b805497a6ffba637 Mon Sep 17 00:00:00 2001 From: Paul Vaneveld Date: Thu, 11 Jul 2024 16:26:32 +0200 Subject: [PATCH 5/7] test: add test --- internal/assets/asset_folder.yaml | 36 ++++++++--------- internal/assets/component.yaml | 44 ++++++++++---------- internal/assets/component_group.yaml | 34 ++++++++-------- internal/assets/space_role.yaml | 34 ++++++++-------- internal/component_resource_test.go | 60 +++++++++++++++++++--------- 5 files changed, 116 insertions(+), 92 deletions(-) diff --git a/internal/assets/asset_folder.yaml b/internal/assets/asset_folder.yaml index 4361fe4..9d9ad77 100644 --- a/internal/assets/asset_folder.yaml +++ b/internal/assets/asset_folder.yaml @@ -25,13 +25,13 @@ interactions: trailer: {} content_length: 139 uncompressed: false - body: '{"asset_folder":{"id":576397,"name":"asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}' + body: '{"asset_folder":{"id":604728,"name":"asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 103.60975ms + duration: 253.17725ms - id: 1 request: proto: HTTP/1.1 @@ -46,7 +46,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397 + url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728 method: GET response: proto: HTTP/2.0 @@ -56,13 +56,13 @@ interactions: trailer: {} content_length: 139 uncompressed: false - body: '{"asset_folder":{"id":576397,"name":"asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}' + body: '{"asset_folder":{"id":604728,"name":"asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 39.288459ms + duration: 102.269667ms - id: 2 request: proto: HTTP/1.1 @@ -77,7 +77,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397 + url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728 method: GET response: proto: HTTP/2.0 @@ -87,13 +87,13 @@ interactions: trailer: {} content_length: 139 uncompressed: false - body: '{"asset_folder":{"id":576397,"name":"asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}' + body: '{"asset_folder":{"id":604728,"name":"asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 262.893583ms + duration: 107.813083ms - id: 3 request: proto: HTTP/1.1 @@ -108,7 +108,7 @@ interactions: body: '{"asset_folder":{"name":"new-asset-folder-name"}}' form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397 + url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728 method: PUT response: proto: HTTP/2.0 @@ -122,7 +122,7 @@ interactions: headers: {} status: 204 No Content code: 204 - duration: 146.615459ms + duration: 152.376458ms - id: 4 request: proto: HTTP/1.1 @@ -137,7 +137,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397 + url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728 method: GET response: proto: HTTP/2.0 @@ -147,13 +147,13 @@ interactions: trailer: {} content_length: 143 uncompressed: false - body: '{"asset_folder":{"id":576397,"name":"new-asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}' + body: '{"asset_folder":{"id":604728,"name":"new-asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 40.777416ms + duration: 86.802167ms - id: 5 request: proto: HTTP/1.1 @@ -168,7 +168,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397 + url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728 method: GET response: proto: HTTP/2.0 @@ -178,13 +178,13 @@ interactions: trailer: {} content_length: 143 uncompressed: false - body: '{"asset_folder":{"id":576397,"name":"new-asset-folder-name","parent_id":null,"uuid":"fa69a52f-3dd1-420b-8e2c-1b30bdef162c","parent_uuid":null}}' + body: '{"asset_folder":{"id":604728,"name":"new-asset-folder-name","parent_id":null,"uuid":"3092d6ba-5c74-416b-be9a-f2de95c64cd4","parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 40.8615ms + duration: 80.509792ms - id: 6 request: proto: HTTP/1.1 @@ -199,7 +199,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/576397 + url: https://mapi.storyblok.com/v1/spaces/233252/asset_folders/604728 method: DELETE response: proto: HTTP/2.0 @@ -213,4 +213,4 @@ interactions: headers: {} status: 204 No Content code: 204 - duration: 174.791209ms + duration: 240.006791ms diff --git a/internal/assets/component.yaml b/internal/assets/component.yaml index 147b60a..cfa6381 100644 --- a/internal/assets/component.yaml +++ b/internal/assets/component.yaml @@ -6,13 +6,13 @@ interactions: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 229 + content_length: 447 transfer_encoding: [] trailer: {} host: mapi.storyblok.com remote_addr: "" request_uri: "" - body: '{"component":{"is_nestable":false,"is_root":false,"name":"test-banner","preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","schema":{"title":{"pos":1,"type":"text"},"intro":{"pos":2,"type":"text"},"image":{"pos":3,"type":"image"}}}}' + body: '{"component":{"is_nestable":false,"is_root":false,"name":"test-banner","preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","schema":{"title":{"pos":1,"type":"text"},"intro":{"pos":2,"type":"text"},"image":{"conditional_settings":[{"modifications":[{"required":true}],"rule_conditions":[{"validated_object":{"field_attr":"value","field_key":"intro","type":"field"},"validation":"empty","value":"empty"}],"rule_match":"all"}],"pos":3,"type":"image"}}}}' form: {} headers: {} url: https://mapi.storyblok.com/v1/spaces/233252/components/ @@ -23,15 +23,15 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 569 + content_length: 787 uncompressed: false - body: '{"component":{"name":"test-banner","display_name":null,"created_at":"2024-06-19T11:49:36.374Z","updated_at":"2024-06-19T11:49:36.374Z","id":5949850,"schema":{"title":{"pos":1,"type":"text"},"intro":{"pos":2,"type":"text"},"image":{"pos":3,"type":"image"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' + body: '{"component":{"name":"test-banner","display_name":null,"created_at":"2024-07-11T14:25:04.047Z","updated_at":"2024-07-11T14:25:04.047Z","id":6038934,"schema":{"title":{"pos":1,"type":"text"},"intro":{"pos":2,"type":"text"},"image":{"conditional_settings":[{"modifications":[{"required":true}],"rule_conditions":[{"validated_object":{"field_attr":"value","field_key":"intro","type":"field"},"validation":"empty","value":"empty"}],"rule_match":"all"}],"pos":3,"type":"image"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 129.956416ms + duration: 104.29925ms - id: 1 request: proto: HTTP/1.1 @@ -46,7 +46,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/components/5949850 + url: https://mapi.storyblok.com/v1/spaces/233252/components/6038934 method: GET response: proto: HTTP/2.0 @@ -54,15 +54,15 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 569 + content_length: 787 uncompressed: false - body: '{"component":{"name":"test-banner","display_name":null,"created_at":"2024-06-19T11:49:36.374Z","updated_at":"2024-06-19T11:49:36.374Z","id":5949850,"schema":{"title":{"pos":1,"type":"text"},"intro":{"pos":2,"type":"text"},"image":{"pos":3,"type":"image"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' + body: '{"component":{"name":"test-banner","display_name":null,"created_at":"2024-07-11T14:25:04.047Z","updated_at":"2024-07-11T14:25:04.047Z","id":6038934,"schema":{"title":{"pos":1,"type":"text"},"intro":{"pos":2,"type":"text"},"image":{"conditional_settings":[{"modifications":[{"required":true}],"rule_conditions":[{"validated_object":{"field_attr":"value","field_key":"intro","type":"field"},"validation":"empty","value":"empty"}],"rule_match":"all"}],"pos":3,"type":"image"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 106.954542ms + duration: 77.601416ms - id: 2 request: proto: HTTP/1.1 @@ -77,7 +77,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/components/5949850 + url: https://mapi.storyblok.com/v1/spaces/233252/components/6038934 method: GET response: proto: HTTP/2.0 @@ -85,15 +85,15 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 569 + content_length: 787 uncompressed: false - body: '{"component":{"name":"test-banner","display_name":null,"created_at":"2024-06-19T11:49:36.374Z","updated_at":"2024-06-19T11:49:36.374Z","id":5949850,"schema":{"title":{"pos":1,"type":"text"},"intro":{"pos":2,"type":"text"},"image":{"pos":3,"type":"image"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' + body: '{"component":{"name":"test-banner","display_name":null,"created_at":"2024-07-11T14:25:04.047Z","updated_at":"2024-07-11T14:25:04.047Z","id":6038934,"schema":{"title":{"pos":1,"type":"text"},"intro":{"pos":2,"type":"text"},"image":{"conditional_settings":[{"modifications":[{"required":true}],"rule_conditions":[{"validated_object":{"field_attr":"value","field_key":"intro","type":"field"},"validation":"empty","value":"empty"}],"rule_match":"all"}],"pos":3,"type":"image"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 43.386ms + duration: 78.886416ms - id: 3 request: proto: HTTP/1.1 @@ -108,7 +108,7 @@ interactions: body: '{"component":{"is_nestable":false,"is_root":false,"name":"new-test-banner","preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","schema":{"intro":{"pos":1,"type":"text"},"title":{"pos":2,"type":"text"},"buttons":{"filter_content_type":["button"],"pos":3,"source":"internal_stories","type":"options"}}}}' form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/components/5949850 + url: https://mapi.storyblok.com/v1/spaces/233252/components/6038934 method: PUT response: proto: HTTP/2.0 @@ -118,13 +118,13 @@ interactions: trailer: {} content_length: 642 uncompressed: false - body: '{"component":{"name":"new-test-banner","display_name":null,"created_at":"2024-06-19T11:49:36.374Z","updated_at":"2024-06-19T11:49:37.276Z","id":5949850,"schema":{"intro":{"pos":1,"type":"text"},"title":{"pos":2,"type":"text"},"buttons":{"filter_content_type":["button"],"pos":3,"source":"internal_stories","type":"options"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"new-test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' + body: '{"component":{"name":"new-test-banner","display_name":null,"created_at":"2024-07-11T14:25:04.047Z","updated_at":"2024-07-11T14:25:04.914Z","id":6038934,"schema":{"intro":{"pos":1,"type":"text"},"title":{"pos":2,"type":"text"},"buttons":{"filter_content_type":["button"],"pos":3,"source":"internal_stories","type":"options"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"new-test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 128.283917ms + duration: 115.851583ms - id: 4 request: proto: HTTP/1.1 @@ -139,7 +139,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/components/5949850 + url: https://mapi.storyblok.com/v1/spaces/233252/components/6038934 method: GET response: proto: HTTP/2.0 @@ -149,13 +149,13 @@ interactions: trailer: {} content_length: 642 uncompressed: false - body: '{"component":{"name":"new-test-banner","display_name":null,"created_at":"2024-06-19T11:49:36.374Z","updated_at":"2024-06-19T11:49:37.276Z","id":5949850,"schema":{"intro":{"pos":1,"type":"text"},"title":{"pos":2,"type":"text"},"buttons":{"filter_content_type":["button"],"pos":3,"source":"internal_stories","type":"options"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"new-test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' + body: '{"component":{"name":"new-test-banner","display_name":null,"created_at":"2024-07-11T14:25:04.047Z","updated_at":"2024-07-11T14:25:04.914Z","id":6038934,"schema":{"intro":{"pos":1,"type":"text"},"title":{"pos":2,"type":"text"},"buttons":{"filter_content_type":["button"],"pos":3,"source":"internal_stories","type":"options"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"new-test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 35.870375ms + duration: 82.617166ms - id: 5 request: proto: HTTP/1.1 @@ -170,7 +170,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/components/5949850 + url: https://mapi.storyblok.com/v1/spaces/233252/components/6038934 method: DELETE response: proto: HTTP/2.0 @@ -180,10 +180,10 @@ interactions: trailer: {} content_length: 642 uncompressed: false - body: '{"component":{"name":"new-test-banner","display_name":null,"created_at":"2024-06-19T11:49:36.374Z","updated_at":"2024-06-19T11:49:37.276Z","id":5949850,"schema":{"intro":{"pos":1,"type":"text"},"title":{"pos":2,"type":"text"},"buttons":{"filter_content_type":["button"],"pos":3,"source":"internal_stories","type":"options"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"new-test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' + body: '{"component":{"name":"new-test-banner","display_name":null,"created_at":"2024-07-11T14:25:04.047Z","updated_at":"2024-07-11T14:25:04.914Z","id":6038934,"schema":{"intro":{"pos":1,"type":"text"},"title":{"pos":2,"type":"text"},"buttons":{"filter_content_type":["button"],"pos":3,"source":"internal_stories","type":"options"}},"image":null,"preview_field":null,"is_root":false,"preview_tmpl":"\u003cdiv\u003e\u003c/div\u003e","is_nestable":false,"all_presets":[],"preset_id":null,"real_name":"new-test-banner","component_group_uuid":null,"color":null,"icon":null,"internal_tags_list":[],"internal_tag_ids":[],"content_type_asset_preview":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 109.515709ms + duration: 146.879375ms diff --git a/internal/assets/component_group.yaml b/internal/assets/component_group.yaml index 052c215..740a6fa 100644 --- a/internal/assets/component_group.yaml +++ b/internal/assets/component_group.yaml @@ -25,13 +25,13 @@ interactions: trailer: {} content_length: 145 uncompressed: false - body: '{"component_group":{"name":"test-component-group","id":357445,"uuid":"39b2bedd-508c-445c-abd0-2424bbb3ee16","parent_id":null,"parent_uuid":null}}' + body: '{"component_group":{"name":"test-component-group","id":368529,"uuid":"7a856dbd-c9f8-46cc-8f1a-ff5a1e97085b","parent_id":null,"parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 147.508ms + duration: 101.948459ms - id: 1 request: proto: HTTP/1.1 @@ -46,7 +46,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/357445 + url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/368529 method: GET response: proto: HTTP/2.0 @@ -56,13 +56,13 @@ interactions: trailer: {} content_length: 145 uncompressed: false - body: '{"component_group":{"name":"test-component-group","id":357445,"uuid":"39b2bedd-508c-445c-abd0-2424bbb3ee16","parent_id":null,"parent_uuid":null}}' + body: '{"component_group":{"name":"test-component-group","id":368529,"uuid":"7a856dbd-c9f8-46cc-8f1a-ff5a1e97085b","parent_id":null,"parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 59.843792ms + duration: 236.725792ms - id: 2 request: proto: HTTP/1.1 @@ -77,7 +77,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/357445 + url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/368529 method: GET response: proto: HTTP/2.0 @@ -87,13 +87,13 @@ interactions: trailer: {} content_length: 145 uncompressed: false - body: '{"component_group":{"name":"test-component-group","id":357445,"uuid":"39b2bedd-508c-445c-abd0-2424bbb3ee16","parent_id":null,"parent_uuid":null}}' + body: '{"component_group":{"name":"test-component-group","id":368529,"uuid":"7a856dbd-c9f8-46cc-8f1a-ff5a1e97085b","parent_id":null,"parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 40.950458ms + duration: 82.279125ms - id: 3 request: proto: HTTP/1.1 @@ -108,7 +108,7 @@ interactions: body: '{"component_group":{"name":"new-test-component-group"}}' form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/357445 + url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/368529 method: PUT response: proto: HTTP/2.0 @@ -118,13 +118,13 @@ interactions: trailer: {} content_length: 149 uncompressed: false - body: '{"component_group":{"name":"new-test-component-group","id":357445,"uuid":"39b2bedd-508c-445c-abd0-2424bbb3ee16","parent_id":null,"parent_uuid":null}}' + body: '{"component_group":{"name":"new-test-component-group","id":368529,"uuid":"7a856dbd-c9f8-46cc-8f1a-ff5a1e97085b","parent_id":null,"parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 53.853041ms + duration: 142.881417ms - id: 4 request: proto: HTTP/1.1 @@ -139,7 +139,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/357445 + url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/368529 method: GET response: proto: HTTP/2.0 @@ -149,13 +149,13 @@ interactions: trailer: {} content_length: 149 uncompressed: false - body: '{"component_group":{"name":"new-test-component-group","id":357445,"uuid":"39b2bedd-508c-445c-abd0-2424bbb3ee16","parent_id":null,"parent_uuid":null}}' + body: '{"component_group":{"name":"new-test-component-group","id":368529,"uuid":"7a856dbd-c9f8-46cc-8f1a-ff5a1e97085b","parent_id":null,"parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 90.631875ms + duration: 84.502167ms - id: 5 request: proto: HTTP/1.1 @@ -170,7 +170,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/357445 + url: https://mapi.storyblok.com/v1/spaces/233252/component_groups/368529 method: DELETE response: proto: HTTP/2.0 @@ -180,10 +180,10 @@ interactions: trailer: {} content_length: 149 uncompressed: false - body: '{"component_group":{"name":"new-test-component-group","id":357445,"uuid":"39b2bedd-508c-445c-abd0-2424bbb3ee16","parent_id":null,"parent_uuid":null}}' + body: '{"component_group":{"name":"new-test-component-group","id":368529,"uuid":"7a856dbd-c9f8-46cc-8f1a-ff5a1e97085b","parent_id":null,"parent_uuid":null}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 1.759588959s + duration: 1.86876175s diff --git a/internal/assets/space_role.yaml b/internal/assets/space_role.yaml index b43ecd2..259056e 100644 --- a/internal/assets/space_role.yaml +++ b/internal/assets/space_role.yaml @@ -25,13 +25,13 @@ interactions: trailer: {} content_length: 359 uncompressed: false - body: '{"space_role":{"id":67200,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"tester","subtitle":"A test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"FizBuz"}}' + body: '{"space_role":{"id":67553,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"tester","subtitle":"A test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"FizBuz"}}' headers: Content-Type: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 133.641292ms + duration: 125.047042ms - id: 1 request: proto: HTTP/1.1 @@ -46,7 +46,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67200 + url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67553 method: GET response: proto: HTTP/2.0 @@ -56,13 +56,13 @@ interactions: trailer: {} content_length: 359 uncompressed: false - body: '{"space_role":{"id":67200,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"tester","subtitle":"A test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"FizBuz"}}' + body: '{"space_role":{"id":67553,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"tester","subtitle":"A test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"FizBuz"}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 38.298ms + duration: 86.834792ms - id: 2 request: proto: HTTP/1.1 @@ -77,7 +77,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67200 + url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67553 method: GET response: proto: HTTP/2.0 @@ -87,13 +87,13 @@ interactions: trailer: {} content_length: 359 uncompressed: false - body: '{"space_role":{"id":67200,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"tester","subtitle":"A test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"FizBuz"}}' + body: '{"space_role":{"id":67553,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"tester","subtitle":"A test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"FizBuz"}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 44.116541ms + duration: 90.119083ms - id: 3 request: proto: HTTP/1.1 @@ -108,7 +108,7 @@ interactions: body: '{"space_role":{"allowed_languages":["default"],"allowed_paths":["1"],"ext_id":"BuzFiz","field_permissions":["component_name.field_name"],"permissions":["access_tasks"],"role":"new-tester","subtitle":"A new test group"}}' form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67200 + url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67553 method: PUT response: proto: HTTP/2.0 @@ -118,13 +118,13 @@ interactions: trailer: {} content_length: 367 uncompressed: false - body: '{"space_role":{"id":67200,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"new-tester","subtitle":"A new test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"BuzFiz"}}' + body: '{"space_role":{"id":67553,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"new-tester","subtitle":"A new test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"BuzFiz"}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 83.993708ms + duration: 174.415375ms - id: 4 request: proto: HTTP/1.1 @@ -139,7 +139,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67200 + url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67553 method: GET response: proto: HTTP/2.0 @@ -149,13 +149,13 @@ interactions: trailer: {} content_length: 367 uncompressed: false - body: '{"space_role":{"id":67200,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"new-tester","subtitle":"A new test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"BuzFiz"}}' + body: '{"space_role":{"id":67553,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"new-tester","subtitle":"A new test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"BuzFiz"}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 46.350167ms + duration: 93.840708ms - id: 5 request: proto: HTTP/1.1 @@ -170,7 +170,7 @@ interactions: body: "" form: {} headers: {} - url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67200 + url: https://mapi.storyblok.com/v1/spaces/233252/space_roles/67553 method: DELETE response: proto: HTTP/2.0 @@ -180,10 +180,10 @@ interactions: trailer: {} content_length: 367 uncompressed: false - body: '{"space_role":{"id":67200,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"new-tester","subtitle":"A new test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"BuzFiz"}}' + body: '{"space_role":{"id":67553,"resolved_allowed_paths":[],"allowed_paths":["1"],"field_permissions":["component_name.field_name"],"readonly_field_permissions":[],"permissions":["access_tasks"],"role":"new-tester","subtitle":"A new test group","datasource_ids":[],"component_ids":[],"branch_ids":[],"allowed_languages":["default"],"asset_folder_ids":[],"ext_id":"BuzFiz"}}' headers: Content-Type: - application/json; charset=utf-8 status: 200 OK code: 200 - duration: 86.8515ms + duration: 121.799292ms diff --git a/internal/component_resource_test.go b/internal/component_resource_test.go index dae9b9c..142e7b3 100644 --- a/internal/component_resource_test.go +++ b/internal/component_resource_test.go @@ -29,6 +29,10 @@ func TestComponentResourceBasic(t *testing.T) { resource.TestCheckResourceAttr(rn, "schema.intro.type", "text"), resource.TestCheckResourceAttr(rn, "schema.image.position", "3"), resource.TestCheckResourceAttr(rn, "schema.image.type", "image"), + resource.TestCheckResourceAttr(rn, "schema.image.conditional_settings.0.modifications.0.required", "true"), + resource.TestCheckResourceAttr(rn, "schema.image.conditional_settings.0.rule_match", "all"), + resource.TestCheckResourceAttr(rn, "schema.image.conditional_settings.0.rule_conditions.0.validation", "empty"), + resource.TestCheckResourceAttr(rn, "schema.image.conditional_settings.0.rule_conditions.0.validated_object.field_key", "intro"), ), }, { @@ -51,25 +55,45 @@ func TestComponentResourceBasic(t *testing.T) { func testComponentConfig(identifier string, spaceId int) string { return HCLTemplate(` resource "storyblok_component" "{{ .identifier }}" { - name = "test-banner" - space_id = "{{ .spaceId }}" - schema = { - title = { - type = "text" - position = 1 - } - - intro = { - type = "text" - position = 2 - } - - image = { - type = "image" - position = 3 + name = "test-banner" + space_id = "{{ .spaceId }}" + schema = { + title = { + type = "text" + position = 1 + } + + intro = { + type = "text" + position = 2 + } + + image = { + type = "image" + position = 3 + + conditional_settings = [ + { + modifications = [ + { + required = true + } + ] + + rule_match = "all" + rule_conditions = [ + { + validation = "empty" + validated_object = { + field_key = "intro" + } + } + ] + } + ] } - } - preview_tmpl = "
" + } + preview_tmpl = "
" } `, map[string]any{ "identifier": identifier, From 99dc3d570506c415fb768e05134ddf1b7822d022 Mon Sep 17 00:00:00 2001 From: Paul Vaneveld Date: Thu, 18 Jul 2024 10:15:15 +0200 Subject: [PATCH 6/7] chore: bump go-sdk to 0.6.0 --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 1b45167..2af27e6 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/hashicorp/terraform-plugin-docs v0.19.2 github.com/hashicorp/terraform-plugin-framework v1.8.0 github.com/hashicorp/terraform-plugin-log v0.9.0 - github.com/labd/storyblok-go-sdk v0.5.0 + github.com/labd/storyblok-go-sdk v0.6.0 github.com/wk8/go-ordered-map/v2 v2.1.8 ) diff --git a/go.sum b/go.sum index 367394a..e558e2e 100644 --- a/go.sum +++ b/go.sum @@ -158,6 +158,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labd/storyblok-go-sdk v0.5.0 h1:Nv+sq6jJm1UfP3BArnNd/XbHRQl2AVyXiJ0fwoBI33Q= github.com/labd/storyblok-go-sdk v0.5.0/go.mod h1:79Zb12MZIzs2qF0FLZKLLGC8ijubZLn3/VaK76XdvWs= +github.com/labd/storyblok-go-sdk v0.6.0 h1:yM6wVTn2/OqyjlnaVUJKVnnI+vSu5isjap9zIP/eWKM= +github.com/labd/storyblok-go-sdk v0.6.0/go.mod h1:79Zb12MZIzs2qF0FLZKLLGC8ijubZLn3/VaK76XdvWs= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= From a36bde5bb7dd4f381356f1927e096d7bb20f95c5 Mon Sep 17 00:00:00 2001 From: Paul Vaneveld Date: Thu, 18 Jul 2024 10:19:18 +0200 Subject: [PATCH 7/7] chore: edit format task and execute --- Taskfile.yml | 1 + examples/resources/storyblok_component_group/resource.tf | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 87af4ea..130f9ac 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -16,6 +16,7 @@ tasks: format: cmds: - go fmt ./... + - terraform fmt -recursive -write=true ./examples/ test: cmds: diff --git a/examples/resources/storyblok_component_group/resource.tf b/examples/resources/storyblok_component_group/resource.tf index d5f6f62..aa4846d 100644 --- a/examples/resources/storyblok_component_group/resource.tf +++ b/examples/resources/storyblok_component_group/resource.tf @@ -4,8 +4,8 @@ resource "storyblok_component_group" "my_component_group" { } resource "storyblok_component" "component1" { - name = "component1" - space_id = storyblok_component_group.my_component_group.space_id + name = "component1" + space_id = storyblok_component_group.my_component_group.space_id component_group_uuid = storyblok_component_group.my_component_group.uuid schema = { @@ -17,8 +17,8 @@ resource "storyblok_component" "component1" { } resource "storyblok_component" "component2" { - name = "component2" - space_id = storyblok_component_group.my_component_group.space_id + name = "component2" + space_id = storyblok_component_group.my_component_group.space_id component_group_uuid = storyblok_component_group.my_component_group.uuid schema = {