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,205 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::Chatbot::Whatsapp::GraphClient do
|
|
6
|
+
subject(:client) { described_class.new(access_token: "tok", business_id: "biz") }
|
|
7
|
+
|
|
8
|
+
let(:http) { instance_double(Net::HTTP) }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
allow(Net::HTTP).to receive(:start).and_yield(http)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def stub_get(path_fragment, body)
|
|
15
|
+
response = instance_double(Net::HTTPSuccess, body: body.to_json, is_a?: true)
|
|
16
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
|
17
|
+
allow(http).to receive(:request) do |req|
|
|
18
|
+
expect(req["Authorization"]).to eq("Bearer tok")
|
|
19
|
+
expect(req.uri.to_s).to include(path_fragment)
|
|
20
|
+
response
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "#fetch_phone" do
|
|
25
|
+
it "returns phone details when the phone belongs to an owned WABA" do
|
|
26
|
+
responses = {
|
|
27
|
+
"owned_whatsapp_business_accounts" => { "data" => [{ "id" => "waba1" }] },
|
|
28
|
+
"phone_numbers" => { "data" => [{ "id" => "p1", "display_phone_number" => "+1" }] },
|
|
29
|
+
"subscribed_apps" => { "data" => [{ "whatsapp_business_api_data" => { "id" => "app" } }] },
|
|
30
|
+
"fields=health_status" => {
|
|
31
|
+
"health_status" => { "can_send_message" => "AVAILABLE" },
|
|
32
|
+
"platform_type" => "CLOUD_API",
|
|
33
|
+
"display_phone_number" => "+1",
|
|
34
|
+
"verified_name" => "Bot"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
allow(http).to receive(:request) do |req|
|
|
39
|
+
expect(req.uri.to_s).to include("/#{Decidim::Chatbot.whatsapp_api_version}/")
|
|
40
|
+
key = responses.keys.find { |fragment| req.uri.to_s.include?(fragment) }
|
|
41
|
+
raise "unexpected #{req.uri}" unless key
|
|
42
|
+
|
|
43
|
+
body = responses[key]
|
|
44
|
+
response = instance_double(Net::HTTPSuccess, body: body.to_json)
|
|
45
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
|
46
|
+
response
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
details = client.fetch_phone("p1")
|
|
50
|
+
expect(details[:id]).to eq("p1")
|
|
51
|
+
expect(details[:verified_name]).to eq("Bot")
|
|
52
|
+
expect(details[:waba]).to eq("waba1")
|
|
53
|
+
expect(details[:subscribed_apps]).to eq([{ "id" => "app" }])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "returns nil when the phone is not listed" do
|
|
57
|
+
allow(http).to receive(:request) do |req|
|
|
58
|
+
body =
|
|
59
|
+
if req.uri.to_s.include?("owned_whatsapp_business_accounts")
|
|
60
|
+
{ "data" => [{ "id" => "waba1" }] }
|
|
61
|
+
else
|
|
62
|
+
{ "data" => [] }
|
|
63
|
+
end
|
|
64
|
+
response = instance_double(Net::HTTPSuccess, body: body.to_json)
|
|
65
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
|
66
|
+
response
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
expect(client.fetch_phone("missing")).to be_nil
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "raises when Graph returns an error" do
|
|
73
|
+
error = instance_double(Net::HTTPBadRequest, code: "400", body: "nope", is_a?: false)
|
|
74
|
+
allow(error).to receive(:is_a?).with(Net::HTTPSuccess).and_return(false)
|
|
75
|
+
allow(http).to receive(:request).and_return(error)
|
|
76
|
+
|
|
77
|
+
expect { client.fetch_phone("p1") }.to raise_error(/Graph API 400/)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe "#fetch_template" do
|
|
82
|
+
it "GETs template fields by id" do
|
|
83
|
+
stub_get(
|
|
84
|
+
"1649483436030166?fields=name,language,status",
|
|
85
|
+
"id" => "1649483436030166",
|
|
86
|
+
"name" => "2023_april_promo",
|
|
87
|
+
"language" => "en_US",
|
|
88
|
+
"status" => "APPROVED"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
expect(client.fetch_template("1649483436030166")).to include(
|
|
92
|
+
"name" => "2023_april_promo",
|
|
93
|
+
"language" => "en_US",
|
|
94
|
+
"status" => "APPROVED"
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe "#send_template" do
|
|
100
|
+
def stub_template_then_send(template_id:, template_name:, template_language:)
|
|
101
|
+
allow(http).to receive(:request) do |req|
|
|
102
|
+
expect(req["Authorization"]).to eq("Bearer tok")
|
|
103
|
+
if req.is_a?(Net::HTTP::Get)
|
|
104
|
+
expect(req.uri.to_s).to include("/#{template_id}?fields=name,language,status")
|
|
105
|
+
body = {
|
|
106
|
+
"id" => template_id,
|
|
107
|
+
"name" => template_name,
|
|
108
|
+
"language" => template_language,
|
|
109
|
+
"status" => "APPROVED"
|
|
110
|
+
}
|
|
111
|
+
response = instance_double(Net::HTTPSuccess, body: body.to_json)
|
|
112
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
|
113
|
+
response
|
|
114
|
+
else
|
|
115
|
+
expect(req).to be_a(Net::HTTP::Post)
|
|
116
|
+
yield(req)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "resolves Meta name and language from template id then POSTs (not Decidim locale)" do
|
|
122
|
+
stub_template_then_send(
|
|
123
|
+
template_id: "1649483436030166",
|
|
124
|
+
template_name: "2023_april_promo",
|
|
125
|
+
template_language: "pt_BR"
|
|
126
|
+
) do |req|
|
|
127
|
+
expect(req.uri.to_s).to include("/p1/messages")
|
|
128
|
+
payload = JSON.parse(req.body)
|
|
129
|
+
expect(payload["to"]).to eq("15551234567")
|
|
130
|
+
expect(payload["template"]).not_to have_key("id")
|
|
131
|
+
expect(payload["template"]["name"]).to eq("2023_april_promo")
|
|
132
|
+
expect(payload["template"]["language"]).to eq("code" => "pt_BR")
|
|
133
|
+
expect(payload["template"]["components"]).to eq(
|
|
134
|
+
[{ "type" => "body", "parameters" => [{ "type" => "text", "parameter_name" => "city", "text" => "Nairobi" }] }]
|
|
135
|
+
)
|
|
136
|
+
response = instance_double(Net::HTTPSuccess, body: { "messages" => [] }.to_json)
|
|
137
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
|
138
|
+
response
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
client.send_template(
|
|
142
|
+
"p1",
|
|
143
|
+
to: "+15551234567",
|
|
144
|
+
template_id: "1649483436030166",
|
|
145
|
+
parameters: [{ type: "text", parameter_name: "city", text: "Nairobi" }]
|
|
146
|
+
)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "raises when template name is blank" do
|
|
150
|
+
stub_get(
|
|
151
|
+
"1649483436030166?fields=name,language,status",
|
|
152
|
+
"id" => "1649483436030166",
|
|
153
|
+
"name" => "",
|
|
154
|
+
"language" => "en_US"
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
expect do
|
|
158
|
+
client.send_template("p1", to: "+15551234567", template_id: "1649483436030166")
|
|
159
|
+
end.to raise_error(/Graph API template missing name/)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "raises when template language is blank" do
|
|
163
|
+
stub_get(
|
|
164
|
+
"1649483436030166?fields=name,language,status",
|
|
165
|
+
"id" => "1649483436030166",
|
|
166
|
+
"name" => "account_creation_confirmation",
|
|
167
|
+
"language" => ""
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
expect do
|
|
171
|
+
client.send_template("p1", to: "+15551234567", template_id: "1649483436030166")
|
|
172
|
+
end.to raise_error(/Graph API template missing language/)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it "omits body components when no parameters are supplied" do
|
|
176
|
+
stub_template_then_send(
|
|
177
|
+
template_id: "1649483436030166",
|
|
178
|
+
template_name: "account_creation_confirmation",
|
|
179
|
+
template_language: "en_US"
|
|
180
|
+
) do |req|
|
|
181
|
+
payload = JSON.parse(req.body)
|
|
182
|
+
expect(payload["template"]).not_to have_key("components")
|
|
183
|
+
response = instance_double(Net::HTTPSuccess, body: { "messages" => [] }.to_json)
|
|
184
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
|
185
|
+
response
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
client.send_template("p1", to: "+15551234567", template_id: "1649483436030166")
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "raises when template is not APPROVED" do
|
|
192
|
+
stub_get(
|
|
193
|
+
"1361142915751283?fields=name,language,status",
|
|
194
|
+
"id" => "1361142915751283",
|
|
195
|
+
"name" => "account_creation_confirmation",
|
|
196
|
+
"language" => "en_US",
|
|
197
|
+
"status" => "PENDING"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
expect do
|
|
201
|
+
client.send_template("p1", to: "+15551234567", template_id: "1361142915751283")
|
|
202
|
+
end.to raise_error(/account_creation_confirmation \(en_US\) is PENDING/)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Decidim::Chatbot::Whatsapp::TemplateManagerUrl do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
Decidim::Toggle.save_config!(
|
|
10
|
+
organization,
|
|
11
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
12
|
+
{ "enabled" => true, "access_token" => "token", "business_id" => "1241516778015058" }
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "builds a WhatsApp Manager edit URL with business_id and template id" do
|
|
17
|
+
url = described_class.for(organization, "1649483436030166")
|
|
18
|
+
expect(url).to eq(
|
|
19
|
+
"https://business.facebook.com/latest/whatsapp_manager/1649483436030166/?reason=business_access&business_id=1241516778015058"
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "returns nil when the template id is blank" do
|
|
24
|
+
expect(described_class.for(organization, "")).to be_nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "builds a WhatsApp Manager message templates URL with business_id" do
|
|
28
|
+
url = described_class.message_templates_for(organization)
|
|
29
|
+
expect(url).to eq(
|
|
30
|
+
"https://business.facebook.com/latest/whatsapp_manager/message_templates/?business_id=1241516778015058"
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
ENV["ENGINE_ROOT"] = File.dirname(__dir__)
|
|
4
|
+
ENV["RAILS_ENV"] ||= "test"
|
|
5
|
+
ENV["DISABLE_SPRING"] = "1"
|
|
6
|
+
# Decidim 0.32 image sets DECIDIM_FORCE_SSL=auto; treat that as enabled SSL.
|
|
7
|
+
ENV["DECIDIM_FORCE_SSL"] = "false"
|
|
8
|
+
|
|
9
|
+
require "decidim/dev"
|
|
10
|
+
|
|
11
|
+
Decidim::Dev.dummy_app_path = File.expand_path(File.join(__dir__, "decidim_dummy_app"))
|
|
12
|
+
|
|
13
|
+
require "decidim/dev/test/map_server"
|
|
14
|
+
require "decidim/dev/test/base_spec_helper"
|
|
15
|
+
require "decidim/core/test/factories"
|
|
16
|
+
|
|
17
|
+
require "decidim/rest_full/test/global_context"
|
|
18
|
+
require "decidim/rest_full/test/on_api_endpoint_methods"
|
|
19
|
+
require "decidim/rest_full/test/factories"
|
|
20
|
+
|
|
21
|
+
Decidim::RestFull::Routes.draw! unless Decidim::RestFull::Routes.routes_drawn?
|
|
22
|
+
|
|
23
|
+
test_locales = %w(en fr es)
|
|
24
|
+
I18n.available_locales = test_locales.map(&:to_sym)
|
|
25
|
+
I18n.enforce_available_locales = false
|
|
26
|
+
Rails.application.config.i18n.available_locales = test_locales
|
|
27
|
+
Rails.application.config.i18n.default_locale = :en
|
|
28
|
+
Decidim.available_locales = test_locales
|
|
29
|
+
Decidim.default_locale = :en
|
|
30
|
+
|
|
31
|
+
require "decidim/rest_full/test/definitions"
|
|
32
|
+
|
|
33
|
+
Dir[File.expand_path("support/**/*.rb", __dir__)].each { |f| require f }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Decidim request specs set Host to organization.*.lvh.me; Rails HostAuthorization
|
|
4
|
+
# otherwise 403s unless every host is allowlisted. Skip the check in this gem's specs.
|
|
5
|
+
ActionDispatch::HostAuthorization.class_eval do
|
|
6
|
+
def call(env)
|
|
7
|
+
@app.call(env)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ChatbotAdminHelpers
|
|
4
|
+
def enable_chatbot!(organization, extras = {})
|
|
5
|
+
Decidim::Toggle.save_config!(
|
|
6
|
+
organization,
|
|
7
|
+
Decidim::Chatbot::MODULE_NAME,
|
|
8
|
+
{ "enabled" => true, "access_token" => "token", "business_id" => "biz" }.merge(extras)
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
RSpec.configure do |config|
|
|
14
|
+
config.include ChatbotAdminHelpers
|
|
15
|
+
config.include Devise::Test::IntegrationHelpers, type: :request
|
|
16
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Decidim's type: :system hook always calls driven_by(:headless_chrome) and then
|
|
4
|
+
# sets the consent cookie via CDP when an organization is present. That boots
|
|
5
|
+
# chromedriver even for examples tagged driver: :rack_test. Force rack_test and
|
|
6
|
+
# no-op CDP for those examples.
|
|
7
|
+
module Decidim
|
|
8
|
+
module Chatbot
|
|
9
|
+
module RackTestSystemDriver
|
|
10
|
+
def driven_by(driver, **driver_options, &)
|
|
11
|
+
driver = :rack_test if rack_test_driver_example?
|
|
12
|
+
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def rack_test_driver_example?
|
|
19
|
+
example = RSpec.current_example
|
|
20
|
+
example && example.metadata[:driver] == :rack_test
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module Capybara
|
|
27
|
+
module RackTest
|
|
28
|
+
class Browser
|
|
29
|
+
def execute_cdp(*)
|
|
30
|
+
# Consent cookie setup uses CDP in Decidim's system hook; not needed for rack_test smoke specs.
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
RSpec.configure do |config|
|
|
37
|
+
config.prepend Decidim::Chatbot::RackTestSystemDriver, type: :system
|
|
38
|
+
|
|
39
|
+
config.prepend_before(:each, driver: :rack_test, type: :system) do
|
|
40
|
+
driven_by(:rack_test)
|
|
41
|
+
switch_to_default_host
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WhatsappGraphHelpers
|
|
4
|
+
def stub_approved_template
|
|
5
|
+
client = instance_double(Decidim::Chatbot::Whatsapp::GraphClient)
|
|
6
|
+
allow(Decidim::Chatbot::Whatsapp::GraphClient).to receive(:new).and_return(client)
|
|
7
|
+
allow(client).to receive(:fetch_phone).and_return({ waba: "waba1" }.with_indifferent_access)
|
|
8
|
+
allow(client).to receive(:send_template).and_return("messages" => [])
|
|
9
|
+
client
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
RSpec.configure do |config|
|
|
14
|
+
config.include WhatsappGraphHelpers
|
|
15
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
require "rswag/specs"
|
|
5
|
+
|
|
6
|
+
require "decidim/rest_full/test/definitions"
|
|
7
|
+
require "decidim/rest_full/test/shared_examples"
|
|
8
|
+
require "decidim/rest_full/test/openapi_specs"
|
|
9
|
+
require "decidim/rest_full/test/factories"
|
|
10
|
+
|
|
11
|
+
# HostAuthorization bypass lives in spec/support/allow_all_hosts.rb (via spec_helper).
|
|
12
|
+
|
|
13
|
+
RSpec.configure do |config|
|
|
14
|
+
config.openapi_root = Rails.root.join("swagger").to_s
|
|
15
|
+
config.extend Decidim::RestFull::Test::OnApiEndpointMethods
|
|
16
|
+
config.before do
|
|
17
|
+
Decidim::RestFull::Test::GlobalContext.security_type = nil
|
|
18
|
+
end
|
|
19
|
+
config.use_transactional_fixtures = true
|
|
20
|
+
|
|
21
|
+
config.after do |example|
|
|
22
|
+
next unless example.metadata[:type] == :request
|
|
23
|
+
next unless example.metadata[:response]
|
|
24
|
+
|
|
25
|
+
content = example.metadata[:response][:content] || {}
|
|
26
|
+
example_name = example.metadata[:example_name]
|
|
27
|
+
if example_name
|
|
28
|
+
json_data = begin
|
|
29
|
+
JSON.parse(response.body, symbolize_names: true)
|
|
30
|
+
rescue StandardError
|
|
31
|
+
{}
|
|
32
|
+
end
|
|
33
|
+
example_spec = {
|
|
34
|
+
"application/json" => {
|
|
35
|
+
examples: {
|
|
36
|
+
example_name.to_sym => {
|
|
37
|
+
value: json_data
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
example.metadata[:response][:content] = content.deep_merge(example_spec)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
config.openapi_specs = Decidim::RestFull::Test.openapi_specs
|
|
47
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin send on manual is allowed when ready", 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)
|
|
24
|
+
switch_to_host(organization.host)
|
|
25
|
+
login_as user, scope: :user
|
|
26
|
+
allow(Decidim::Chatbot::SendNotificationJob).to receive(:perform_later)
|
|
27
|
+
visit decidim_admin_chatbot.edit_chatbot_notification_path(chatbot, item)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "enqueues the blast" do
|
|
31
|
+
click_on "Send now"
|
|
32
|
+
expect(page).to have_admin_callout("Notification queued to send.")
|
|
33
|
+
expect(Decidim::Chatbot::SendNotificationJob).to have_received(:perform_later).with(item.id, user.id)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin configures vote on proposal 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(:space) do
|
|
10
|
+
create(:participatory_process, :published, :with_steps, organization:, title: { "en" => "Visible process" })
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
before do
|
|
14
|
+
enable_chatbot!(organization)
|
|
15
|
+
switch_to_host(organization.host)
|
|
16
|
+
login_as user, scope: :user
|
|
17
|
+
visit decidim_admin_chatbot.chatbot_menu_items_path(chatbot)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_vote_item(component)
|
|
21
|
+
click_on "Add"
|
|
22
|
+
click_on "Vote on a proposal"
|
|
23
|
+
expect(page).to have_no_css(".grid.grid-cols-2")
|
|
24
|
+
expect(page).to have_no_field("item_vote_label_en")
|
|
25
|
+
select component.hierarchy_title, from: "Proposal Component"
|
|
26
|
+
fill_in "item_title_en", with: "Cast votes"
|
|
27
|
+
fill_in "item_action_prompt_label_en", with: "Here the actions you can do:"
|
|
28
|
+
fill_in "item_menu_button_label_en", with: "Back to menu"
|
|
29
|
+
fill_in "item_menu_connector_label_en", with: "See more"
|
|
30
|
+
fill_in "item_skip_menu_button_en", with: "Skip"
|
|
31
|
+
within(".item__edit-sticky") { click_on "Save" }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "warns when votes are not open and still saves labels" do
|
|
35
|
+
proposals = create(:proposal_component, :with_votes_disabled, participatory_space: space, name: { "en" => "Ideas" })
|
|
36
|
+
create_vote_item(proposals)
|
|
37
|
+
|
|
38
|
+
item = chatbot.items.for_scope(:menu).last
|
|
39
|
+
expect(page).to have_current_path(
|
|
40
|
+
decidim_admin_chatbot.edit_chatbot_menu_item_path(chatbot, item),
|
|
41
|
+
ignore_query: true
|
|
42
|
+
)
|
|
43
|
+
expect(page).to have_content("Voting is not open on this proposal component")
|
|
44
|
+
expect(page).to have_field("item_vote_label_en")
|
|
45
|
+
fill_in "item_vote_label_en", with: "Support"
|
|
46
|
+
expect(page).to have_content("Intro text shown above the voting action menu.")
|
|
47
|
+
expect(page).to have_content("Button to exit voting and go back to the menu.")
|
|
48
|
+
expect(page).to have_content("Shown when there are more than three voting menu items.")
|
|
49
|
+
expect(page).to have_content("Button labeled Skip when no abstention is defined.")
|
|
50
|
+
within(".item__edit-sticky") { click_on "Save" }
|
|
51
|
+
|
|
52
|
+
expect(page).to have_current_path(decidim_admin_chatbot.chatbot_menu_items_path(chatbot), ignore_query: true)
|
|
53
|
+
expect(page).to have_content("Cast votes")
|
|
54
|
+
expect(item.reload.manifest_name).to eq("vote_on_proposal")
|
|
55
|
+
expect(item.settings["component_id"]).to eq(proposals.id)
|
|
56
|
+
expect(item.settings["vote_label"]["en"]).to eq("Support")
|
|
57
|
+
expect(item.settings["action_prompt_label"]["en"]).to eq("Here the actions you can do:")
|
|
58
|
+
expect(item.settings["menu_button_label"]["en"]).to eq("Back to menu")
|
|
59
|
+
expect(item.settings["menu_connector_label"]["en"]).to eq("See more")
|
|
60
|
+
expect(item.settings["skip_menu_button"]["en"]).to eq("Skip")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "saves simple vote labels when votes are open" do
|
|
64
|
+
proposals = create(:proposal_component, :with_votes_enabled, participatory_space: space, name: { "en" => "Ideas" })
|
|
65
|
+
create_vote_item(proposals)
|
|
66
|
+
|
|
67
|
+
item = chatbot.items.for_scope(:menu).last
|
|
68
|
+
expect(page).to have_current_path(
|
|
69
|
+
decidim_admin_chatbot.edit_chatbot_menu_item_path(chatbot, item),
|
|
70
|
+
ignore_query: true
|
|
71
|
+
)
|
|
72
|
+
expect(page).to have_no_content("Voting is not open on this proposal component")
|
|
73
|
+
fill_in "item_vote_label_en", with: "Support"
|
|
74
|
+
within(".item__edit-sticky") { click_on "Save" }
|
|
75
|
+
|
|
76
|
+
expect(page).to have_admin_callout("Item saved successfully")
|
|
77
|
+
expect(page).to have_current_path(decidim_admin_chatbot.chatbot_menu_items_path(chatbot), ignore_query: true)
|
|
78
|
+
expect(item.reload.settings["vote_label"]["en"]).to eq("Support")
|
|
79
|
+
expect(item.settings["action_prompt_label"]["en"]).to eq("Here the actions you can do:")
|
|
80
|
+
expect(item.settings["menu_button_label"]["en"]).to eq("Back to menu")
|
|
81
|
+
expect(item.settings["menu_connector_label"]["en"]).to eq("See more")
|
|
82
|
+
expect(item.settings["skip_menu_button"]["en"]).to eq("Skip")
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin confirms Send now recipient count", 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
|
+
create(:user, organization:, extended_data: { "whatsapp_phone_number" => "+15550001" })
|
|
24
|
+
create(:user, organization:, extended_data: { "whatsapp_phone_number" => "+15550002" })
|
|
25
|
+
create(
|
|
26
|
+
:user,
|
|
27
|
+
organization:,
|
|
28
|
+
extended_data: { "whatsapp_phone_number" => "+15550003", chatbot.subscription_key => false }
|
|
29
|
+
)
|
|
30
|
+
enable_chatbot!(organization)
|
|
31
|
+
switch_to_host(organization.host)
|
|
32
|
+
login_as user, scope: :user
|
|
33
|
+
visit decidim_admin_chatbot.edit_chatbot_notification_path(chatbot, item)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "asks to notify subscribed users only" do
|
|
37
|
+
button = find_button("Send now")
|
|
38
|
+
expect(button["data-confirm"]).to eq("Are you sure you want to notify 2 subscribed users?")
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "Admin creates login 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
|
+
|
|
10
|
+
before do
|
|
11
|
+
enable_chatbot!(organization)
|
|
12
|
+
switch_to_host(organization.host)
|
|
13
|
+
login_as user, scope: :user
|
|
14
|
+
visit decidim_admin_chatbot.chatbot_menu_items_path(chatbot)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "cancels creation back to the menu list" do
|
|
18
|
+
click_on "Add"
|
|
19
|
+
expect(page).to have_no_css(".item_show__header")
|
|
20
|
+
expect(page).to have_no_link("Back to list")
|
|
21
|
+
expect(page).to have_css(".process-title-content-breadcrumb-container-left", text: "New menu item")
|
|
22
|
+
within(".main-tabs-menu") { click_on "Menu" }
|
|
23
|
+
expect(page).to have_current_path(decidim_admin_chatbot.chatbot_menu_items_path(chatbot), ignore_query: true)
|
|
24
|
+
|
|
25
|
+
click_on "Add"
|
|
26
|
+
click_on "Login"
|
|
27
|
+
expect(page).to have_no_css(".item_show__header")
|
|
28
|
+
within(".item__edit-sticky") { click_on "Cancel" }
|
|
29
|
+
expect(page).to have_current_path(decidim_admin_chatbot.chatbot_menu_items_path(chatbot), ignore_query: true)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "adds a login item with redirect path" do
|
|
33
|
+
within(".main-tabs-menu__buttons") { expect(page).to have_no_link("Add") }
|
|
34
|
+
click_on "Add"
|
|
35
|
+
expect(page).to have_css(".grid.grid-cols-2")
|
|
36
|
+
expect(page).to have_css("span.help-text", text: "Read blogs one by one, from the newest to the oldest.")
|
|
37
|
+
expect(page).to have_css("span.help-text", text: "Read proposals already made.")
|
|
38
|
+
expect(page).to have_css("span.help-text", text: "Propose new things.")
|
|
39
|
+
expect(page).to have_css("span.help-text", text: "Vote on accepted proposals.")
|
|
40
|
+
expect(page).to have_css("span.help-text", text: "Log in and redirect to some page.")
|
|
41
|
+
expect(page).to have_css("span.help-text", text: "Unsubscribe from notification.")
|
|
42
|
+
click_on "Login"
|
|
43
|
+
expect(page).to have_css("h2.card-title", text: "New Login menu item")
|
|
44
|
+
expect(page).to have_no_field("item_introduction_en")
|
|
45
|
+
expect(page).to have_no_field("item_hint")
|
|
46
|
+
fill_in "item_title_en", with: "Sign in"
|
|
47
|
+
fill_in "item_redirect_path", with: "/users/sign_in"
|
|
48
|
+
fill_in "item_response_label_en", with: "Open {{login_url}} to continue"
|
|
49
|
+
expect(page).to have_content("You can use {{login_url}} to place the login URL in the response label.")
|
|
50
|
+
expect(page).to have_checked_field("Enabled")
|
|
51
|
+
within(".item__edit-sticky") { click_on "Save" }
|
|
52
|
+
|
|
53
|
+
item = chatbot.items.for_scope(:menu).last
|
|
54
|
+
expect(page).to have_admin_callout("Item saved successfully")
|
|
55
|
+
expect(page).to have_current_path(
|
|
56
|
+
decidim_admin_chatbot.edit_chatbot_menu_item_path(chatbot, item),
|
|
57
|
+
ignore_query: true
|
|
58
|
+
)
|
|
59
|
+
expect(page).to have_field("item_title_en", with: "Sign in")
|
|
60
|
+
expect(item.manifest_name).to eq("login")
|
|
61
|
+
expect(item.settings["redirect_path"]).to eq("/users/sign_in")
|
|
62
|
+
expect(item.settings["response_label"]["en"]).to eq("Open {{login_url}} to continue")
|
|
63
|
+
expect(item).to be_enabled
|
|
64
|
+
end
|
|
65
|
+
end
|