Skip to content

Commit

Permalink
Fix Oban job and do test it
Browse files Browse the repository at this point in the history
  • Loading branch information
vdegove committed Dec 17, 2024
1 parent 32a3697 commit 8c8d2de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
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

0 comments on commit 8c8d2de

Please sign in to comment.