a0731f5a47450cbb81caaaecab91be007206fc13
[anni] / test / pleroma / repo / migrations / confirm_logged_in_users_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.ConfirmLoggedInUsersTest do
6   alias Pleroma.Repo
7   alias Pleroma.User
8   use Pleroma.DataCase, async: true
9   import Ecto.Query
10   import Pleroma.Factory
11   import Pleroma.Tests.Helpers
12
13   setup_all do: require_migration("20201231185546_confirm_logged_in_users")
14
15   test "up/0 confirms unconfirmed but previously-logged-in users", %{migration: migration} do
16     insert_list(25, :oauth_token)
17     Repo.update_all(User, set: [is_confirmed: false])
18     insert_list(5, :user, is_confirmed: false)
19
20     count =
21       User
22       |> where(is_confirmed: false)
23       |> Repo.aggregate(:count)
24
25     assert count == 30
26
27     assert {25, nil} == migration.up()
28
29     count =
30       User
31       |> where(is_confirmed: false)
32       |> Repo.aggregate(:count)
33
34     assert count == 5
35   end
36
37   test "down/0 does nothing", %{migration: migration} do
38     assert :noop == migration.down()
39   end
40 end