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
data/spec/system/decidim/chatbot/admin/admin_sees_disabled_menu_item_faded_on_the_table_spec.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin sees disabled menu item faded on the table", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr es)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let!(:on) { create(:chatbot_item, chatbot:, title: { "en" => "Active login" }) }
|
|
10
|
+
let!(:off) { create(:chatbot_item, :disabled, chatbot:, title: { "en" => "Quiet login" }) }
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
enable_chatbot!(organization)
|
|
14
|
+
switch_to_host(organization.host)
|
|
15
|
+
login_as user, scope: :user
|
|
16
|
+
visit decidim_admin_chatbot.chatbot_menu_items_path(chatbot)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "fades only the disabled row" do
|
|
20
|
+
expect(find("tr[data-record-id='#{off.id}']")[:style]).to include("opacity: 0.6")
|
|
21
|
+
expect(find("tr[data-record-id='#{on.id}']")[:style].to_s).not_to include("opacity")
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin sees disabled notification item faded on the table", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr es)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let!(:on) do
|
|
10
|
+
create(
|
|
11
|
+
:chatbot_item,
|
|
12
|
+
chatbot:,
|
|
13
|
+
scope: "notification",
|
|
14
|
+
manifest_name: "manual",
|
|
15
|
+
settings: { "template_id" => { "en" => "1649483436030171" } }
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
let!(:off) do
|
|
19
|
+
create(
|
|
20
|
+
:chatbot_item,
|
|
21
|
+
:disabled,
|
|
22
|
+
chatbot:,
|
|
23
|
+
scope: "notification",
|
|
24
|
+
manifest_name: "manual",
|
|
25
|
+
settings: { "template_id" => { "en" => "1649483436030172" } }
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
before do
|
|
30
|
+
enable_chatbot!(organization)
|
|
31
|
+
switch_to_host(organization.host)
|
|
32
|
+
login_as user, scope: :user
|
|
33
|
+
visit decidim_admin_chatbot.chatbot_notifications_path(chatbot)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "fades only the disabled row" do
|
|
37
|
+
expect(find("tr[data-record-id='#{off.id}']")[:style]).to include("opacity: 0.6")
|
|
38
|
+
expect(find("tr[data-record-id='#{on.id}']")[:style].to_s).not_to include("opacity")
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin sees an editable notification template id", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr es)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
enable_chatbot!(organization)
|
|
12
|
+
switch_to_host(organization.host)
|
|
13
|
+
login_as user, scope: :user
|
|
14
|
+
visit decidim_admin_chatbot.edit_chatbot_notification_path(chatbot, item)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "when the item is manual" do
|
|
18
|
+
let!(:item) do
|
|
19
|
+
create(
|
|
20
|
+
:chatbot_item,
|
|
21
|
+
chatbot:,
|
|
22
|
+
scope: "notification",
|
|
23
|
+
manifest_name: "manual",
|
|
24
|
+
settings: {
|
|
25
|
+
"template_id" => { "en" => "1649483436030166" },
|
|
26
|
+
"variables" => { "en" => { "name" => "Hi" } }
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "shows an enabled template id and Send now next to Save" do
|
|
32
|
+
expect(page).to have_css(".process-title-content-breadcrumb-container-left", text: "Edit 1649483436030166")
|
|
33
|
+
expect(page).to have_css(".row.column")
|
|
34
|
+
expect(page).to have_no_button("Sync template")
|
|
35
|
+
expect(page).to have_no_content("Last synced")
|
|
36
|
+
expect(page).to have_no_table
|
|
37
|
+
expect(page).to have_field("item_template_id_en", with: "1649483436030166", disabled: false)
|
|
38
|
+
expect(page).to have_css("#chatbot-notification-item-form")
|
|
39
|
+
within(".item__edit-sticky") do
|
|
40
|
+
expect(page).to have_button("Send now")
|
|
41
|
+
expect(page).to have_button("Save")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "when the item is phase" do
|
|
47
|
+
let!(:process) { create(:participatory_process, :published, organization:) }
|
|
48
|
+
let!(:item) do
|
|
49
|
+
create(
|
|
50
|
+
:chatbot_item,
|
|
51
|
+
chatbot:,
|
|
52
|
+
scope: "notification",
|
|
53
|
+
manifest_name: "phase",
|
|
54
|
+
settings: {
|
|
55
|
+
"template_id" => { "en" => "1649483436030169" },
|
|
56
|
+
"participatory_space_gid" => process.to_gid.to_s,
|
|
57
|
+
"variables" => { "space_name" => "%{space_name}" }
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "shows Save only" do
|
|
63
|
+
expect(page).to have_css(".process-title-content-breadcrumb-container-left", text: "Edit 1649483436030169")
|
|
64
|
+
expect(page).to have_css(".row.column")
|
|
65
|
+
expect(page).to have_css("fieldset legend", text: "Variables list")
|
|
66
|
+
expect(page).to have_no_button("Send now")
|
|
67
|
+
expect(page).to have_no_css("#chatbot-notification-item-form")
|
|
68
|
+
within(".item__edit-sticky") { expect(page).to have_button("Save") }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/spec/system/decidim/chatbot/admin/admin_sees_propose_proposals_defaults_prefilled_spec.rb
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin sees propose proposals defaults prefilled", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr), default_locale: "en") }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let(:space) { create(:participatory_process, :published, organization:) }
|
|
10
|
+
let!(:proposals) { create(:proposal_component, participatory_space: space) }
|
|
11
|
+
|
|
12
|
+
let(:expected) do
|
|
13
|
+
{
|
|
14
|
+
"default_title_label" => {
|
|
15
|
+
"en" => "{{id}} Anonymous proposal",
|
|
16
|
+
"fr" => "{{id}} Proposition anonyme"
|
|
17
|
+
},
|
|
18
|
+
"body_label" => {
|
|
19
|
+
"en" => "Please write your proposal",
|
|
20
|
+
"fr" => "Veuillez écrire votre proposition"
|
|
21
|
+
},
|
|
22
|
+
"verification_label" => {
|
|
23
|
+
"en" => "Thanks, here is your proposal:",
|
|
24
|
+
"fr" => "Merci, voici votre proposition :"
|
|
25
|
+
},
|
|
26
|
+
"action_prompt_label" => {
|
|
27
|
+
"en" => "What do you want to do with the proposal?",
|
|
28
|
+
"fr" => "Que voulez-vous faire de la proposition ?"
|
|
29
|
+
},
|
|
30
|
+
"save_button_label" => {
|
|
31
|
+
"en" => "Save",
|
|
32
|
+
"fr" => "Enregistrer"
|
|
33
|
+
},
|
|
34
|
+
"success_label" => {
|
|
35
|
+
"en" => "Your proposal has been submitted",
|
|
36
|
+
"fr" => "Votre proposition a été envoyée"
|
|
37
|
+
},
|
|
38
|
+
"withdraw_button_label" => {
|
|
39
|
+
"en" => "Withdraw",
|
|
40
|
+
"fr" => "Retirer"
|
|
41
|
+
},
|
|
42
|
+
"withdraw_success_label" => {
|
|
43
|
+
"en" => "Your proposal has been withdrawn",
|
|
44
|
+
"fr" => "Votre proposition a été retirée"
|
|
45
|
+
},
|
|
46
|
+
"creation_not_enabled_label" => {
|
|
47
|
+
"en" => "Proposal creation is not available right now, please come back later.",
|
|
48
|
+
"fr" => "La création de propositions n'est pas disponible pour le moment, veuillez revenir plus tard."
|
|
49
|
+
},
|
|
50
|
+
"title_blank_label" => {
|
|
51
|
+
"en" => "cannot be blank",
|
|
52
|
+
"fr" => "ne peut être vide"
|
|
53
|
+
},
|
|
54
|
+
"body_blank_label" => {
|
|
55
|
+
"en" => "cannot be blank",
|
|
56
|
+
"fr" => "ne peut être vide"
|
|
57
|
+
},
|
|
58
|
+
"title_must_start_with_caps_label" => {
|
|
59
|
+
"en" => "must start with a capital letter",
|
|
60
|
+
"fr" => "doit commencer par une majuscule"
|
|
61
|
+
},
|
|
62
|
+
"body_must_start_with_caps_label" => {
|
|
63
|
+
"en" => "must start with a capital letter",
|
|
64
|
+
"fr" => "doit commencer par une majuscule"
|
|
65
|
+
},
|
|
66
|
+
"title_too_much_caps_label" => {
|
|
67
|
+
"en" => "is using too many capital letters (over 25% of the text)",
|
|
68
|
+
"fr" => "utilise trop de lettres majuscules (plus de 25% du texte)"
|
|
69
|
+
},
|
|
70
|
+
"body_too_much_caps_label" => {
|
|
71
|
+
"en" => "is using too many capital letters (over 25% of the text)",
|
|
72
|
+
"fr" => "utilise trop de lettres majuscules (plus de 25% du texte)"
|
|
73
|
+
},
|
|
74
|
+
"title_too_short_label" => {
|
|
75
|
+
"en" => "is too short (under %{count} characters)",
|
|
76
|
+
"fr" => "est trop court (le minimum est de %{count} caractères)"
|
|
77
|
+
},
|
|
78
|
+
"body_too_short_label" => {
|
|
79
|
+
"en" => "is too short (under %{count} characters)",
|
|
80
|
+
"fr" => "est trop court (le minimum est de %{count} caractères)"
|
|
81
|
+
},
|
|
82
|
+
"title_too_long_label" => {
|
|
83
|
+
"en" => "is too long (maximum is %{count} characters)",
|
|
84
|
+
"fr" => "est trop long (pas plus de %{count} caractères)"
|
|
85
|
+
},
|
|
86
|
+
"body_too_long_label" => {
|
|
87
|
+
"en" => "is too long (maximum is %{count} characters)",
|
|
88
|
+
"fr" => "est trop long (pas plus de %{count} caractères)"
|
|
89
|
+
},
|
|
90
|
+
"title_too_many_marks_label" => {
|
|
91
|
+
"en" => "is using too many consecutive punctuation marks (e.g. ! and ?)",
|
|
92
|
+
"fr" => "utilise trop de signes de ponctuation consécutifs (par exemple! et?)"
|
|
93
|
+
},
|
|
94
|
+
"body_too_many_marks_label" => {
|
|
95
|
+
"en" => "is using too many consecutive punctuation marks (e.g. ! and ?)",
|
|
96
|
+
"fr" => "utilise trop de signes de ponctuation consécutifs (par exemple! et?)"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
before do
|
|
102
|
+
enable_chatbot!(organization)
|
|
103
|
+
switch_to_host(organization.host)
|
|
104
|
+
login_as user, scope: :user
|
|
105
|
+
visit decidim_admin_chatbot.chatbot_menu_items_path(chatbot)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "prefills every propose label in all organization locales" do
|
|
109
|
+
click_on "Add"
|
|
110
|
+
click_on "Propose proposals"
|
|
111
|
+
|
|
112
|
+
expected.each do |attr, translations|
|
|
113
|
+
translations.each do |locale, value|
|
|
114
|
+
expect(page).to have_field("item_#{attr}_#{locale}", with: value),
|
|
115
|
+
"expected #{attr} (#{locale}) to be prefilled with #{value.inspect}"
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin sees type-specific fields on new item forms", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr es)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
enable_chatbot!(organization)
|
|
12
|
+
switch_to_host(organization.host)
|
|
13
|
+
login_as user, scope: :user
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def open_menu_type(label)
|
|
17
|
+
visit decidim_admin_chatbot.chatbot_menu_items_path(chatbot)
|
|
18
|
+
click_on "Add"
|
|
19
|
+
click_on label
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def open_notification_type(label)
|
|
23
|
+
visit decidim_admin_chatbot.chatbot_notifications_path(chatbot)
|
|
24
|
+
click_on "Add"
|
|
25
|
+
click_on label
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "shows login fields and hides propose / component fields" do
|
|
29
|
+
open_menu_type("Login")
|
|
30
|
+
expect(page).to have_field("item_redirect_path")
|
|
31
|
+
expect(page).to have_field("item_response_label_en")
|
|
32
|
+
expect(page).to have_no_field("item_component_id")
|
|
33
|
+
expect(page).to have_no_field("item_body_label_en")
|
|
34
|
+
expect(page).to have_no_field("item_template_id_en")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "shows exit response label only" do
|
|
38
|
+
open_menu_type("Exit")
|
|
39
|
+
expect(page).to have_field("item_response_label_en")
|
|
40
|
+
expect(page).to have_no_field("item_redirect_path")
|
|
41
|
+
expect(page).to have_no_field("item_component_id")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "shows read blogs component and read labels" do
|
|
45
|
+
open_menu_type("Read blogs")
|
|
46
|
+
expect(page).to have_field("item_component_id")
|
|
47
|
+
expect(page).to have_field("item_menu_button_label_en")
|
|
48
|
+
expect(page).to have_field("item_nothing_to_read_label_en")
|
|
49
|
+
expect(page).to have_no_field("item_body_label_en")
|
|
50
|
+
expect(page).to have_no_field("item_redirect_path")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "shows propose label fields and hides read-more labels" do
|
|
54
|
+
open_menu_type("Propose proposals")
|
|
55
|
+
expect(page).to have_field("item_component_id")
|
|
56
|
+
expect(page).to have_field("item_body_label_en")
|
|
57
|
+
expect(page).to have_field("item_title_blank_label_en")
|
|
58
|
+
expect(page).to have_no_field("item_read_more_button_label_en")
|
|
59
|
+
expect(page).to have_no_field("item_redirect_path")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "shows vote component and menu button without vote labels on new" do
|
|
63
|
+
open_menu_type("Vote on a proposal")
|
|
64
|
+
expect(page).to have_field("item_component_id")
|
|
65
|
+
expect(page).to have_field("item_action_prompt_label_en")
|
|
66
|
+
expect(page).to have_field("item_menu_button_label_en")
|
|
67
|
+
expect(page).to have_field("item_menu_connector_label_en")
|
|
68
|
+
expect(page).to have_field("item_skip_menu_button_en")
|
|
69
|
+
expect(page).to have_no_field("item_vote_label_en")
|
|
70
|
+
expect(page).to have_no_field("item_body_label_en")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "shows phase space and checkboxes without variables_json" do
|
|
74
|
+
open_notification_type("Phase")
|
|
75
|
+
expect(page).to have_field("item_participatory_space_gid")
|
|
76
|
+
expect(page).to have_field("item_template_id_en")
|
|
77
|
+
expect(page).to have_field("item_use_space_name")
|
|
78
|
+
expect(page).to have_no_field("item_variables_json_en")
|
|
79
|
+
expect(page).to have_no_field("item_component_id")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "shows manual template and variables_json without phase space" do
|
|
83
|
+
open_notification_type("Manual")
|
|
84
|
+
expect(page).to have_field("item_template_id_en")
|
|
85
|
+
expect(page).to have_field("item_variables_json_en")
|
|
86
|
+
expect(page).to have_no_field("item_participatory_space_gid")
|
|
87
|
+
expect(page).to have_no_field("item_use_space_name")
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin sees WhatsApp facts and can sync", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:, whatsapp_display_name: "Visible Bot") }
|
|
9
|
+
let(:client) { instance_double(Decidim::Chatbot::Whatsapp::GraphClient) }
|
|
10
|
+
let(:details) do
|
|
11
|
+
{
|
|
12
|
+
verified_name: "Synced Bot",
|
|
13
|
+
display_phone_number: "+15550001212",
|
|
14
|
+
platform_type: "CLOUD_API",
|
|
15
|
+
subscribed_apps: [{ "id" => "1" }],
|
|
16
|
+
health_status: { "can_send_message" => "AVAILABLE", "entities" => [] }
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
before do
|
|
21
|
+
enable_chatbot!(organization)
|
|
22
|
+
allow(Decidim::Chatbot::Whatsapp::GraphClient).to receive(:new).and_return(client)
|
|
23
|
+
allow(client).to receive(:fetch_phone).and_return(details)
|
|
24
|
+
switch_to_host(organization.host)
|
|
25
|
+
login_as user, scope: :user
|
|
26
|
+
visit decidim_admin_chatbot.chatbot_whatsapp_path(chatbot)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "shows facts and syncs without a sticky save" do
|
|
30
|
+
expect(page).to have_css("[data-announcement]",
|
|
31
|
+
text: "Synced from your WhatsApp Business Profile. Use Sync to refresh them.")
|
|
32
|
+
expect(page).to have_content(chatbot.whatsapp_phone_id)
|
|
33
|
+
expect(page).to have_content("Visible Bot")
|
|
34
|
+
expect(page).to have_no_button("Link")
|
|
35
|
+
expect(page).to have_no_field("phone_id")
|
|
36
|
+
expect(page).to have_button("Sync")
|
|
37
|
+
expect(page).to have_no_css(".item__edit-sticky")
|
|
38
|
+
within(".main-tabs-menu__buttons") do
|
|
39
|
+
expect(page).to have_no_button
|
|
40
|
+
expect(page).to have_no_link
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
click_on "Sync"
|
|
44
|
+
|
|
45
|
+
expect(page).to have_admin_callout("WhatsApp information updated successfully")
|
|
46
|
+
expect(chatbot.reload.whatsapp_display_name).to eq("Synced Bot")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin sees WhatsApp template edit link", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr es)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let!(:item) do
|
|
10
|
+
create(
|
|
11
|
+
:chatbot_item,
|
|
12
|
+
chatbot:,
|
|
13
|
+
scope: "notification",
|
|
14
|
+
manifest_name: "manual",
|
|
15
|
+
settings: {
|
|
16
|
+
"template_id" => { "en" => "1649483436030166" },
|
|
17
|
+
"variables" => { "en" => {} }
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
before do
|
|
23
|
+
enable_chatbot!(organization, "business_id" => "1241516778015058")
|
|
24
|
+
switch_to_host(organization.host)
|
|
25
|
+
login_as user, scope: :user
|
|
26
|
+
visit decidim_admin_chatbot.edit_chatbot_notification_path(chatbot, item)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "shows the Meta validation helper and an edit link to WhatsApp Manager" do
|
|
30
|
+
expect(page).to have_content("Template modifications can take up to 3 days to be validated by Meta")
|
|
31
|
+
link = find_link("Edit template in WhatsApp Manager")
|
|
32
|
+
expect(link[:target]).to eq("_blank")
|
|
33
|
+
expect(link[:href]).to eq(
|
|
34
|
+
"https://business.facebook.com/latest/whatsapp_manager/1649483436030166/?reason=business_access&business_id=1241516778015058"
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin tests a notification", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr es)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:, whatsapp_phone_id: "phone-1") }
|
|
9
|
+
let(:graph) { instance_double(Decidim::Chatbot::Whatsapp::GraphClient, send_template: { "messages" => [] }) }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
enable_chatbot!(organization)
|
|
13
|
+
switch_to_host(organization.host)
|
|
14
|
+
login_as user, scope: :user
|
|
15
|
+
allow(Decidim::Chatbot::Whatsapp::GraphClient).to receive(:new).and_return(graph)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "sends a manual notification with submitted variable fields" do
|
|
19
|
+
item = create(
|
|
20
|
+
:chatbot_item,
|
|
21
|
+
chatbot:,
|
|
22
|
+
scope: "notification",
|
|
23
|
+
manifest_name: "manual",
|
|
24
|
+
settings: {
|
|
25
|
+
"template_id" => { "en" => "1649483436030166", "fr" => "1649483436030167" },
|
|
26
|
+
"variables" => { "en" => { "city" => "Nairobi" } }
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
visit decidim_admin_chatbot.chatbot_notifications_path(chatbot)
|
|
31
|
+
click_on "Test"
|
|
32
|
+
|
|
33
|
+
expect(page).to have_select("test_locale", options: %w(English Français Castellano))
|
|
34
|
+
expect(page).to have_field("test_phone_number")
|
|
35
|
+
expect(page).to have_field("test_values_city", with: "Nairobi")
|
|
36
|
+
expect(page).to have_no_select("test_step_id")
|
|
37
|
+
|
|
38
|
+
fill_in "test_phone_number", with: "+15551234567"
|
|
39
|
+
fill_in "test_values_city", with: "Mombasa"
|
|
40
|
+
select "Français", from: "test_locale"
|
|
41
|
+
click_on "Send"
|
|
42
|
+
|
|
43
|
+
expect(page).to have_admin_callout("Test notification sent.")
|
|
44
|
+
expect(graph).to have_received(:send_template).with(
|
|
45
|
+
"phone-1",
|
|
46
|
+
to: "15551234567",
|
|
47
|
+
template_id: "1649483436030167",
|
|
48
|
+
parameters: [{ type: "text", parameter_name: "city", text: "Mombasa" }]
|
|
49
|
+
)
|
|
50
|
+
expect(page).to have_current_path(decidim_admin_chatbot.chatbot_notifications_path(chatbot))
|
|
51
|
+
expect(item.reload.settings["variables"]["en"]).to eq("city" => "Nairobi")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "sends a phase notification using the selected process step" do
|
|
55
|
+
process = create(:participatory_process, :published, organization:, title: { "en" => "Town process" })
|
|
56
|
+
create(
|
|
57
|
+
:participatory_process_step,
|
|
58
|
+
participatory_process: process,
|
|
59
|
+
title: { "en" => "Collect ideas" },
|
|
60
|
+
start_date: Date.new(2026, 1, 1),
|
|
61
|
+
end_date: Date.new(2026, 2, 1)
|
|
62
|
+
)
|
|
63
|
+
create(
|
|
64
|
+
:chatbot_item,
|
|
65
|
+
chatbot:,
|
|
66
|
+
scope: "notification",
|
|
67
|
+
manifest_name: "phase",
|
|
68
|
+
settings: {
|
|
69
|
+
"template_id" => { "en" => "1649483436030169" },
|
|
70
|
+
"variables" => { "en" => { "space_name" => "%{space_name}" } },
|
|
71
|
+
"participatory_space_gid" => process.to_gid.to_s
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
visit decidim_admin_chatbot.chatbot_notifications_path(chatbot)
|
|
76
|
+
click_on "Test"
|
|
77
|
+
|
|
78
|
+
expect(page).to have_select("test_locale", options: %w(English Français Castellano))
|
|
79
|
+
expect(page).to have_select("test_step_id")
|
|
80
|
+
expect(page).to have_no_field("test_values_1")
|
|
81
|
+
fill_in "test_phone_number", with: "15557654321"
|
|
82
|
+
select "Collect ideas", from: "test_step_id"
|
|
83
|
+
click_on "Send"
|
|
84
|
+
|
|
85
|
+
expect(page).to have_admin_callout("Test notification sent.")
|
|
86
|
+
expect(graph).to have_received(:send_template).with(
|
|
87
|
+
"phone-1",
|
|
88
|
+
to: "15557654321",
|
|
89
|
+
template_id: "1649483436030169",
|
|
90
|
+
parameters: [{ type: "text", parameter_name: "space_name", text: "Town process" }]
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "shows the Facebook Graph error when send fails" do
|
|
95
|
+
create(
|
|
96
|
+
:chatbot_item,
|
|
97
|
+
chatbot:,
|
|
98
|
+
scope: "notification",
|
|
99
|
+
manifest_name: "manual",
|
|
100
|
+
settings: {
|
|
101
|
+
"template_id" => { "en" => "1649483436030166" },
|
|
102
|
+
"variables" => { "en" => { "city" => "Nairobi" } }
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
allow(graph).to receive(:send_template).and_raise(
|
|
106
|
+
RuntimeError,
|
|
107
|
+
'Graph API 400: {"error":{"message":"Your request has violated JSON schema constraint \'required\' for the JSON field \'template\'.","code":100,"type":"OAuthException"}}'
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
visit decidim_admin_chatbot.chatbot_notifications_path(chatbot)
|
|
111
|
+
click_on "Test"
|
|
112
|
+
fill_in "test_phone_number", with: "+15551234567"
|
|
113
|
+
click_on "Send"
|
|
114
|
+
|
|
115
|
+
expect(page).to have_admin_callout(
|
|
116
|
+
"There was a problem sending the test notification. Your request has violated JSON schema constraint 'required' for the JSON field 'template'."
|
|
117
|
+
)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "does not offer Test on menu items" do
|
|
121
|
+
create(:chatbot_item, chatbot:)
|
|
122
|
+
visit decidim_admin_chatbot.chatbot_menu_items_path(chatbot)
|
|
123
|
+
expect(page).to have_no_link("Test")
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin unchecks Enabled on a menu item", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr es)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let!(:item) { create(:chatbot_item, chatbot:, title: { "en" => "Sign in" }) }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
enable_chatbot!(organization)
|
|
13
|
+
switch_to_host(organization.host)
|
|
14
|
+
login_as user, scope: :user
|
|
15
|
+
visit decidim_admin_chatbot.edit_chatbot_menu_item_path(chatbot, item)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "saves disabled and fades the table row" do
|
|
19
|
+
expect(page).to have_css(".process-title-content-breadcrumb-container-left", text: "Edit Sign in")
|
|
20
|
+
expect(page).to have_css("#item_title_en[maxlength='20'][data-controller='character-counter']")
|
|
21
|
+
expect(page).to have_css(".row.column")
|
|
22
|
+
expect(page).to have_checked_field("Enabled")
|
|
23
|
+
uncheck "Enabled"
|
|
24
|
+
within(".item__edit-sticky") { click_on "Save" }
|
|
25
|
+
|
|
26
|
+
expect(page).to have_admin_callout("Item saved successfully")
|
|
27
|
+
expect(item.reload).not_to be_enabled
|
|
28
|
+
expect(find("tr[data-record-id='#{item.id}']")[:style]).to include("opacity: 0.6")
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin unsubscribes WhatsApp user from chatbot", driver: :rack_test do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: %w(en fr es)) }
|
|
7
|
+
let(:user) { create(:user, :admin, :confirmed, organization:) }
|
|
8
|
+
let!(:chatbot) { create(:chatbot, organization:) }
|
|
9
|
+
let!(:member) do
|
|
10
|
+
create(:user, :confirmed, organization:, name: "Ada Lovelace",
|
|
11
|
+
extended_data: { "whatsapp_phone_number" => "+15550001" })
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
enable_chatbot!(organization)
|
|
16
|
+
switch_to_host(organization.host)
|
|
17
|
+
login_as user, scope: :user
|
|
18
|
+
visit decidim_admin_chatbot.chatbot_users_path(chatbot)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "unsubscribes and keeps the row listed" do
|
|
22
|
+
expect(page).to have_css(".fcell.search")
|
|
23
|
+
expect(page).to have_no_css("[data-target^='dropdown-filters']")
|
|
24
|
+
expect(page).to have_content("Ada Lovelace")
|
|
25
|
+
expect(page).to have_content("+15550001")
|
|
26
|
+
expect(page).to have_content("Subscribed")
|
|
27
|
+
|
|
28
|
+
find(".dropdown__button--danger", text: "Unsubscribe", visible: :all).click
|
|
29
|
+
|
|
30
|
+
expect(page).to have_admin_callout("User unsubscribed successfully")
|
|
31
|
+
expect(page).to have_content("Ada Lovelace")
|
|
32
|
+
expect(page).to have_content("Unsubscribed")
|
|
33
|
+
expect(member.reload.extended_data[chatbot.subscription_key]).to be(false)
|
|
34
|
+
end
|
|
35
|
+
end
|