From cec44525c17784749728be4b1100680834ab0278 Mon Sep 17 00:00:00 2001 From: Antoine Augusti Date: Thu, 28 Nov 2024 13:31:17 +0100 Subject: [PATCH] ImportGBFSFeedContactEmailJob : remplit organization pour le contact --- .../lib/jobs/import_gbfs_feed_contact_email_job.ex | 12 +++++++++--- .../jobs/import_gbfs_feed_contact_point_job_test.exs | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/transport/lib/jobs/import_gbfs_feed_contact_email_job.ex b/apps/transport/lib/jobs/import_gbfs_feed_contact_email_job.ex index 1e58fbf9f5..e801435b6b 100644 --- a/apps/transport/lib/jobs/import_gbfs_feed_contact_email_job.ex +++ b/apps/transport/lib/jobs/import_gbfs_feed_contact_email_job.ex @@ -1,11 +1,12 @@ defmodule Transport.Jobs.ImportGBFSFeedContactEmailJob do @moduledoc """ - Reuse `feed_contact_email` from GBFS feed. + Reuse `feed_contact_email` from GBFS feeds. Use these email addresses to find or create a contact and subscribe this contact to producer subscriptions for this dataset. - When a `feed_contact_point` was previously set and has been removed, we delete old subscriptions. + When a `feed_contact_point` was previously set and changed, + we delete old subscriptions and create new ones. """ use Oban.Worker, max_attempts: 3 import Ecto.Query @@ -45,7 +46,12 @@ defmodule Transport.Jobs.ImportGBFSFeedContactEmailJob do contact nil -> - %{mailing_list_title: contact_title(resource_url), email: feed_contact_email, creation_source: @contact_source} + %{ + mailing_list_title: contact_title(resource_url), + email: feed_contact_email, + creation_source: @contact_source, + organization: Transport.GBFSMetadata.operator(resource_url) + } |> DB.Contact.insert!() end end diff --git a/apps/transport/test/transport/jobs/import_gbfs_feed_contact_point_job_test.exs b/apps/transport/test/transport/jobs/import_gbfs_feed_contact_point_job_test.exs index 0b4c58115e..25489f5f9d 100644 --- a/apps/transport/test/transport/jobs/import_gbfs_feed_contact_point_job_test.exs +++ b/apps/transport/test/transport/jobs/import_gbfs_feed_contact_point_job_test.exs @@ -143,7 +143,7 @@ defmodule Transport.Test.Transport.Jobs.ImportGBFSFeedContactEmailJobTest do feed_contact_email: email }) - %DB.Contact{email: ^email, creation_source: :"automation:import_gbfs_feed_contact_email"} = + %DB.Contact{email: ^email, creation_source: :"automation:import_gbfs_feed_contact_email", organization: "Example"} = contact = DB.Repo.get_by(DB.Contact, mailing_list_title: "Équipe technique GBFS Example") assert nil == DB.Repo.reload(previous_gbfs_contact_ns) @@ -167,7 +167,7 @@ defmodule Transport.Test.Transport.Jobs.ImportGBFSFeedContactEmailJobTest do ) end) - # Another producer production does not interfere + # Another producer's subscription does not interfere other_ns = insert(:notification_subscription, dataset_id: dataset.id,