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,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Admin::MenuItems::ReadBlogsForm do
|
|
6
|
+
subject(:form) do
|
|
7
|
+
described_class.from_params(
|
|
8
|
+
manifest_name: "read_blogs"
|
|
9
|
+
).with_context(current_organization: organization)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:organization) { create(:organization, available_locales: %w(en), default_locale: :en) }
|
|
13
|
+
|
|
14
|
+
it "prefills nothing_to_read_label from the manifest default" do
|
|
15
|
+
form.manifest_name = "read_blogs"
|
|
16
|
+
form.prefill_defaults!
|
|
17
|
+
|
|
18
|
+
expect(form.nothing_to_read_label["en"]).to eq(
|
|
19
|
+
I18n.t("decidim.chatbot.admin.items.nothing_to_read_label_read_blogs_default", locale: :en)
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
module Notifications
|
|
9
|
+
describe ManualForm do
|
|
10
|
+
subject do
|
|
11
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:organization) { create(:organization, available_locales: %w(en fr)) }
|
|
15
|
+
let(:attributes) do
|
|
16
|
+
{
|
|
17
|
+
manifest_name: "manual",
|
|
18
|
+
template_id_en: "1649483436030166",
|
|
19
|
+
variables_json_en: '{"foo":"bar"}'
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it { is_expected.to be_valid }
|
|
24
|
+
|
|
25
|
+
it "does not require a title" do
|
|
26
|
+
expect(subject).to be_valid
|
|
27
|
+
expect(subject.shows_title?).to be(false)
|
|
28
|
+
expect(subject.shows_introduction?).to be(false)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "stores translated template name and parsed variables" do
|
|
32
|
+
expect(subject.settings_hash["template_id"]["en"]).to eq("1649483436030166")
|
|
33
|
+
expect(subject.settings_hash["variables"]["en"]).to eq("foo" => "bar")
|
|
34
|
+
expect(subject.settings_hash["variables"]["fr"]).to eq({})
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "defaults empty variables to {}" do
|
|
38
|
+
expect(subject.variables_json["en"]).to eq('{"foo":"bar"}')
|
|
39
|
+
expect(subject.variables_json["fr"]).to eq("{}")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "when variables are not JSON" do
|
|
43
|
+
let(:attributes) do
|
|
44
|
+
{ manifest_name: "manual", template_id_en: "1649483436030166", variables_json_en: "nope" }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it { is_expected.not_to be_valid }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "when variables are a JSON array" do
|
|
51
|
+
let(:attributes) do
|
|
52
|
+
{ manifest_name: "manual", template_id_en: "1649483436030166", variables_json_en: "[]" }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it { is_expected.not_to be_valid }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "when a variable key is not a Facebook named placeholder" do
|
|
59
|
+
let(:attributes) do
|
|
60
|
+
{ manifest_name: "manual", template_id_en: "1649483436030166", variables_json_en: '{"Foo":"bar"}' }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it { is_expected.not_to be_valid }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "when a variable key contains digits" do
|
|
67
|
+
let(:attributes) do
|
|
68
|
+
{ manifest_name: "manual", template_id_en: "1649483436030166", variables_json_en: '{"1":"bar"}' }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it { is_expected.not_to be_valid }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context "when a variable key contains a hyphen" do
|
|
75
|
+
let(:attributes) do
|
|
76
|
+
{ manifest_name: "manual", template_id_en: "1649483436030166", variables_json_en: '{"first-name":"bar"}' }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it { is_expected.not_to be_valid }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "when mapping a stored item" do
|
|
83
|
+
subject { described_class.from_model(item).with_context(current_organization: organization) }
|
|
84
|
+
|
|
85
|
+
let(:item) do
|
|
86
|
+
build(
|
|
87
|
+
:chatbot_item,
|
|
88
|
+
chatbot: build(:chatbot, organization:),
|
|
89
|
+
manifest_name: "manual",
|
|
90
|
+
settings: { "template_id" => { "en" => "1649483436030166" }, "variables" => { "en" => { "foo" => "bar" } } }
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "exposes JSON strings per locale" do
|
|
95
|
+
expect(subject.template_id["en"]).to eq("1649483436030166")
|
|
96
|
+
expect(JSON.parse(subject.variables_json["en"])).to eq("foo" => "bar")
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "when a template id is not numeric" do
|
|
101
|
+
let(:attributes) do
|
|
102
|
+
{ manifest_name: "manual", template_id_en: "hello", variables_json_en: "{}" }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it { is_expected.not_to be_valid }
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "when mapping a legacy stored item" do
|
|
109
|
+
subject { described_class.from_model(item).with_context(current_organization: organization) }
|
|
110
|
+
|
|
111
|
+
let(:item) do
|
|
112
|
+
build(
|
|
113
|
+
:chatbot_item,
|
|
114
|
+
chatbot: build(:chatbot, organization:),
|
|
115
|
+
manifest_name: "manual",
|
|
116
|
+
settings: { "template_id" => "1649483436030166", "variables" => { "foo" => "bar" } }
|
|
117
|
+
)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "lifts string template name and flat variables into the default locale" do
|
|
121
|
+
expect(subject.template_id["en"]).to eq("1649483436030166")
|
|
122
|
+
expect(JSON.parse(subject.variables_json["en"])).to eq("foo" => "bar")
|
|
123
|
+
expect(subject.variables_json["fr"]).to eq("{}")
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
module Notifications
|
|
9
|
+
describe PhaseForm do
|
|
10
|
+
subject do
|
|
11
|
+
described_class.from_params(attributes).with_context(current_organization: organization)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:organization) { create(:organization, available_locales: %w(en fr)) }
|
|
15
|
+
let(:process) { create(:participatory_process, :published, organization:, title: { "en" => "Town process" }) }
|
|
16
|
+
let(:attributes) do
|
|
17
|
+
{
|
|
18
|
+
manifest_name: "phase",
|
|
19
|
+
participatory_space_gid: process.to_gid.to_s,
|
|
20
|
+
template_id_en: "1649483436030169",
|
|
21
|
+
use_space_name: "1",
|
|
22
|
+
use_phase_name: "0",
|
|
23
|
+
use_phase_start: "0",
|
|
24
|
+
use_phase_end: "0"
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it { is_expected.to be_valid }
|
|
29
|
+
|
|
30
|
+
it "does not show the variables JSON field" do
|
|
31
|
+
expect(subject.shows_variables_json?).to be(false)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "stores selected placeholders as interpolatable variables" do
|
|
35
|
+
expect(subject.settings_hash["participatory_space_gid"]).to eq(process.to_gid.to_s)
|
|
36
|
+
expect(subject.settings_hash["template_id"]["en"]).to eq("1649483436030169")
|
|
37
|
+
expect(subject.settings_hash["variables"]).to eq("space_name" => "%{space_name}")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "lists published spaces of this organization only" do
|
|
41
|
+
unpublished = create(:participatory_process, :unpublished, organization:)
|
|
42
|
+
foreign = create(:participatory_process, :published, organization: create(:organization))
|
|
43
|
+
assembly = create(:assembly, :published, organization:)
|
|
44
|
+
|
|
45
|
+
gids = subject.space_choices.map(&:last)
|
|
46
|
+
expect(gids).to include(process.to_gid.to_s, assembly.to_gid.to_s)
|
|
47
|
+
expect(gids).not_to include(unpublished.to_gid.to_s, foreign.to_gid.to_s)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "rejects a space from another organization" do
|
|
51
|
+
subject.participatory_space_gid = create(:participatory_process, organization: create(:organization)).to_gid.to_s
|
|
52
|
+
expect(subject).not_to be_valid
|
|
53
|
+
expect(subject.errors[:participatory_space_gid]).to be_present
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "checks boxes from stored variable keys" do
|
|
57
|
+
item = create(
|
|
58
|
+
:chatbot_item,
|
|
59
|
+
chatbot: create(:chatbot, organization:),
|
|
60
|
+
scope: "notification",
|
|
61
|
+
manifest_name: "phase",
|
|
62
|
+
settings: {
|
|
63
|
+
"template_id" => { "en" => "1649483436030169" },
|
|
64
|
+
"participatory_space_gid" => process.to_gid.to_s,
|
|
65
|
+
"variables" => { "space_name" => "%{space_name}", "phase_end" => "%{phase_end}" }
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
form = described_class.from_model(item).with_context(current_organization: organization)
|
|
70
|
+
expect(form.use_space_name).to be(true)
|
|
71
|
+
expect(form.use_phase_name).to be(false)
|
|
72
|
+
expect(form.use_phase_start).to be(false)
|
|
73
|
+
expect(form.use_phase_end).to be(true)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Chatbot
|
|
7
|
+
module Admin
|
|
8
|
+
module Notifications
|
|
9
|
+
describe TestForm do
|
|
10
|
+
subject do
|
|
11
|
+
described_class.from_params(attributes).with_context(
|
|
12
|
+
current_organization: organization,
|
|
13
|
+
item:
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
let(:organization) { create(:organization, available_locales: %w(en fr)) }
|
|
18
|
+
let(:chatbot) { create(:chatbot, organization:) }
|
|
19
|
+
let(:item) do
|
|
20
|
+
create(
|
|
21
|
+
:chatbot_item,
|
|
22
|
+
chatbot:,
|
|
23
|
+
scope: "notification",
|
|
24
|
+
manifest_name: "manual",
|
|
25
|
+
settings: {
|
|
26
|
+
"template_id" => { "en" => "1649483436030166" },
|
|
27
|
+
"variables" => { "en" => { "city" => "Nairobi" } }
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
let(:attributes) { { phone_number: "+15551234567", values: { "city" => "Mombasa" } } }
|
|
32
|
+
|
|
33
|
+
it { is_expected.to be_valid }
|
|
34
|
+
|
|
35
|
+
it "normalizes the phone and uses submitted values" do
|
|
36
|
+
expect(subject.normalized_phone).to eq("15551234567")
|
|
37
|
+
expect(subject.body_parameters).to eq([{ type: "text", parameter_name: "city", text: "Mombasa" }])
|
|
38
|
+
expect(subject.template_id).to eq("1649483436030166")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "hydrates values from stored locale variables" do
|
|
42
|
+
form = described_class.new.with_context(current_organization: organization, item:).hydrate
|
|
43
|
+
expect(form.locale).to eq("en")
|
|
44
|
+
expect(form.values).to eq("city" => "Nairobi")
|
|
45
|
+
expect(form.variable_keys).to eq(["city"])
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "keeps an explicitly selected locale when hydrating" do
|
|
49
|
+
form = described_class.new(locale: "fr").with_context(current_organization: organization, item:).hydrate
|
|
50
|
+
|
|
51
|
+
expect(form.locale).to eq("fr")
|
|
52
|
+
expect(form.values).to eq("city" => "Nairobi")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "accepts variables that are not grouped by locale" do
|
|
56
|
+
item.update!(settings: item.settings.merge("variables" => { "city" => "Nairobi" }))
|
|
57
|
+
|
|
58
|
+
expect(subject.variable_keys).to eq(["city"])
|
|
59
|
+
expect(subject.body_parameters).to eq([{ type: "text", parameter_name: "city", text: "Mombasa" }])
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "returns no variables when only another available locale is configured" do
|
|
63
|
+
item.update!(settings: item.settings.merge("variables" => { "fr" => { "city" => "Paris" } }))
|
|
64
|
+
|
|
65
|
+
expect(subject.variable_keys).to be_empty
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "stringifies permitted parameter values" do
|
|
69
|
+
form = described_class.new(values: ActionController::Parameters.new(city: "Kisumu").permit!)
|
|
70
|
+
|
|
71
|
+
expect(form.values).to eq("city" => "Kisumu")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "uses the selected locale for the template name" do
|
|
75
|
+
item.settings["template_id"] = { "en" => "1649483436030166", "fr" => "1649483436030167" }
|
|
76
|
+
item.save!
|
|
77
|
+
attributes[:locale] = "fr"
|
|
78
|
+
expect(subject).to be_valid
|
|
79
|
+
expect(subject.template_id).to eq("1649483436030167")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "rejects a locale the organization does not offer" do
|
|
83
|
+
attributes[:locale] = "ca"
|
|
84
|
+
expect(subject).not_to be_valid
|
|
85
|
+
expect(subject.errors[:locale]).to be_present
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "rejects a short phone number" do
|
|
89
|
+
attributes[:phone_number] = "123"
|
|
90
|
+
expect(subject).not_to be_valid
|
|
91
|
+
expect(subject.errors[:phone_number]).to be_present
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context "when the item is a phase notification" do
|
|
95
|
+
let(:process) do
|
|
96
|
+
create(:participatory_process, :published, organization:, title: { "en" => "Town process" })
|
|
97
|
+
end
|
|
98
|
+
let!(:step) do
|
|
99
|
+
create(
|
|
100
|
+
:participatory_process_step,
|
|
101
|
+
participatory_process: process,
|
|
102
|
+
title: { "en" => "Collect ideas" },
|
|
103
|
+
start_date: Date.new(2026, 1, 1),
|
|
104
|
+
end_date: Date.new(2026, 2, 1)
|
|
105
|
+
)
|
|
106
|
+
end
|
|
107
|
+
let(:item) do
|
|
108
|
+
create(
|
|
109
|
+
:chatbot_item,
|
|
110
|
+
chatbot:,
|
|
111
|
+
scope: "notification",
|
|
112
|
+
manifest_name: "phase",
|
|
113
|
+
settings: {
|
|
114
|
+
"template_id" => { "en" => "1649483436030169" },
|
|
115
|
+
"variables" => { "en" => { "space_name" => "%{space_name}" } },
|
|
116
|
+
"participatory_space_gid" => process.to_gid.to_s
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
end
|
|
120
|
+
let(:attributes) { { phone_number: "+15551234567", step_id: step.id } }
|
|
121
|
+
|
|
122
|
+
it "interpolates the selected process step" do
|
|
123
|
+
expect(subject).to be_valid
|
|
124
|
+
expect(subject.step_choices.map(&:last)).to include(step.id)
|
|
125
|
+
expect(subject.body_parameters).to eq([{ type: "text", parameter_name: "space_name", text: "Town process" }])
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "rejects a step from another process" do
|
|
129
|
+
other = create(:participatory_process, :published, organization:)
|
|
130
|
+
foreign_step = create(:participatory_process_step, participatory_process: other)
|
|
131
|
+
attributes[:step_id] = foreign_step.id
|
|
132
|
+
expect(subject).not_to be_valid
|
|
133
|
+
expect(subject.errors[:step_id]).to be_present
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "ignores a process from another organization" do
|
|
137
|
+
foreign = create(:participatory_process, :published, organization: create(:organization))
|
|
138
|
+
item.settings["participatory_space_gid"] = foreign.to_gid.to_s
|
|
139
|
+
item.save!
|
|
140
|
+
expect(subject.step_choices).to be_empty
|
|
141
|
+
expect(subject).not_to be_valid
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "interpolates blank phase values without a configured process" do
|
|
145
|
+
item.update!(
|
|
146
|
+
settings: {
|
|
147
|
+
"template_id" => { "en" => "1649483436030169" },
|
|
148
|
+
"variables" => {
|
|
149
|
+
"en" => {
|
|
150
|
+
"space_name" => "%{space_name}",
|
|
151
|
+
"phase_name" => "%{phase_name}",
|
|
152
|
+
"phase_start" => "%{phase_start}",
|
|
153
|
+
"phase_end" => "%{phase_end}"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
attributes.delete(:step_id)
|
|
159
|
+
|
|
160
|
+
expect(subject.body_parameters).to contain_exactly(
|
|
161
|
+
{ type: "text", parameter_name: "space_name", text: "" },
|
|
162
|
+
{ type: "text", parameter_name: "phase_name", text: "" },
|
|
163
|
+
{ type: "text", parameter_name: "phase_start", text: "" },
|
|
164
|
+
{ type: "text", parameter_name: "phase_end", text: "" }
|
|
165
|
+
)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::ChatbotWebhookJob do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:other_organization) { create(:organization) }
|
|
8
|
+
let(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let!(:api_client) { create(:api_client, organization:, scopes: ["whatsapp"]) }
|
|
10
|
+
let(:event_name) { "chatbot.settings_updated.succeeded" }
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
allow(Decidim::RestFull::Core::WebhookJob).to receive(:perform_later).and_return(true)
|
|
14
|
+
api_client.permissions.create!(permission: event_name, is_event: true)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "calls WebhookJob for webhook registrations subscribed to this event" do
|
|
18
|
+
webhook = create(:webhook_registration, api_client:, subscriptions: [event_name])
|
|
19
|
+
|
|
20
|
+
expect(Decidim::RestFull::Core::WebhookJob).to receive(:perform_later) do |registration, *_args|
|
|
21
|
+
expect(registration).to eq(webhook)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
described_class.perform_now(event_name, chatbot.id, organization.id)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "does not enqueue for a client from another organization" do
|
|
28
|
+
foreign_client = create(:api_client, organization: other_organization, scopes: ["whatsapp"])
|
|
29
|
+
foreign_client.permissions.create!(permission: event_name, is_event: true)
|
|
30
|
+
create(:webhook_registration, api_client: foreign_client, subscriptions: [event_name])
|
|
31
|
+
create(:webhook_registration, api_client:, subscriptions: [event_name])
|
|
32
|
+
|
|
33
|
+
expect(Decidim::RestFull::Core::WebhookJob).to receive(:perform_later).once
|
|
34
|
+
|
|
35
|
+
described_class.perform_now(event_name, chatbot.id, organization.id)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "serializes with ChatbotSerializer" do
|
|
39
|
+
create(:webhook_registration, api_client:, subscriptions: [event_name])
|
|
40
|
+
|
|
41
|
+
expect(Decidim::Api::RestFull::Chatbot::ChatbotSerializer).to receive(:new).with(
|
|
42
|
+
chatbot, kind_of(Hash)
|
|
43
|
+
).and_call_original
|
|
44
|
+
|
|
45
|
+
described_class.perform_now(event_name, chatbot.id, organization.id)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::SendNotificationJob do
|
|
6
|
+
subject(:job) { described_class.new }
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization) }
|
|
9
|
+
let(:chatbot) { create(:chatbot, organization:, whatsapp_phone_id: "phone-1") }
|
|
10
|
+
let!(:actor) { create(:user, :admin, organization:) }
|
|
11
|
+
let(:item) do
|
|
12
|
+
create(
|
|
13
|
+
:chatbot_item,
|
|
14
|
+
chatbot:,
|
|
15
|
+
scope: "notification",
|
|
16
|
+
manifest_name: "manual",
|
|
17
|
+
settings: {
|
|
18
|
+
"template_id" => { "en" => "1649483436030166" },
|
|
19
|
+
"variables" => { "en" => {} }
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
before { allow(Decidim::Chatbot::Notifications::Send).to receive(:call) }
|
|
25
|
+
|
|
26
|
+
it "sends through Notifications::Send" do
|
|
27
|
+
job.perform(item.id, actor.id)
|
|
28
|
+
expect(Decidim::Chatbot::Notifications::Send).to have_received(:call).with(item, actor)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "skips a missing item" do
|
|
32
|
+
job.perform(-1, actor.id)
|
|
33
|
+
expect(Decidim::Chatbot::Notifications::Send).not_to have_received(:call)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "skips when the template name is blank" do
|
|
37
|
+
item.update!(settings: item.settings.merge("template_id" => { "en" => "" }))
|
|
38
|
+
job.perform(item.id, actor.id)
|
|
39
|
+
expect(Decidim::Chatbot::Notifications::Send).not_to have_received(:call)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "skips a disabled item" do
|
|
43
|
+
item.update!(enabled: false)
|
|
44
|
+
job.perform(item.id, actor.id)
|
|
45
|
+
expect(Decidim::Chatbot::Notifications::Send).not_to have_received(:call)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "falls back to an org admin when the actor is foreign" do
|
|
49
|
+
foreign = create(:user, :admin, organization: create(:organization))
|
|
50
|
+
job.perform(item.id, foreign.id)
|
|
51
|
+
expect(Decidim::Chatbot::Notifications::Send).to have_received(:call).with(item, actor)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Engine do
|
|
6
|
+
it "registers whatsapp.read permission" do
|
|
7
|
+
keys = Decidim::RestFull::Core::PermissionRegistry.all.map(&:key)
|
|
8
|
+
expect(keys).to include("whatsapp.read")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "registers the whatsapp OAuth scope for Doorkeeper and /system" do
|
|
12
|
+
expect(Decidim::RestFull::Extension.doorkeeper_optional_scopes).to include(:whatsapp)
|
|
13
|
+
expect(Decidim::RestFull::Core::DoorkeeperConfig.advertised_scopes).to include(:whatsapp)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "exposes whatsapp to the System API client permissions UI" do
|
|
17
|
+
expect(Decidim::RestFull::Core::PermissionRegistry.extension_ui_scopes).to include("whatsapp")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "advertises whatsapp for an organization when the chatbot gem is present" do
|
|
21
|
+
organization = create(:organization)
|
|
22
|
+
|
|
23
|
+
expect(Decidim::RestFull::Core::DoorkeeperConfig.advertised_scopes_for(organization)).to include(:whatsapp)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "registers chatbot webhook events under whatsapp" do
|
|
27
|
+
names = Decidim::RestFull::Core::WebhookEventCatalog.all.map(&:event_name)
|
|
28
|
+
expect(names).to include(
|
|
29
|
+
"chatbot.settings_updated.succeeded",
|
|
30
|
+
"chatbot.menu_updated.succeeded"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
settings = Decidim::RestFull::Core::WebhookEventCatalog.find("chatbot.settings_updated.succeeded")
|
|
34
|
+
menu = Decidim::RestFull::Core::WebhookEventCatalog.find("chatbot.menu_updated.succeeded")
|
|
35
|
+
expect(settings.scope).to eq("whatsapp")
|
|
36
|
+
expect(menu.scope).to eq("whatsapp")
|
|
37
|
+
|
|
38
|
+
keys = Decidim::RestFull::Core::PermissionRegistry.all.select(&:event).map(&:key)
|
|
39
|
+
expect(keys).to include(
|
|
40
|
+
"chatbot.settings_updated.succeeded",
|
|
41
|
+
"chatbot.menu_updated.succeeded"
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Registry do
|
|
6
|
+
describe "default manifests" do
|
|
7
|
+
it "registers the six menu types" do
|
|
8
|
+
names = Decidim::Chatbot.registry.for(:menu).map(&:name)
|
|
9
|
+
expect(names).to contain_exactly(
|
|
10
|
+
:read_blogs, :read_proposals, :propose_proposals, :vote_on_proposal, :login, :exit
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "registers the two notification types" do
|
|
15
|
+
names = Decidim::Chatbot.registry.for(:notification).map(&:name)
|
|
16
|
+
expect(names).to contain_exactly(:phase, :manual)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "does not include unknown names" do
|
|
20
|
+
expect(Decidim::Chatbot.registry.for(:menu).map(&:name)).not_to include(:unknown, :surveys)
|
|
21
|
+
expect(Decidim::Chatbot.registry.for(:notification).map(&:name)).not_to include(:unknown, :login)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "refuses a duplicate name in the same scope" do
|
|
25
|
+
expect do
|
|
26
|
+
Decidim::Chatbot.registry.register(:menu, :login) { |manifest| manifest.form_class_name = "X" }
|
|
27
|
+
end.to raise_error(described_class::AlreadyRegistered)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::SettingsTab do
|
|
6
|
+
it "registers the Chatbot organization settings tab" do
|
|
7
|
+
tabs = double("tabs")
|
|
8
|
+
allow(Decidim::Toggle).to receive(:settings_tabs).with(:organization_settings).and_yield(tabs)
|
|
9
|
+
expect(tabs).to receive(:add_tab).with(
|
|
10
|
+
:decidim_chatbot,
|
|
11
|
+
kind_of(String),
|
|
12
|
+
hash_including(
|
|
13
|
+
form: Decidim::Chatbot::Admin::ConfigForm,
|
|
14
|
+
command: Decidim::Toggle::UpdateModuleConfigCommand,
|
|
15
|
+
module_name: Decidim::Chatbot::MODULE_NAME
|
|
16
|
+
)
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
described_class.register!
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Chatbot::VariableInterpolator do
|
|
6
|
+
subject do
|
|
7
|
+
described_class.new(
|
|
8
|
+
"organization_name" => "Town",
|
|
9
|
+
"chatbot_name" => "Bot",
|
|
10
|
+
"user_name" => "Ada",
|
|
11
|
+
"space_name" => "Town process",
|
|
12
|
+
"phase_name" => "Collect"
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "binds I18n-style tokens" do
|
|
17
|
+
expect(subject.expand("space_name" => "%{space_name}", "phase_name" => "%{phase_name}")).to eq(
|
|
18
|
+
"space_name" => "Town process",
|
|
19
|
+
"phase_name" => "Collect"
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "binds shared tokens" do
|
|
24
|
+
expect(subject.expand_value("%{organization_name} / %{user_name}")).to eq("Town / Ada")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "leaves unknown tokens empty" do
|
|
28
|
+
expect(subject.expand_value("%{other}")).to eq("")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "lists keys in a string" do
|
|
32
|
+
expect(described_class.keys_in("%{user_name} and %{other}")).to eq(%w(user_name other))
|
|
33
|
+
end
|
|
34
|
+
end
|