decidim-chatbot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.erb_lint.yml +2134 -0
- data/.github/workflows/website.yml +57 -0
- data/.gitignore +13 -0
- data/.gitlab-ci.yml +204 -0
- data/.node-version +1 -0
- data/.nvmrc +1 -0
- data/.rspec +2 -0
- data/.rubocop.yml +17 -0
- data/.ruby-version +1 -0
- data/.simplecov +36 -0
- data/CONTRIBUTING.md +54 -0
- data/Gemfile +50 -0
- data/Gemfile.lock +1013 -0
- data/LICENSE.md +661 -0
- data/README.md +62 -0
- data/Rakefile +54 -0
- data/app/commands/decidim/chatbot/admin/destroy_item.rb +25 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_exit.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_login.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_propose_proposals.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_read_blogs.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_read_proposals.rb +12 -0
- data/app/commands/decidim/chatbot/admin/menu_items/update_vote_on_proposal.rb +12 -0
- data/app/commands/decidim/chatbot/admin/notifications/update_manual.rb +12 -0
- data/app/commands/decidim/chatbot/admin/notifications/update_phase.rb +12 -0
- data/app/commands/decidim/chatbot/admin/persist_item.rb +47 -0
- data/app/commands/decidim/chatbot/admin/reorder_items.rb +51 -0
- data/app/commands/decidim/chatbot/admin/send_test_notification.rb +74 -0
- data/app/commands/decidim/chatbot/admin/unsubscribe_user.rb +35 -0
- data/app/commands/decidim/chatbot/admin/update_chatbot.rb +17 -0
- data/app/commands/decidim/chatbot/notifications/deliver.rb +30 -0
- data/app/commands/decidim/chatbot/notifications/enqueue_phase.rb +67 -0
- data/app/commands/decidim/chatbot/notifications/send.rb +115 -0
- data/app/commands/decidim/chatbot/whatsapp/create_from_phone.rb +95 -0
- data/app/commands/decidim/chatbot/whatsapp/sync_phone.rb +56 -0
- data/app/controllers/decidim/api/rest_full/chatbot/base_controller.rb +52 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbot_menu_items_controller.rb +49 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbot_users_controller.rb +46 -0
- data/app/controllers/decidim/api/rest_full/chatbot/chatbots_controller.rb +40 -0
- data/app/controllers/decidim/chatbot/admin/chatbot_edit.rb +85 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/generals_controller.rb +43 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/menu_items_controller.rb +32 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/notifications_controller.rb +92 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/users/filterable.rb +33 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/users_controller.rb +53 -0
- data/app/controllers/decidim/chatbot/admin/chatbots/whatsapps_controller.rb +59 -0
- data/app/controllers/decidim/chatbot/admin/chatbots_controller.rb +20 -0
- data/app/controllers/decidim/chatbot/admin/items_crud.rb +183 -0
- data/app/forms/decidim/chatbot/admin/chatbot_form.rb +20 -0
- data/app/forms/decidim/chatbot/admin/config_form.rb +20 -0
- data/app/forms/decidim/chatbot/admin/menu_item_form.rb +80 -0
- data/app/forms/decidim/chatbot/admin/menu_items/component_id_form.rb +60 -0
- data/app/forms/decidim/chatbot/admin/menu_items/exit_form.rb +24 -0
- data/app/forms/decidim/chatbot/admin/menu_items/login_form.rb +35 -0
- data/app/forms/decidim/chatbot/admin/menu_items/propose_proposals_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/propose_proposals_labels.rb +53 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_blogs_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_content_labels.rb +51 -0
- data/app/forms/decidim/chatbot/admin/menu_items/read_proposals_form.rb +23 -0
- data/app/forms/decidim/chatbot/admin/menu_items/vote_on_proposal_form.rb +123 -0
- data/app/forms/decidim/chatbot/admin/notification_item_form.rb +111 -0
- data/app/forms/decidim/chatbot/admin/notifications/manual_form.rb +13 -0
- data/app/forms/decidim/chatbot/admin/notifications/phase_form.rb +79 -0
- data/app/forms/decidim/chatbot/admin/notifications/template_fields.rb +60 -0
- data/app/forms/decidim/chatbot/admin/notifications/test_form.rb +179 -0
- data/app/helpers/decidim/chatbot/admin/items_helper.rb +44 -0
- data/app/jobs/decidim/chatbot/chatbot_webhook_job.rb +59 -0
- data/app/jobs/decidim/chatbot/send_notification_job.rb +33 -0
- data/app/models/decidim/chatbot/chatbot.rb +47 -0
- data/app/models/decidim/chatbot/item.rb +99 -0
- data/app/packs/.keep +0 -0
- data/app/presenters/decidim/chatbot/admin_log/chatbot_presenter.rb +42 -0
- data/app/presenters/decidim/chatbot/admin_log/item_presenter.rb +32 -0
- data/app/queries/decidim/chatbot/admin/proposal_vote_mode.rb +41 -0
- data/app/queries/decidim/chatbot/whatsapp_users.rb +58 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_menu_item_serializer.rb +113 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_notification_serializer.rb +19 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_serializer.rb +66 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_user_identity_serializer.rb +23 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_user_serializer.rb +28 -0
- data/app/serializers/decidim/api/rest_full/chatbot/chatbot_webhook_serializer.rb +21 -0
- data/app/services/decidim/chatbot/chatbot_webhook_handler.rb +40 -0
- data/app/services/decidim/chatbot/notifications/bindings.rb +87 -0
- data/app/services/decidim/chatbot/whatsapp/body_parameters.rb +29 -0
- data/app/services/decidim/chatbot/whatsapp/graph_client.rb +136 -0
- data/app/services/decidim/chatbot/whatsapp/status_mapper.rb +93 -0
- data/app/services/decidim/chatbot/whatsapp/template_manager_url.rb +35 -0
- data/app/views/decidim/chatbot/admin/chatbots/generals/_menu_preview.html.erb +49 -0
- data/app/views/decidim/chatbot/admin/chatbots/generals/edit.html.erb +79 -0
- data/app/views/decidim/chatbot/admin/chatbots/index.html.erb +50 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/_form.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/edit.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/index.html.erb +43 -0
- data/app/views/decidim/chatbot/admin/chatbots/menu_items/new.html.erb +12 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_form.html.erb +4 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_manual_fields.html.erb +8 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/_phase_fields.html.erb +6 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/edit.html.erb +3 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/index.html.erb +40 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/new.html.erb +11 -0
- data/app/views/decidim/chatbot/admin/chatbots/notifications/test.html.erb +35 -0
- data/app/views/decidim/chatbot/admin/chatbots/tabs/_whatsapp.html.erb +47 -0
- data/app/views/decidim/chatbot/admin/chatbots/users/_filters.html.erb +23 -0
- data/app/views/decidim/chatbot/admin/chatbots/users/index.html.erb +56 -0
- data/app/views/decidim/chatbot/admin/chatbots/whatsapps/show.html.erb +5 -0
- data/app/views/decidim/chatbot/admin/shared/_item_form.html.erb +64 -0
- data/app/views/decidim/chatbot/admin/shared/_row_actions.html.erb +28 -0
- data/app/views/decidim/chatbot/admin/shared/_tabs_menu.html.erb +13 -0
- data/app/views/decidim/chatbot/admin/shared/_type_fields.html.erb +2 -0
- data/app/views/decidim/chatbot/admin/shared/_type_picker.html.erb +15 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_component_id.html.erb +9 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_exit.html.erb +5 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_login.html.erb +8 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_manual.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_phase.html.erb +46 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_propose_proposals.html.erb +10 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_read_blogs.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_read_proposals.html.erb +16 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/_vote_on_proposal.html.erb +26 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_abstention_label.html.erb +7 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_vote_label.html.erb +7 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_votes_closed_warning.html.erb +6 -0
- data/app/views/decidim/chatbot/admin/shared/type_fields/vote/_shows_weight_labels.html.erb +15 -0
- data/bin/check +13 -0
- data/bin/ci-setup +38 -0
- data/bin/gen-node-client +112 -0
- data/bin/gen-openapi +248 -0
- data/bin/i18n-tasks +27 -0
- data/bin/postversion +17 -0
- data/config/i18n-tasks.yml +38 -0
- data/config/locales/decidim_chatbot.en.yml +323 -0
- data/config/locales/decidim_chatbot.fr.yml +29 -0
- data/contrib/decidim-node-client/.gitignore +4 -0
- data/contrib/decidim-node-client/.npmignore +1 -0
- data/contrib/decidim-node-client/.openapi-generator/FILES +8 -0
- data/contrib/decidim-node-client/.openapi-generator/VERSION +1 -0
- data/contrib/decidim-node-client/.openapi-generator-ignore +13 -0
- data/contrib/decidim-node-client/.yarnrc.yml +5 -0
- data/contrib/decidim-node-client/README.md +37 -0
- data/contrib/decidim-node-client/api.ts +14193 -0
- data/contrib/decidim-node-client/base.ts +70 -0
- data/contrib/decidim-node-client/common.ts +185 -0
- data/contrib/decidim-node-client/configuration.ts +138 -0
- data/contrib/decidim-node-client/git_push.sh +57 -0
- data/contrib/decidim-node-client/index.ts +16 -0
- data/contrib/decidim-node-client/package.json +49 -0
- data/contrib/decidim-node-client/packup.config.ts +7 -0
- data/contrib/decidim-node-client/tsconfig.json +25 -0
- data/contrib/decidim-node-client/yarn.lock +2367 -0
- data/crowdin.yml +15 -0
- data/db/migrate/20260725120000_create_decidim_chatbot_chatbots.rb +20 -0
- data/db/migrate/20260822120000_create_decidim_chatbot_items.rb +20 -0
- data/db/migrate/20260824120000_add_menu_and_error_copy_to_decidim_chatbot_chatbots.rb +13 -0
- data/db/migrate/20260824140000_add_enabled_to_decidim_chatbot_items.rb +7 -0
- data/decidim-chatbot.gemspec +40 -0
- data/docker-compose.ci.yml +59 -0
- data/docker-compose.yml +47 -0
- data/lib/decidim/chatbot/admin_engine.rb +67 -0
- data/lib/decidim/chatbot/admin_menu.rb +41 -0
- data/lib/decidim/chatbot/default_manifests.rb +91 -0
- data/lib/decidim/chatbot/engine.rb +107 -0
- data/lib/decidim/chatbot/manifest.rb +31 -0
- data/lib/decidim/chatbot/menu_item_label_keys.rb +26 -0
- data/lib/decidim/chatbot/registry.rb +42 -0
- data/lib/decidim/chatbot/rest_full_ability.rb +24 -0
- data/lib/decidim/chatbot/settings_tab.rb +18 -0
- data/lib/decidim/chatbot/test_definitions.rb +352 -0
- data/lib/decidim/chatbot/variable_interpolator.rb +30 -0
- data/lib/decidim/chatbot/version.rb +21 -0
- data/lib/decidim/chatbot/webhook_publisher.rb +29 -0
- data/lib/decidim/chatbot.rb +41 -0
- data/lib/decidim-chatbot.rb +3 -0
- data/lib/tasks/chatbot.rake +64 -0
- data/openapi/openapi.json +37801 -0
- data/openapitools.json +7 -0
- data/package.json +22 -0
- data/prettier.config.js +15 -0
- data/spec/commands/decidim/chatbot/admin/destroy_item_spec.rb +24 -0
- data/spec/commands/decidim/chatbot/admin/persist_item_spec.rb +80 -0
- data/spec/commands/decidim/chatbot/admin/reorder_items_spec.rb +53 -0
- data/spec/commands/decidim/chatbot/admin/send_test_notification_spec.rb +105 -0
- data/spec/commands/decidim/chatbot/admin/unsubscribe_user_spec.rb +46 -0
- data/spec/commands/decidim/chatbot/admin/update_chatbot_spec.rb +56 -0
- data/spec/commands/decidim/chatbot/notifications/enqueue_phase_spec.rb +59 -0
- data/spec/commands/decidim/chatbot/notifications/send_spec.rb +101 -0
- data/spec/commands/decidim/chatbot/whatsapp/create_from_phone_spec.rb +122 -0
- data/spec/commands/decidim/chatbot/whatsapp/sync_phone_spec.rb +110 -0
- data/spec/controllers/decidim/chatbot/admin/chatbots_controller_spec.rb +25 -0
- data/spec/factories/chatbot.rb +44 -0
- data/spec/forms/decidim/chatbot/admin/chatbot_form_spec.rb +41 -0
- data/spec/forms/decidim/chatbot/admin/config_form_spec.rb +30 -0
- data/spec/forms/decidim/chatbot/admin/menu_item_form_spec.rb +49 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/component_id_form_spec.rb +54 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/component_id_forms_spec.rb +512 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/exit_form_spec.rb +39 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/login_form_spec.rb +101 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/propose_proposals_form_prefill_spec.rb +26 -0
- data/spec/forms/decidim/chatbot/admin/menu_items/read_blogs_form_prefill_spec.rb +22 -0
- data/spec/forms/decidim/chatbot/admin/notifications/manual_form_spec.rb +130 -0
- data/spec/forms/decidim/chatbot/admin/notifications/phase_form_spec.rb +79 -0
- data/spec/forms/decidim/chatbot/admin/notifications/test_form_spec.rb +172 -0
- data/spec/jobs/decidim/chatbot/chatbot_webhook_job_spec.rb +47 -0
- data/spec/jobs/decidim/chatbot/send_notification_job_spec.rb +53 -0
- data/spec/lib/decidim/chatbot/engine_spec.rb +44 -0
- data/spec/lib/decidim/chatbot/registry_spec.rb +30 -0
- data/spec/lib/decidim/chatbot/settings_tab_spec.rb +21 -0
- data/spec/lib/decidim/chatbot/variable_interpolator_spec.rb +34 -0
- data/spec/lib/decidim/chatbot/whatsapp/status_mapper_spec.rb +64 -0
- data/spec/lib/decidim/chatbot_spec.rb +59 -0
- data/spec/models/decidim/chatbot/chatbot_spec.rb +23 -0
- data/spec/models/decidim/chatbot/item_spec.rb +88 -0
- data/spec/presenters/decidim/chatbot/admin_log/chatbot_presenter_spec.rb +64 -0
- data/spec/queries/decidim/chatbot/admin/proposal_vote_mode_spec.rb +74 -0
- data/spec/queries/decidim/chatbot/whatsapp_users_spec.rb +57 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbot_menu_items_controller_spec.rb +344 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbot_users_controller_spec.rb +140 -0
- data/spec/requests/decidim/api/rest_full/chatbot/chatbots_controller_spec.rb +195 -0
- data/spec/requests/decidim/chatbot/admin/chatbots/notifications_controller_spec.rb +44 -0
- data/spec/requests/decidim/chatbot/admin/tenant_isolation_spec.rb +133 -0
- data/spec/requests/decidim/chatbot/admin/unsubscribe_user_spec.rb +28 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_menu_item_serializer_spec.rb +321 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_serializer_spec.rb +49 -0
- data/spec/serializers/decidim/api/rest_full/chatbot/chatbot_user_serializer_spec.rb +40 -0
- data/spec/services/decidim/chatbot/chatbot_webhook_handler_spec.rb +43 -0
- data/spec/services/decidim/chatbot/notifications/bindings_spec.rb +86 -0
- data/spec/services/decidim/chatbot/whatsapp/body_parameters_spec.rb +22 -0
- data/spec/services/decidim/chatbot/whatsapp/graph_client_spec.rb +205 -0
- data/spec/services/decidim/chatbot/whatsapp/template_manager_url_spec.rb +33 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/allow_all_hosts.rb +9 -0
- data/spec/support/chatbot_admin.rb +16 -0
- data/spec/support/decidim_factories.rb +7 -0
- data/spec/support/decidim_system_factories.rb +3 -0
- data/spec/support/devise.rb +5 -0
- data/spec/support/rack_test_system_driver.rb +43 -0
- data/spec/support/whatsapp_graph.rb +15 -0
- data/spec/swagger_helper.rb +47 -0
- data/spec/system/decidim/chatbot/admin/admin_can_send_manual_when_ready_spec.rb +35 -0
- data/spec/system/decidim/chatbot/admin/admin_configures_vote_on_proposal_menu_item_spec.rb +84 -0
- data/spec/system/decidim/chatbot/admin/admin_confirms_send_now_recipient_count_spec.rb +40 -0
- data/spec/system/decidim/chatbot/admin/admin_creates_menu_item_with_demo_field_spec.rb +65 -0
- data/spec/system/decidim/chatbot/admin/admin_creates_phase_and_manual_notifications_spec.rb +52 -0
- data/spec/system/decidim/chatbot/admin/admin_does_not_see_other_org_processes_in_phase_select_spec.rb +27 -0
- data/spec/system/decidim/chatbot/admin/admin_does_not_see_other_organization_chatbots_spec.rb +25 -0
- data/spec/system/decidim/chatbot/admin/admin_is_redirected_when_chatbot_is_disabled_spec.rb +28 -0
- data/spec/system/decidim/chatbot/admin/admin_lists_organization_chatbots_spec.rb +36 -0
- data/spec/system/decidim/chatbot/admin/admin_manual_notification_sends_with_nickname_spec.rb +68 -0
- data/spec/system/decidim/chatbot/admin/admin_navigates_chatbot_main_tabs_spec.rb +52 -0
- data/spec/system/decidim/chatbot/admin/admin_phase_notification_sends_on_step_change_spec.rb +79 -0
- data/spec/system/decidim/chatbot/admin/admin_picks_published_blog_component_spec.rb +205 -0
- data/spec/system/decidim/chatbot/admin/admin_picks_published_participatory_space_spec.rb +45 -0
- data/spec/system/decidim/chatbot/admin/admin_reorders_chatbot_menu_items_spec.rb +29 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_disabled_menu_item_faded_on_the_table_spec.rb +23 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_disabled_notification_item_faded_on_the_table_spec.rb +40 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_notification_facts_and_frozen_template_name_spec.rb +71 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_propose_proposals_defaults_prefilled_spec.rb +119 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_type_specific_fields_spec.rb +89 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_whatsapp_facts_and_can_sync_spec.rb +48 -0
- data/spec/system/decidim/chatbot/admin/admin_sees_whatsapp_template_edit_link_spec.rb +37 -0
- data/spec/system/decidim/chatbot/admin/admin_tests_notification_spec.rb +125 -0
- data/spec/system/decidim/chatbot/admin/admin_unchecks_enabled_on_a_menu_item_spec.rb +30 -0
- data/spec/system/decidim/chatbot/admin/admin_unsubscribes_whatsapp_user_from_chatbot_spec.rb +35 -0
- data/spec/system/decidim/chatbot/admin/admin_updates_welcome_message_from_general_tab_spec.rb +84 -0
- data/spec/system/decidim/chatbot/system/admin_updates_organization_chatbot_settings_spec.rb +33 -0
- data/spec/tasks/chatbot_create_spec.rb +99 -0
- data/spec/tasks/chatbot_sync_spec.rb +90 -0
- data/website/.node-version +1 -0
- data/website/.nvmrc +1 -0
- data/website/docs/developer/_category_.json +4 -0
- data/website/docs/developer/contribute.md +87 -0
- data/website/docs/index.md +42 -0
- data/website/docs/integrate/_category_.json +4 -0
- data/website/docs/integrate/index.md +214 -0
- data/website/docusaurus.config.ts +93 -0
- data/website/package.json +37 -0
- data/website/sidebars.ts +7 -0
- data/website/src/css/custom.css +37 -0
- data/website/static/api-docs.html +2218 -0
- data/website/static/img/logo.svg +1 -0
- data/website/static/openapi.json +37801 -0
- data/website/tsconfig.json +6 -0
- data/website/yarn.lock +9782 -0
- data/yarn.lock +1003 -0
- metadata +424 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Api::RestFull::Chatbot::ChatbotMenuItemSerializer do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:chatbot) { create(:chatbot, organization:) }
|
|
8
|
+
let(:params) { { locales: [:en], host: organization.host } }
|
|
9
|
+
|
|
10
|
+
def serialize(item)
|
|
11
|
+
described_class.new(item, params:).serializable_hash
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def data_of(item)
|
|
15
|
+
hash = serialize(item)
|
|
16
|
+
(hash[:data] || hash["data"]).with_indifferent_access
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "uses dynamic type for login" do
|
|
20
|
+
item = create(:chatbot_item, chatbot:, manifest_name: "login")
|
|
21
|
+
data = data_of(item)
|
|
22
|
+
attrs = data[:attributes]
|
|
23
|
+
|
|
24
|
+
expect(data[:type]).to eq("chatbot_menu_item_login")
|
|
25
|
+
expect(attrs[:redirect_path]).to eq("/users/sign_in")
|
|
26
|
+
expect(attrs[:response_label]).to eq({ "en" => "Open {{login_url}}" })
|
|
27
|
+
expect(attrs[:manifest_name]).to eq("login")
|
|
28
|
+
expect(attrs).not_to have_key(:confirm_label)
|
|
29
|
+
expect(attrs).not_to have_key(:component_id)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "serializes response_label for exit" do
|
|
33
|
+
item = create(
|
|
34
|
+
:chatbot_item,
|
|
35
|
+
chatbot:,
|
|
36
|
+
manifest_name: "exit",
|
|
37
|
+
settings: { "response_label" => { "en" => "Bye" } }
|
|
38
|
+
)
|
|
39
|
+
data = data_of(item)
|
|
40
|
+
attrs = data[:attributes]
|
|
41
|
+
|
|
42
|
+
expect(data[:type]).to eq("chatbot_menu_item_exit")
|
|
43
|
+
expect(attrs[:response_label]).to eq({ "en" => "Bye" })
|
|
44
|
+
expect(attrs).not_to have_key(:redirect_path)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "serializes component_id for read_blogs" do
|
|
48
|
+
item = create(
|
|
49
|
+
:chatbot_item,
|
|
50
|
+
chatbot:,
|
|
51
|
+
manifest_name: "read_blogs",
|
|
52
|
+
settings: {
|
|
53
|
+
"component_id" => 42,
|
|
54
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
55
|
+
"read_more_button_label" => { "en" => "Read more" },
|
|
56
|
+
"nothing_to_read_label" => { "en" => "Nothing to read" }
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
data = data_of(item)
|
|
60
|
+
attrs = data[:attributes]
|
|
61
|
+
|
|
62
|
+
expect(data[:type]).to eq("chatbot_menu_item_read_blogs")
|
|
63
|
+
expect(attrs[:component_id]).to eq(42)
|
|
64
|
+
expect(attrs[:menu_button_label]).to eq({ "en" => "Back to menu" })
|
|
65
|
+
expect(attrs[:read_more_button_label]).to eq({ "en" => "Read more" })
|
|
66
|
+
expect(attrs[:nothing_to_read_label]).to eq({ "en" => "Nothing to read" })
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "serializes menu labels for read_proposals" do
|
|
70
|
+
item = create(
|
|
71
|
+
:chatbot_item,
|
|
72
|
+
chatbot:,
|
|
73
|
+
manifest_name: "read_proposals",
|
|
74
|
+
settings: {
|
|
75
|
+
"component_id" => 22,
|
|
76
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
77
|
+
"read_more_button_label" => { "en" => "Read more" },
|
|
78
|
+
"nothing_to_read_label" => { "en" => "Nothing to read" }
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
data = data_of(item)
|
|
82
|
+
attrs = data[:attributes]
|
|
83
|
+
|
|
84
|
+
expect(data[:type]).to eq("chatbot_menu_item_read_proposals")
|
|
85
|
+
expect(attrs[:component_id]).to eq(22)
|
|
86
|
+
expect(attrs[:menu_button_label]).to eq({ "en" => "Back to menu" })
|
|
87
|
+
expect(attrs[:read_more_button_label]).to eq({ "en" => "Read more" })
|
|
88
|
+
expect(attrs[:nothing_to_read_label]).to eq({ "en" => "Nothing to read" })
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# rubocop:disable RSpec/ExampleLength -- asserts every propose label attribute
|
|
92
|
+
it "serializes propose labels for propose_proposals" do
|
|
93
|
+
item = create(
|
|
94
|
+
:chatbot_item,
|
|
95
|
+
chatbot:,
|
|
96
|
+
manifest_name: "propose_proposals",
|
|
97
|
+
settings: {
|
|
98
|
+
"component_id" => 33,
|
|
99
|
+
"default_title_label" => { "en" => "{{id}} Anonymous proposal" },
|
|
100
|
+
"body_label" => { "en" => "Please write your proposal" },
|
|
101
|
+
"verification_label" => { "en" => "Thanks, here is your proposal:" },
|
|
102
|
+
"action_prompt_label" => { "en" => "What do you want to do with the proposal?" },
|
|
103
|
+
"save_button_label" => { "en" => "Save" },
|
|
104
|
+
"success_label" => { "en" => "Your proposal has been submitted" },
|
|
105
|
+
"withdraw_button_label" => { "en" => "Withdraw" },
|
|
106
|
+
"withdraw_success_label" => { "en" => "Your proposal has been withdrawn" },
|
|
107
|
+
"creation_not_enabled_label" => {
|
|
108
|
+
"en" => "Proposal creation is not available right now, please come back later."
|
|
109
|
+
},
|
|
110
|
+
"title_blank_label" => { "en" => "cannot be blank" },
|
|
111
|
+
"body_blank_label" => { "en" => "cannot be blank" },
|
|
112
|
+
"title_must_start_with_caps_label" => { "en" => "must start with a capital letter" },
|
|
113
|
+
"body_must_start_with_caps_label" => { "en" => "must start with a capital letter" },
|
|
114
|
+
"title_too_much_caps_label" => { "en" => "is using too many capital letters (over 25% of the text)" },
|
|
115
|
+
"body_too_much_caps_label" => { "en" => "is using too many capital letters (over 25% of the text)" },
|
|
116
|
+
"title_too_short_label" => { "en" => "is too short (under %{count} characters)" },
|
|
117
|
+
"body_too_short_label" => { "en" => "is too short (under %{count} characters)" },
|
|
118
|
+
"title_too_long_label" => { "en" => "is too long (maximum is %{count} characters)" },
|
|
119
|
+
"body_too_long_label" => { "en" => "is too long (maximum is %{count} characters)" },
|
|
120
|
+
"title_too_many_marks_label" => { "en" => "is using too many consecutive punctuation marks (e.g. ! and ?)" },
|
|
121
|
+
"body_too_many_marks_label" => { "en" => "is using too many consecutive punctuation marks (e.g. ! and ?)" }
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
data = data_of(item)
|
|
125
|
+
attrs = data[:attributes]
|
|
126
|
+
|
|
127
|
+
expect(data[:type]).to eq("chatbot_menu_item_propose_proposals")
|
|
128
|
+
expect(attrs[:component_id]).to eq(33)
|
|
129
|
+
expect(attrs[:default_title_label]).to eq({ "en" => "{{id}} Anonymous proposal" })
|
|
130
|
+
expect(attrs[:body_label]).to eq({ "en" => "Please write your proposal" })
|
|
131
|
+
expect(attrs[:verification_label]).to eq({ "en" => "Thanks, here is your proposal:" })
|
|
132
|
+
expect(attrs[:action_prompt_label]).to eq({ "en" => "What do you want to do with the proposal?" })
|
|
133
|
+
expect(attrs[:save_button_label]).to eq({ "en" => "Save" })
|
|
134
|
+
expect(attrs[:success_label]).to eq({ "en" => "Your proposal has been submitted" })
|
|
135
|
+
expect(attrs[:withdraw_button_label]).to eq({ "en" => "Withdraw" })
|
|
136
|
+
expect(attrs[:withdraw_success_label]).to eq({ "en" => "Your proposal has been withdrawn" })
|
|
137
|
+
expect(attrs[:creation_not_enabled_label]).to eq(
|
|
138
|
+
{ "en" => "Proposal creation is not available right now, please come back later." }
|
|
139
|
+
)
|
|
140
|
+
expect(attrs[:title_blank_label]).to eq({ "en" => "cannot be blank" })
|
|
141
|
+
expect(attrs[:body_blank_label]).to eq({ "en" => "cannot be blank" })
|
|
142
|
+
expect(attrs[:title_must_start_with_caps_label]).to eq({ "en" => "must start with a capital letter" })
|
|
143
|
+
expect(attrs[:body_must_start_with_caps_label]).to eq({ "en" => "must start with a capital letter" })
|
|
144
|
+
expect(attrs[:title_too_much_caps_label]).to eq(
|
|
145
|
+
{ "en" => "is using too many capital letters (over 25% of the text)" }
|
|
146
|
+
)
|
|
147
|
+
expect(attrs[:body_too_much_caps_label]).to eq(
|
|
148
|
+
{ "en" => "is using too many capital letters (over 25% of the text)" }
|
|
149
|
+
)
|
|
150
|
+
expect(attrs[:title_too_short_label]).to eq({ "en" => "is too short (under %{count} characters)" })
|
|
151
|
+
expect(attrs[:body_too_short_label]).to eq({ "en" => "is too short (under %{count} characters)" })
|
|
152
|
+
expect(attrs[:title_too_long_label]).to eq({ "en" => "is too long (maximum is %{count} characters)" })
|
|
153
|
+
expect(attrs[:body_too_long_label]).to eq({ "en" => "is too long (maximum is %{count} characters)" })
|
|
154
|
+
expect(attrs[:title_too_many_marks_label]).to eq(
|
|
155
|
+
{ "en" => "is using too many consecutive punctuation marks (e.g. ! and ?)" }
|
|
156
|
+
)
|
|
157
|
+
expect(attrs[:body_too_many_marks_label]).to eq(
|
|
158
|
+
{ "en" => "is using too many consecutive punctuation marks (e.g. ! and ?)" }
|
|
159
|
+
)
|
|
160
|
+
expect(attrs).not_to have_key(:menu_button_label)
|
|
161
|
+
expect(attrs).not_to have_key(:menu_connector_label)
|
|
162
|
+
expect(attrs).not_to have_key(:skip_menu_button)
|
|
163
|
+
expect(attrs).not_to have_key(:read_more_button_label)
|
|
164
|
+
expect(attrs).not_to have_key(:nothing_to_read_label)
|
|
165
|
+
end
|
|
166
|
+
# rubocop:enable RSpec/ExampleLength
|
|
167
|
+
|
|
168
|
+
it "omits propose labels for other manifests" do
|
|
169
|
+
item = create(
|
|
170
|
+
:chatbot_item,
|
|
171
|
+
chatbot:,
|
|
172
|
+
manifest_name: "read_proposals",
|
|
173
|
+
settings: {
|
|
174
|
+
"component_id" => 22,
|
|
175
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
176
|
+
"read_more_button_label" => { "en" => "Read more" },
|
|
177
|
+
"nothing_to_read_label" => { "en" => "Nothing to read" },
|
|
178
|
+
"body_label" => { "en" => "Should not appear" }
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
attrs = data_of(item)[:attributes]
|
|
182
|
+
|
|
183
|
+
expect(attrs).not_to have_key(:default_title_label)
|
|
184
|
+
expect(attrs).not_to have_key(:body_label)
|
|
185
|
+
expect(attrs).not_to have_key(:verification_label)
|
|
186
|
+
expect(attrs).not_to have_key(:action_prompt_label)
|
|
187
|
+
expect(attrs).not_to have_key(:save_button_label)
|
|
188
|
+
expect(attrs).not_to have_key(:success_label)
|
|
189
|
+
expect(attrs).not_to have_key(:withdraw_button_label)
|
|
190
|
+
expect(attrs).not_to have_key(:withdraw_success_label)
|
|
191
|
+
expect(attrs).not_to have_key(:creation_not_enabled_label)
|
|
192
|
+
expect(attrs).not_to have_key(:title_blank_label)
|
|
193
|
+
expect(attrs).not_to have_key(:body_blank_label)
|
|
194
|
+
expect(attrs).not_to have_key(:title_must_start_with_caps_label)
|
|
195
|
+
expect(attrs).not_to have_key(:body_must_start_with_caps_label)
|
|
196
|
+
expect(attrs).not_to have_key(:title_too_much_caps_label)
|
|
197
|
+
expect(attrs).not_to have_key(:body_too_much_caps_label)
|
|
198
|
+
expect(attrs).not_to have_key(:title_too_short_label)
|
|
199
|
+
expect(attrs).not_to have_key(:body_too_short_label)
|
|
200
|
+
expect(attrs).not_to have_key(:title_too_long_label)
|
|
201
|
+
expect(attrs).not_to have_key(:body_too_long_label)
|
|
202
|
+
expect(attrs).not_to have_key(:title_too_many_marks_label)
|
|
203
|
+
expect(attrs).not_to have_key(:body_too_many_marks_label)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it "serializes vote labels for vote_on_proposal" do
|
|
207
|
+
item = create(
|
|
208
|
+
:chatbot_item,
|
|
209
|
+
chatbot:,
|
|
210
|
+
manifest_name: "vote_on_proposal",
|
|
211
|
+
settings: {
|
|
212
|
+
"component_id" => 44,
|
|
213
|
+
"action_prompt_label" => { "en" => "Here the actions you can do:" },
|
|
214
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
215
|
+
"menu_connector_label" => { "en" => "See more" },
|
|
216
|
+
"skip_menu_button" => { "en" => "Skip" },
|
|
217
|
+
"vote_label" => { "en" => "Support" }
|
|
218
|
+
}
|
|
219
|
+
)
|
|
220
|
+
data = data_of(item)
|
|
221
|
+
attrs = data[:attributes]
|
|
222
|
+
|
|
223
|
+
expect(data[:type]).to eq("chatbot_menu_item_vote_on_proposal")
|
|
224
|
+
expect(attrs[:component_id]).to eq(44)
|
|
225
|
+
expect(attrs[:action_prompt_label]).to eq({ "en" => "Here the actions you can do:" })
|
|
226
|
+
expect(attrs[:menu_button_label]).to eq({ "en" => "Back to menu" })
|
|
227
|
+
expect(attrs[:menu_connector_label]).to eq({ "en" => "See more" })
|
|
228
|
+
expect(attrs[:skip_menu_button]).to eq({ "en" => "Skip" })
|
|
229
|
+
expect(attrs[:vote_label]).to eq({ "en" => "Support" })
|
|
230
|
+
expect(attrs).not_to have_key(:weight_1_label)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it "serializes optional weight labels when present" do
|
|
234
|
+
item = create(
|
|
235
|
+
:chatbot_item,
|
|
236
|
+
chatbot:,
|
|
237
|
+
manifest_name: "vote_on_proposal",
|
|
238
|
+
settings: {
|
|
239
|
+
"component_id" => 44,
|
|
240
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
241
|
+
"weight_1_label" => { "en" => "Disagree" },
|
|
242
|
+
"weight_2_label" => { "en" => "Neutral" },
|
|
243
|
+
"weight_3_label" => { "en" => "Agree" },
|
|
244
|
+
"abstention_label" => { "en" => "Skip" }
|
|
245
|
+
}
|
|
246
|
+
)
|
|
247
|
+
attrs = data_of(item)[:attributes]
|
|
248
|
+
|
|
249
|
+
expect(attrs[:weight_1_label]).to eq({ "en" => "Disagree" })
|
|
250
|
+
expect(attrs[:weight_2_label]).to eq({ "en" => "Neutral" })
|
|
251
|
+
expect(attrs[:weight_3_label]).to eq({ "en" => "Agree" })
|
|
252
|
+
expect(attrs[:abstention_label]).to eq({ "en" => "Skip" })
|
|
253
|
+
expect(attrs).not_to have_key(:vote_label)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
it "wraps scalar setting labels into the first locale" do
|
|
257
|
+
item = create(
|
|
258
|
+
:chatbot_item,
|
|
259
|
+
chatbot:,
|
|
260
|
+
manifest_name: "login",
|
|
261
|
+
settings: {
|
|
262
|
+
"redirect_path" => "/users/sign_in",
|
|
263
|
+
"response_label" => "Sign in"
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
attrs = data_of(item)[:attributes]
|
|
267
|
+
|
|
268
|
+
expect(attrs[:response_label]).to eq({ "en" => "Sign in" })
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it "omits blank hash weight labels" do
|
|
272
|
+
item = create(
|
|
273
|
+
:chatbot_item,
|
|
274
|
+
chatbot:,
|
|
275
|
+
manifest_name: "vote_on_proposal",
|
|
276
|
+
settings: {
|
|
277
|
+
"component_id" => 44,
|
|
278
|
+
"menu_button_label" => { "en" => "Back to menu" },
|
|
279
|
+
"vote_label" => { "en" => "" },
|
|
280
|
+
"weight_1_label" => {}
|
|
281
|
+
}
|
|
282
|
+
)
|
|
283
|
+
attrs = data_of(item)[:attributes]
|
|
284
|
+
|
|
285
|
+
expect(attrs).not_to have_key(:vote_label)
|
|
286
|
+
expect(attrs).not_to have_key(:weight_1_label)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it "returns nil timestamps when clocks are missing" do
|
|
290
|
+
item = create(:chatbot_item, chatbot:, manifest_name: "exit")
|
|
291
|
+
allow(item).to receive_messages(created_at: nil, updated_at: nil)
|
|
292
|
+
|
|
293
|
+
attrs = data_of(item)[:attributes]
|
|
294
|
+
|
|
295
|
+
expect(attrs[:created_at]).to be_nil
|
|
296
|
+
expect(attrs[:updated_at]).to be_nil
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
describe ".translated_setting" do
|
|
300
|
+
it "returns empty hash for blank scalars" do
|
|
301
|
+
expect(described_class.translated_setting(nil, [:en])).to eq({})
|
|
302
|
+
expect(described_class.translated_setting("", [:en])).to eq({})
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it "uses :en when locales are empty (translated_field still yields {})" do
|
|
306
|
+
expect(described_class.translated_setting("Hi", [])).to eq({})
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
describe ".translated_setting_present?" do
|
|
311
|
+
it "is false for blank hashes and blank scalars" do
|
|
312
|
+
expect(described_class.translated_setting_present?({})).to be(false)
|
|
313
|
+
expect(described_class.translated_setting_present?({ "en" => "" })).to be(false)
|
|
314
|
+
expect(described_class.translated_setting_present?(nil)).to be(false)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
it "is true for present scalars" do
|
|
318
|
+
expect(described_class.translated_setting_present?("Vote")).to be(true)
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Api::RestFull::Chatbot::ChatbotSerializer do
|
|
6
|
+
subject(:payload) do
|
|
7
|
+
described_class.new(chatbot, params: { locales: [:en], host: organization.host }).serializable_hash
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
let(:organization) { create(:organization) }
|
|
11
|
+
let(:chatbot) do
|
|
12
|
+
create(
|
|
13
|
+
:chatbot,
|
|
14
|
+
organization:,
|
|
15
|
+
name: { "en" => "Name" },
|
|
16
|
+
welcome_message: { "en" => "Hi" },
|
|
17
|
+
menu_intro: { "en" => "What next?" },
|
|
18
|
+
menu_connector: { "en" => "or" },
|
|
19
|
+
error_404: { "en" => "Not found" },
|
|
20
|
+
error_502: { "en" => "Upstream failed" },
|
|
21
|
+
error_401: { "en" => "Not authorized" }
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "serializes WhatsApp and translated attributes" do
|
|
26
|
+
data = payload[:data] || payload["data"]
|
|
27
|
+
attributes = (data[:attributes] || data["attributes"]).with_indifferent_access
|
|
28
|
+
|
|
29
|
+
expect(attributes[:whatsapp_phone_id]).to eq(chatbot.whatsapp_phone_id)
|
|
30
|
+
expect(attributes[:name]).to eq({ "en" => "Name" })
|
|
31
|
+
expect(attributes[:welcome_message]).to eq({ "en" => "Hi" })
|
|
32
|
+
expect(attributes[:menu_intro]).to eq({ "en" => "What next?" })
|
|
33
|
+
expect(attributes[:menu_connector]).to eq({ "en" => "or" })
|
|
34
|
+
expect(attributes[:error_404]).to eq({ "en" => "Not found" })
|
|
35
|
+
expect(attributes[:error_502]).to eq({ "en" => "Upstream failed" })
|
|
36
|
+
expect(attributes[:error_401]).to eq({ "en" => "Not authorized" })
|
|
37
|
+
expect(attributes[:created_at]).to be_present
|
|
38
|
+
expect(attributes[:updated_at]).to be_present
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "allows nil timestamps" do
|
|
42
|
+
allow(chatbot).to receive_messages(created_at: nil, updated_at: nil)
|
|
43
|
+
data = payload[:data] || payload["data"]
|
|
44
|
+
attributes = (data[:attributes] || data["attributes"]).with_indifferent_access
|
|
45
|
+
|
|
46
|
+
expect(attributes[:created_at]).to be_nil
|
|
47
|
+
expect(attributes[:updated_at]).to be_nil
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Api::RestFull::Chatbot::ChatbotUserSerializer do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
8
|
+
let(:user) do
|
|
9
|
+
create(:user, organization:, extended_data: { "whatsapp_phone_number" => "+15550001" })
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def data_of(record)
|
|
13
|
+
hash = described_class.new(record, params: { organization:, locales: [:en] }).serializable_hash
|
|
14
|
+
(hash[:data] || hash["data"]).with_indifferent_access
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "serializes phone and empty identities" do
|
|
18
|
+
data = data_of(user)
|
|
19
|
+
attrs = data[:attributes]
|
|
20
|
+
rel = data[:relationships]
|
|
21
|
+
|
|
22
|
+
expect(attrs[:whatsapp_phone_number]).to eq("+15550001")
|
|
23
|
+
expect(attrs[:subscribed_chatbot_ids]).to include(chatbot.id.to_s)
|
|
24
|
+
expect(rel[:identities][:data]).to eq([])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "includes Decidim identities when present" do
|
|
28
|
+
identity = Decidim::Identity.create!(
|
|
29
|
+
user:,
|
|
30
|
+
organization: user.organization,
|
|
31
|
+
provider: "facebook",
|
|
32
|
+
uid: "abc-#{SecureRandom.hex(4)}"
|
|
33
|
+
)
|
|
34
|
+
data = data_of(user.reload)
|
|
35
|
+
rel = data[:relationships]
|
|
36
|
+
ids = rel[:identities][:data].map { |row| row[:id] || row["id"] }
|
|
37
|
+
|
|
38
|
+
expect(ids).to include(identity.id.to_s)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::ChatbotWebhookHandler do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:chatbot) { create(:chatbot, organization:) }
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
allow(Decidim::Chatbot::ChatbotWebhookJob).to receive(:perform_later)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "enqueues a job for settings_updated" do
|
|
14
|
+
expect(Decidim::Chatbot::ChatbotWebhookJob).to receive(:perform_later).with(
|
|
15
|
+
"chatbot.settings_updated.succeeded",
|
|
16
|
+
chatbot.id,
|
|
17
|
+
organization.id
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
described_class.call(
|
|
21
|
+
Decidim::Chatbot::WebhookPublisher::SETTINGS_EVENT,
|
|
22
|
+
{ resource: chatbot }
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "enqueues a job for menu_updated" do
|
|
27
|
+
expect(Decidim::Chatbot::ChatbotWebhookJob).to receive(:perform_later).with(
|
|
28
|
+
"chatbot.menu_updated.succeeded",
|
|
29
|
+
chatbot.id,
|
|
30
|
+
organization.id
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
described_class.call(
|
|
34
|
+
Decidim::Chatbot::WebhookPublisher::MENU_EVENT,
|
|
35
|
+
{ resource: chatbot }
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "ignores unknown events" do
|
|
40
|
+
expect(Decidim::Chatbot::ChatbotWebhookJob).not_to receive(:perform_later)
|
|
41
|
+
described_class.call("decidim.events.other", { resource: chatbot })
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Chatbot::Notifications::Bindings do
|
|
6
|
+
subject { described_class.for(item, user) }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization) }
|
|
9
|
+
let(:chatbot) { create(:chatbot, organization:, name: { "en" => "Bot" }) }
|
|
10
|
+
let(:process) do
|
|
11
|
+
create(:participatory_process, :published, organization:, title: { "en" => "Gather Together" })
|
|
12
|
+
end
|
|
13
|
+
let(:user) { create(:user, organization:, name: "Ada") }
|
|
14
|
+
let(:item) do
|
|
15
|
+
create(
|
|
16
|
+
:chatbot_item,
|
|
17
|
+
chatbot:,
|
|
18
|
+
scope: "notification",
|
|
19
|
+
manifest_name: "phase",
|
|
20
|
+
settings: { "participatory_space_gid" => process.to_gid.to_s }
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
before do
|
|
25
|
+
step = process.steps.find_by(active: true) || process.steps.first ||
|
|
26
|
+
create(:participatory_process_step, participatory_process: process, active: true)
|
|
27
|
+
step.update!(
|
|
28
|
+
title: { "en" => "Introduction" },
|
|
29
|
+
start_date: Date.new(2026, 7, 10),
|
|
30
|
+
end_date: Date.new(2026, 10, 13),
|
|
31
|
+
active: true
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "binds Facebook named phase placeholders" do
|
|
36
|
+
expect(subject).to include(
|
|
37
|
+
"space_name" => "Gather Together",
|
|
38
|
+
"phase_name" => "Introduction",
|
|
39
|
+
"phase_start" => "10/07/2026",
|
|
40
|
+
"phase_end" => "13/10/2026",
|
|
41
|
+
"user_name" => "Ada",
|
|
42
|
+
"nickname" => user.nickname.to_s
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "formats a missing date as an empty string" do
|
|
47
|
+
expect(described_class.format_date(nil)).to eq("")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "returns only shared bindings without a participatory space" do
|
|
51
|
+
item.update!(settings: {})
|
|
52
|
+
|
|
53
|
+
expect(subject).to include(
|
|
54
|
+
"organization_name" => organization.name,
|
|
55
|
+
"chatbot_name" => "Bot",
|
|
56
|
+
"user_name" => "Ada"
|
|
57
|
+
)
|
|
58
|
+
expect(subject).not_to have_key("space_name")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "returns blank phase values when the process has no active step" do
|
|
62
|
+
# ponytail: skip step validations so this example has zero active steps; if a factory can build that, drop update_all and the disable
|
|
63
|
+
process.steps.update_all(active: false) # rubocop:disable Rails/SkipsModelValidations
|
|
64
|
+
|
|
65
|
+
expect(subject).to include(
|
|
66
|
+
"space_name" => "Gather Together",
|
|
67
|
+
"phase_name" => "",
|
|
68
|
+
"phase_start" => "",
|
|
69
|
+
"phase_end" => ""
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "ignores a participatory space from another organization" do
|
|
74
|
+
foreign_process = create(:participatory_process, :published, organization: create(:organization))
|
|
75
|
+
item.update!(settings: { "participatory_space_gid" => foreign_process.to_gid.to_s })
|
|
76
|
+
|
|
77
|
+
expect(subject).not_to have_key("space_name")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "ignores a located record without an organization" do
|
|
81
|
+
item.update!(settings: { "participatory_space_gid" => "gid://test/Unsupported/1" })
|
|
82
|
+
allow(GlobalID::Locator).to receive(:locate).and_return(Object.new)
|
|
83
|
+
|
|
84
|
+
expect(subject).not_to have_key("space_name")
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Whatsapp::BodyParameters do
|
|
6
|
+
describe ".from" do
|
|
7
|
+
it "adds parameter_name for named keys" do
|
|
8
|
+
expect(described_class.from("city" => "Nairobi", "space_name" => "Town")).to eq(
|
|
9
|
+
[
|
|
10
|
+
{ type: "text", parameter_name: "city", text: "Nairobi" },
|
|
11
|
+
{ type: "text", parameter_name: "space_name", text: "Town" }
|
|
12
|
+
]
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "omits parameter_name for positional keys and sorts numerically" do
|
|
17
|
+
expect(described_class.from("2" => "Nairobi", "1" => "Ada")).to eq(
|
|
18
|
+
[{ type: "text", text: "Ada" }, { type: "text", text: "Nairobi" }]
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|