Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Oban job and do test it
  • Loading branch information
vdegove committed Dec 17, 2024
commit e042c0ff7d663df0276f90ac105d2ea13415baf5
6 changes: 6 additions & 0 deletions apps/transport/lib/jobs/outdated_data_notification_job.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
defmodule Transport.Jobs.OutdatedDataNotificationJob do
@moduledoc """
This module is in charge of sending notifications to both admins and users when data is outdated.
It is (currently) using the old DataChecker module, where there is also code for checking active/inactive datasets.
Behaviour of this job is tested in test/transport/data_checker_test.exs.
"""
use Oban.Worker, max_attempts: 3, tags: ["notifications"]

@impl Oban.Worker

def perform(%Oban.Job{id: job_id}) do
Transport.DataChecker.outdated_data(job_id)
:ok
end
end
4 changes: 3 additions & 1 deletion apps/transport/lib/transport/data_checker.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Transport.DataChecker do
@moduledoc """
Use to check data, and act about it, like send email
Use to check data for two things:
- Toggle in and of active status of datasets depending on status on data.gouv.fr
- Send notifications to producers and admins when data is outdated
"""
alias DB.{Dataset, Repo}
import Ecto.Query
Expand Down
5 changes: 3 additions & 2 deletions apps/transport/test/transport/data_checker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Transport.DataCheckerTest do
import Mox
import DB.Factory
import Swoosh.TestAssertions
use Oban.Testing, repo: DB.Repo

doctest Transport.DataChecker, import: true

Expand Down Expand Up @@ -233,7 +234,7 @@ defmodule Transport.DataCheckerTest do
dataset_id: dataset.id
})

Transport.DataChecker.outdated_data(42)
assert :ok == perform_job(Transport.Jobs.OutdatedDataNotificationJob, %{})

# a first mail to our team

Expand Down Expand Up @@ -271,7 +272,7 @@ defmodule Transport.DataCheckerTest do
end

test "outdated_data job with nothing to send should not send email" do
Transport.DataChecker.outdated_data(42)
assert :ok == perform_job(Transport.Jobs.OutdatedDataNotificationJob, %{})
assert_no_email_sent()
end
end
Expand Down