mirror of
https://github.com/mirego/accent.git
synced 2024-08-16 22:40:36 +03:00
Use factori in tests
This commit is contained in:
parent
857176fdbf
commit
436bc1359e
@ -31,6 +31,11 @@ else
|
||||
debug_errors: get_env("DEBUG_ERRORS", :boolean)
|
||||
end
|
||||
|
||||
if config_env() === :test do
|
||||
config :accent, Accent.Repo,
|
||||
pool_size: System.schedulers_online() * 2,
|
||||
url: get_env("DATABASE_URL")
|
||||
else
|
||||
ecto_ipv6? = get_env("ECTO_IPV6", :boolean)
|
||||
|
||||
config :accent, Accent.Repo,
|
||||
@ -42,6 +47,7 @@ config :accent, Accent.Repo,
|
||||
ssl_opts: [verify: :verify_none],
|
||||
url: get_env("DATABASE_URL") || "postgres://localhost/accent_development",
|
||||
socket_options: if(ecto_ipv6?, do: [:inet6], else: [])
|
||||
end
|
||||
|
||||
config :accent, Accent.MachineTranslations,
|
||||
default_providers_config: %{
|
||||
|
@ -62,7 +62,7 @@ defmodule Accent.GraphQL.Resolvers.Project do
|
||||
"name" => args.name,
|
||||
"main_color" => args.main_color,
|
||||
"logo" => args.logo,
|
||||
"locked_file_operations" => args.is_file_operations_locked
|
||||
"locked_file_operations" => args.is_file_operations_locked || false
|
||||
}
|
||||
|
||||
case ProjectUpdater.update(
|
||||
|
@ -46,7 +46,7 @@ defmodule Accent.GraphQL.Resolvers.Version do
|
||||
|> Version.changeset(%{
|
||||
name: args[:name],
|
||||
tag: args[:tag],
|
||||
copy_on_update_translation: args[:copy_on_update_translation]
|
||||
copy_on_update_translation: args[:copy_on_update_translation] || false
|
||||
})
|
||||
|> Repo.update()
|
||||
|> case do
|
||||
|
@ -56,7 +56,7 @@ defmodule Movement.Migration.Translation do
|
||||
locked: operation.locked,
|
||||
file_index: operation.file_index,
|
||||
file_comment: operation.file_comment,
|
||||
removed: operation.previous_translation && operation.previous_translation.removed,
|
||||
removed: (operation.previous_translation && operation.previous_translation.removed) || false,
|
||||
translated: is_nil(operation.translation_id),
|
||||
revision_id: operation.revision_id,
|
||||
document_id: operation.document_id,
|
||||
@ -82,11 +82,11 @@ defmodule Movement.Migration.Translation do
|
||||
proposed_text: operation.text,
|
||||
corrected_text: operation.text,
|
||||
translated: (operation.previous_translation && operation.previous_translation.translated) || false,
|
||||
conflicted: operation.previous_translation && operation.previous_translation.conflicted,
|
||||
conflicted: (operation.previous_translation && operation.previous_translation.conflicted) || false,
|
||||
value_type: operation.value_type,
|
||||
file_index: operation.file_index,
|
||||
file_comment: operation.file_comment,
|
||||
removed: operation.previous_translation && operation.previous_translation.removed,
|
||||
removed: (operation.previous_translation && operation.previous_translation.removed) || false,
|
||||
revision_id: operation.revision_id,
|
||||
document_id: operation.document_id,
|
||||
version_id: operation.version_id,
|
||||
|
1
mix.exs
1
mix.exs
@ -116,6 +116,7 @@ defmodule Accent.Mixfile do
|
||||
# Mock testing
|
||||
{:mox, "~> 1.0", only: :test},
|
||||
{:mock, "~> 0.3.0", only: :test},
|
||||
{:factori, path: "../mirego/factori", only: :test},
|
||||
|
||||
# Google API authentication
|
||||
{:goth, "~> 1.4"},
|
||||
|
2
mix.lock
2
mix.lock
@ -34,6 +34,8 @@
|
||||
"eternal": {:hex, :eternal, "1.2.2", "d1641c86368de99375b98d183042dd6c2b234262b8d08dfd72b9eeaafc2a1abd", [:mix], [], "hexpm", "2c9fe32b9c3726703ba5e1d43a1d255a4f3f2d8f8f9bc19f094c7cb1a7a9e782"},
|
||||
"excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"},
|
||||
"exile": {:hex, :exile, "0.9.1", "832b6340cf800661e90e52cebc760b795450f803c0e9265ccdc54150423fbb32", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "553a1847b27118c843d3dc6912adbc36d60336811d15ad70a31b82eb5a416328"},
|
||||
"factori": {:hex, :factori, "0.12.0", "55cddfcaa12619a5864bbfe23112d6e852d992ed1c53118606923ba6ed0f97ac", [:make, :mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:faker, "~> 0.16", [hex: :faker, repo: "hexpm", optional: false]}], "hexpm", "bd1456a7c06823160ffb047c4f1f265c330210620aa41d940b952dcde14f87cd"},
|
||||
"faker": {:hex, :faker, "0.18.0", "943e479319a22ea4e8e39e8e076b81c02827d9302f3d32726c5bf82f430e6e14", [:mix], [], "hexpm", "bfbdd83958d78e2788e99ec9317c4816e651ad05e24cfd1196ce5db5b3e81797"},
|
||||
"fast_yaml": {:git, "https://github.com/processone/fast_yaml.git", "e789f68895f71b7ad31057177810ca0161bf790e", [ref: "e789f68895f71b7ad31057177810ca0161bf790e"]},
|
||||
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
|
||||
"finch": {:hex, :finch, "0.17.0", "17d06e1d44d891d20dbd437335eebe844e2426a0cd7e3a3e220b461127c73f70", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8d014a661bb6a437263d4b5abf0bcbd3cf0deb26b1e8596f2a271d22e48934c7"},
|
||||
|
@ -0,0 +1,86 @@
|
||||
defmodule Accent.Repo.Migrations.AddNonNullableChecks do
|
||||
@moduledoc false
|
||||
use Ecto.Migration
|
||||
|
||||
def down do
|
||||
end
|
||||
|
||||
# credo:disable-for-next-line
|
||||
def up do
|
||||
drop(constraint(:documents, :documents_project_id_fkey))
|
||||
|
||||
alter table(:documents) do
|
||||
modify(:path, :string, null: false)
|
||||
modify(:format, :string, null: false)
|
||||
modify(:project_id, references(:projects, type: :uuid), null: false)
|
||||
end
|
||||
|
||||
alter table(:languages) do
|
||||
modify(:name, :string, null: false)
|
||||
modify(:slug, :string, null: false)
|
||||
modify(:iso_639_1, :string, null: false)
|
||||
modify(:iso_639_3, :string, null: false)
|
||||
modify(:locale, :string, null: false)
|
||||
modify(:android_code, :string, null: false)
|
||||
modify(:osx_code, :string, null: false)
|
||||
modify(:osx_locale, :string, null: false)
|
||||
end
|
||||
|
||||
drop(constraint(:auth_access_tokens, :auth_access_tokens_user_id_fkey))
|
||||
|
||||
alter table(:auth_access_tokens) do
|
||||
modify(:token, :string, null: false)
|
||||
modify(:user_id, references(:users, type: :uuid), null: false)
|
||||
end
|
||||
|
||||
drop(constraint(:auth_providers, :auth_providers_user_id_fkey))
|
||||
|
||||
alter table(:auth_providers) do
|
||||
modify(:name, :string, null: false)
|
||||
modify(:uid, :string, null: false)
|
||||
modify(:user_id, references(:users, type: :uuid), null: false)
|
||||
end
|
||||
|
||||
drop(constraint(:collaborators, :collaborators_project_id_fkey))
|
||||
|
||||
alter table(:collaborators) do
|
||||
modify(:role, :string, null: false)
|
||||
modify(:project_id, references(:projects, type: :uuid), null: false)
|
||||
end
|
||||
|
||||
drop(constraint(:comments, :comments_user_id_fkey))
|
||||
|
||||
alter table(:comments) do
|
||||
modify(:text, :text, null: false)
|
||||
modify(:user_id, references(:users, type: :uuid), null: false)
|
||||
end
|
||||
|
||||
alter table(:projects) do
|
||||
modify(:name, :string, null: false)
|
||||
modify(:locked_file_operations, :boolean, null: false, default: false)
|
||||
modify(:sync_lock_version, :integer, null: false, default: 1)
|
||||
end
|
||||
|
||||
drop(constraint(:revisions, :revisions_project_id_fkey))
|
||||
drop(constraint(:revisions, :revisions_language_id_fkey))
|
||||
|
||||
alter table(:revisions) do
|
||||
modify(:project_id, references(:projects, type: :uuid), null: false)
|
||||
modify(:language_id, references(:languages, type: :uuid), null: false)
|
||||
modify(:master, :boolean, null: false, default: true)
|
||||
end
|
||||
|
||||
alter table(:operations) do
|
||||
modify(:rollbacked, :boolean, null: false, default: false)
|
||||
modify(:batch, :boolean, null: false, default: false)
|
||||
modify(:action, :string, null: false)
|
||||
end
|
||||
|
||||
alter table(:translations) do
|
||||
modify(:key, :string, null: false)
|
||||
modify(:removed, :boolean, null: false, default: false)
|
||||
modify(:conflicted, :boolean, null: false, default: false)
|
||||
modify(:comments_count, :integer, null: false, default: 0)
|
||||
end
|
||||
end
|
||||
end
|
@ -25,9 +25,9 @@ defmodule AccentTest.UserRemote.Authenticator do
|
||||
end
|
||||
|
||||
test "normalize collaborators with email" do
|
||||
assigner = Repo.insert!(%User{email: "foo@example.com"})
|
||||
language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project", language_id: language.id})
|
||||
assigner = Factory.insert(User, email: "foo@example.com")
|
||||
language = Factory.insert(Language)
|
||||
project = Factory.insert(Project, language_id: language.id)
|
||||
|
||||
collaborator =
|
||||
Repo.insert!(%Collaborator{
|
||||
@ -45,9 +45,9 @@ defmodule AccentTest.UserRemote.Authenticator do
|
||||
end
|
||||
|
||||
test "normalize collaborators with uppercased email" do
|
||||
assigner = Repo.insert!(%User{email: "foo@example.com"})
|
||||
language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project", language_id: language.id})
|
||||
assigner = Factory.insert(User, email: "foo@example.com")
|
||||
language = Factory.insert(Language)
|
||||
project = Factory.insert(Project, language_id: language.id)
|
||||
|
||||
collaborator =
|
||||
Repo.insert!(%Collaborator{
|
||||
|
@ -18,8 +18,8 @@ defmodule AccentTest.UserRemote.Persister do
|
||||
end
|
||||
|
||||
test "persist with existing user existing provider" do
|
||||
existing_user = Repo.insert!(%User{email: @user.email})
|
||||
Repo.insert!(%AuthProvider{name: @user.provider, uid: @user.uid})
|
||||
existing_user = Factory.insert(User, email: @user.email)
|
||||
Factory.insert(AuthProvider, name: @user.provider, uid: @user.uid)
|
||||
|
||||
user = Persister.persist(@user)
|
||||
|
||||
@ -28,8 +28,8 @@ defmodule AccentTest.UserRemote.Persister do
|
||||
end
|
||||
|
||||
test "persist with existing user new provider" do
|
||||
existing_user = Repo.insert!(%User{email: @user.email})
|
||||
Repo.insert!(%AuthProvider{name: "dummy", uid: @user.email})
|
||||
existing_user = Factory.insert(User, email: @user.email)
|
||||
Factory.insert(AuthProvider, name: "dummy", uid: @user.email)
|
||||
|
||||
user = Persister.persist(@user)
|
||||
|
||||
|
@ -7,15 +7,14 @@ defmodule AccentTest.UserRemote.TokenGiver do
|
||||
alias Accent.User
|
||||
alias Accent.UserRemote.TokenGiver
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
@token %AccessToken{revoked_at: nil, token: "1234"}
|
||||
|
||||
test "revoke existing token" do
|
||||
user = Repo.insert!(@user)
|
||||
user = Factory.insert(User)
|
||||
token = Repo.insert!(Map.put(@token, :user_id, user.id))
|
||||
|
||||
existing_revoked_token =
|
||||
Repo.insert!(%AccessToken{token: "revoked", revoked_at: NaiveDateTime.utc_now(:second), user_id: user.id})
|
||||
Factory.insert(AccessToken, token: "revoked", revoked_at: NaiveDateTime.utc_now(:second), user_id: user.id)
|
||||
|
||||
TokenGiver.grant_token(user)
|
||||
|
||||
@ -27,7 +26,7 @@ defmodule AccentTest.UserRemote.TokenGiver do
|
||||
end
|
||||
|
||||
test "create token" do
|
||||
user = Repo.insert!(@user)
|
||||
user = Factory.insert(User)
|
||||
|
||||
TokenGiver.grant_token(user)
|
||||
|
||||
|
@ -13,41 +13,41 @@ defmodule AccentTest.BadgeGenerator do
|
||||
alias Accent.Translation
|
||||
|
||||
setup do
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project", language_id: french_language.id})
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, master: true, project_id: project.id})
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project, language_id: french_language.id)
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, master: true, project_id: project.id)
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
{:ok, [project: Repo.preload(project, :revisions), revision: revision, document: document]}
|
||||
end
|
||||
|
||||
test "percentage_reviewed error", %{project: project, revision: revision, document: document} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "a",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "b",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "c",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
response = [get: fn _url, _, _ -> {:ok, %{body: "<svg></svg>"}} end]
|
||||
|
||||
@ -59,41 +59,41 @@ defmodule AccentTest.BadgeGenerator do
|
||||
end
|
||||
|
||||
test "percentage_reviewed warning", %{project: project, revision: revision, document: document} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "a",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "b",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "c",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "d",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
response = [get: fn _url, _, _ -> {:ok, %{body: "<svg></svg>"}} end]
|
||||
|
||||
@ -105,41 +105,41 @@ defmodule AccentTest.BadgeGenerator do
|
||||
end
|
||||
|
||||
test "percentage_reviewed success", %{project: project, revision: revision, document: document} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "a",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "b",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "c",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "d",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
response = [get: fn _url, _, _ -> {:ok, %{body: "<svg></svg>"}} end]
|
||||
|
||||
@ -151,41 +151,41 @@ defmodule AccentTest.BadgeGenerator do
|
||||
end
|
||||
|
||||
test "translations_count", %{project: project, revision: revision, document: document} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "a",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "b",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "c",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "d",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
response = [get: fn _url, _, _ -> {:ok, %{body: "<svg></svg>"}} end]
|
||||
|
||||
@ -199,23 +199,23 @@ defmodule AccentTest.BadgeGenerator do
|
||||
end
|
||||
|
||||
test "conflicts_count", %{project: project, revision: revision, document: document} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "c",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "d",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
response = [get: fn _url, _, _ -> {:ok, %{body: "<svg></svg>"}} end]
|
||||
|
||||
@ -229,23 +229,23 @@ defmodule AccentTest.BadgeGenerator do
|
||||
end
|
||||
|
||||
test "reviewed_count", %{project: project, revision: revision, document: document} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "c",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "d",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
response = [get: fn _url, _, _ -> {:ok, %{body: "<svg></svg>"}} end]
|
||||
|
||||
|
@ -15,20 +15,18 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
alias Accent.User
|
||||
alias Accent.Version
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
version = Repo.insert!(%Version{project_id: project.id, name: "test", tag: "v1.0", user_id: user.id})
|
||||
translation = Repo.insert!(%Translation{revision_id: revision.id, key: "test", corrected_text: "bar"})
|
||||
collaborator = Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "owner"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
version = Factory.insert(Version, project_id: project.id, name: "test", tag: "v1.0", user_id: user.id)
|
||||
translation = Factory.insert(Translation, revision_id: revision.id, key: "test", corrected_text: "bar")
|
||||
collaborator = Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "owner")
|
||||
|
||||
integration =
|
||||
Repo.insert!(%Integration{
|
||||
@ -39,7 +37,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
})
|
||||
|
||||
translation_comments_subscription =
|
||||
Repo.insert!(%TranslationCommentsSubscription{translation_id: translation.id, user_id: user.id})
|
||||
Factory.insert(TranslationCommentsSubscription, translation_id: translation.id, user_id: user.id)
|
||||
|
||||
{:ok,
|
||||
[
|
||||
@ -127,7 +125,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
end
|
||||
|
||||
test "unauthorized project root", %{project: project} do
|
||||
user = Repo.insert!(%User{email: "test+2@test.com"})
|
||||
user = Factory.insert(User, email: "test+2@test.com")
|
||||
user = Map.put(user, :permissions, %{})
|
||||
root = project
|
||||
args = %{}
|
||||
@ -178,7 +176,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
end
|
||||
|
||||
test "unauthorized revision root", %{revision: revision} do
|
||||
user = Repo.insert!(%User{email: "test+2@test.com"})
|
||||
user = Factory.insert(User, email: "test+2@test.com")
|
||||
user = Map.put(user, :permissions, %{})
|
||||
root = revision
|
||||
args = %{}
|
||||
@ -229,7 +227,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
end
|
||||
|
||||
test "unauthorized version root", %{version: version} do
|
||||
user = Repo.insert!(%User{email: "test+2@test.com"})
|
||||
user = Factory.insert(User, email: "test+2@test.com")
|
||||
user = Map.put(user, :permissions, %{})
|
||||
root = version
|
||||
args = %{}
|
||||
@ -298,7 +296,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
end
|
||||
|
||||
test "unauthorized translation root", %{translation: translation} do
|
||||
user = Repo.insert!(%User{email: "test+2@test.com"})
|
||||
user = Factory.insert(User, email: "test+2@test.com")
|
||||
user = Map.put(user, :permissions, %{})
|
||||
root = translation
|
||||
args = %{}
|
||||
@ -387,7 +385,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
end
|
||||
|
||||
test "authorized operation revision args", %{user: user, revision: revision, project: project} do
|
||||
operation = Repo.insert!(%Operation{revision_id: revision.id, user_id: user.id, key: "test", text: "bar"})
|
||||
operation = Factory.insert(Operation, revision_id: revision.id, user_id: user.id, key: "test", text: "bar")
|
||||
|
||||
user = Map.put(user, :permissions, %{project.id => "owner"})
|
||||
root = nil
|
||||
@ -401,7 +399,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
end
|
||||
|
||||
test "authorized operation translation args", %{user: user, translation: translation, project: project} do
|
||||
operation = Repo.insert!(%Operation{translation_id: translation.id, user_id: user.id, key: "test", text: "bar"})
|
||||
operation = Factory.insert(Operation, translation_id: translation.id, user_id: user.id, key: "test", text: "bar")
|
||||
|
||||
user = Map.put(user, :permissions, %{project.id => "owner"})
|
||||
root = nil
|
||||
@ -415,7 +413,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
end
|
||||
|
||||
test "authorized operation project args", %{user: user, project: project} do
|
||||
operation = Repo.insert!(%Operation{project_id: project.id, user_id: user.id, key: "test", text: "bar"})
|
||||
operation = Factory.insert(Operation, project_id: project.id, user_id: user.id, key: "test", text: "bar")
|
||||
|
||||
user = Map.put(user, :permissions, %{project.id => "owner"})
|
||||
root = nil
|
||||
@ -429,7 +427,7 @@ defmodule AccentTest.GraphQL.Helpers.Authorization do
|
||||
end
|
||||
|
||||
test "unauthorized operation role", %{user: user, revision: revision, project: project} do
|
||||
operation = Repo.insert!(%Operation{revision_id: revision.id, user_id: user.id, key: "test", text: "bar"})
|
||||
operation = Factory.insert(Operation, revision_id: revision.id, user_id: user.id, key: "test", text: "bar")
|
||||
|
||||
user = Map.put(user, :permissions, %{project.id => "reviewer"})
|
||||
root = nil
|
||||
|
@ -8,10 +8,8 @@ defmodule AccentTest.GraphQL.Requests.ProjectIntegrations do
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
user = Factory.insert(User)
|
||||
|
||||
project =
|
||||
Repo.insert!(%Project{
|
||||
@ -22,7 +20,7 @@ defmodule AccentTest.GraphQL.Requests.ProjectIntegrations do
|
||||
|
||||
user = %{user | permissions: %{project.id => "admin"}}
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
|
||||
create_mutation = """
|
||||
mutation IntegrationCreate(
|
||||
|
@ -9,11 +9,9 @@ defmodule AccentTest.GraphQL.Requests.ProjectRevisions do
|
||||
alias Accent.Revision
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
|
||||
project =
|
||||
Repo.insert!(%Project{
|
||||
@ -24,7 +22,7 @@ defmodule AccentTest.GraphQL.Requests.ProjectRevisions do
|
||||
|
||||
user = %{user | permissions: %{project.id => "admin"}}
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
|
||||
revision =
|
||||
Repo.insert!(%Revision{
|
||||
|
@ -10,11 +10,9 @@ defmodule AccentTest.GraphQL.Requests.Projects do
|
||||
alias Accent.Translation
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
|
||||
project =
|
||||
Repo.insert!(%Project{
|
||||
@ -23,16 +21,16 @@ defmodule AccentTest.GraphQL.Requests.Projects do
|
||||
last_synced_at: DateTime.from_naive!(~N[2017-01-01T00:00:00], "Etc/UTC")
|
||||
})
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
{:ok, [user: user, project: project, language: french_language, revision: revision]}
|
||||
end
|
||||
|
||||
test "list projects", %{user: user, project: project, revision: revision} do
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "A", conflicted: true})
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "B", conflicted: true})
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "C", conflicted: false})
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "A", conflicted: true)
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "B", conflicted: true)
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "C", conflicted: false)
|
||||
|
||||
{:ok, data} =
|
||||
Absinthe.run(
|
||||
|
@ -18,23 +18,21 @@ defmodule AccentTest.GraphQL.Resolvers.Activity do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision = Repo.insert!(%Revision{language_id: language.id, project_id: project.id, master: true})
|
||||
revision = Factory.insert(Revision, language_id: language.id, project_id: project.id, master: true)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar"})
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar")
|
||||
|
||||
{:ok, [user: user, project: project, revision: revision, translation: translation]}
|
||||
end
|
||||
|
||||
test "list activities", %{user: user, project: project, translation: translation, revision: revision} do
|
||||
operation = Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
operation = Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
|
||||
Repo.insert!(%Operation{
|
||||
user_id: user.id,
|
||||
@ -66,7 +64,7 @@ defmodule AccentTest.GraphQL.Resolvers.Activity do
|
||||
action: "update"
|
||||
})
|
||||
|
||||
Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
{:ok, %{entries: entries, meta: meta}} = Resolver.list_project(project, %{}, %{})
|
||||
|
||||
assert Enum.count(entries) == 2
|
||||
@ -79,7 +77,7 @@ defmodule AccentTest.GraphQL.Resolvers.Activity do
|
||||
|
||||
test "list project paginated", %{user: user, project: project} do
|
||||
for _index <- 1..100 do
|
||||
Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
end
|
||||
|
||||
{:ok, %{entries: entries, meta: meta}} = Resolver.list_project(project, %{page: 3}, %{})
|
||||
@ -93,25 +91,25 @@ defmodule AccentTest.GraphQL.Resolvers.Activity do
|
||||
end
|
||||
|
||||
test "list project from user", %{user: user, project: project} do
|
||||
other_user = Repo.insert!(%User{email: "foo@bar.com"})
|
||||
Repo.insert!(%Operation{user_id: other_user.id, project_id: project.id, action: "sync"})
|
||||
Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
other_user = Factory.insert(User, email: "foo@bar.com")
|
||||
Factory.insert(Operation, user_id: other_user.id, project_id: project.id, action: "sync")
|
||||
Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
{:ok, %{entries: entries}} = Resolver.list_project(project, %{user_id: other_user.id}, %{})
|
||||
|
||||
assert Enum.count(entries) == 1
|
||||
end
|
||||
|
||||
test "list project from batch", %{user: user, project: project} do
|
||||
Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync", batch: true})
|
||||
Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync", batch: true)
|
||||
Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
{:ok, %{entries: entries}} = Resolver.list_project(project, %{is_batch: true}, %{})
|
||||
|
||||
assert Enum.count(entries) == 1
|
||||
end
|
||||
|
||||
test "list project from action", %{user: user, project: project} do
|
||||
Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "delete_document"})
|
||||
Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "delete_document")
|
||||
Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
{:ok, %{entries: entries}} = Resolver.list_project(project, %{action: "sync"}, %{})
|
||||
|
||||
assert Enum.count(entries) == 1
|
||||
@ -127,7 +125,7 @@ defmodule AccentTest.GraphQL.Resolvers.Activity do
|
||||
action: "update"
|
||||
})
|
||||
|
||||
Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
{:ok, %{entries: entries, meta: meta}} = Resolver.list_translation(translation, %{}, %{})
|
||||
|
||||
assert Enum.count(entries) == 1
|
||||
@ -139,32 +137,32 @@ defmodule AccentTest.GraphQL.Resolvers.Activity do
|
||||
end
|
||||
|
||||
test "list translation from user", %{user: user, translation: translation} do
|
||||
other_user = Repo.insert!(%User{email: "foo@bar.com"})
|
||||
Repo.insert!(%Operation{user_id: other_user.id, translation_id: translation.id, action: "update"})
|
||||
Repo.insert!(%Operation{user_id: user.id, translation_id: translation.id, action: "update"})
|
||||
other_user = Factory.insert(User, email: "foo@bar.com")
|
||||
Factory.insert(Operation, user_id: other_user.id, translation_id: translation.id, action: "update")
|
||||
Factory.insert(Operation, user_id: user.id, translation_id: translation.id, action: "update")
|
||||
{:ok, %{entries: entries}} = Resolver.list_translation(translation, %{user_id: other_user.id}, %{})
|
||||
|
||||
assert Enum.count(entries) == 1
|
||||
end
|
||||
|
||||
test "list translation from batch", %{user: user, translation: translation} do
|
||||
Repo.insert!(%Operation{user_id: user.id, translation_id: translation.id, action: "sync", batch: true})
|
||||
Repo.insert!(%Operation{user_id: user.id, translation_id: translation.id, action: "update"})
|
||||
Factory.insert(Operation, user_id: user.id, translation_id: translation.id, action: "sync", batch: true)
|
||||
Factory.insert(Operation, user_id: user.id, translation_id: translation.id, action: "update")
|
||||
{:ok, %{entries: entries}} = Resolver.list_translation(translation, %{is_batch: true}, %{})
|
||||
|
||||
assert Enum.count(entries) == 1
|
||||
end
|
||||
|
||||
test "list translation from action", %{user: user, translation: translation} do
|
||||
Repo.insert!(%Operation{user_id: user.id, translation_id: translation.id, action: "delete_document"})
|
||||
Repo.insert!(%Operation{user_id: user.id, translation_id: translation.id, action: "update"})
|
||||
Factory.insert(Operation, user_id: user.id, translation_id: translation.id, action: "delete_document")
|
||||
Factory.insert(Operation, user_id: user.id, translation_id: translation.id, action: "update")
|
||||
{:ok, %{entries: entries}} = Resolver.list_translation(translation, %{action: "update"}, %{})
|
||||
|
||||
assert Enum.count(entries) == 1
|
||||
end
|
||||
|
||||
test "show project", %{user: user, project: project} do
|
||||
operation = Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
operation = Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
|
||||
{:ok, %{id: id}} = Resolver.show_project(project, %{id: operation.id}, %{})
|
||||
|
||||
|
@ -13,11 +13,9 @@ defmodule AccentTest.GraphQL.Resolvers.Collaborator do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
{:ok, [user: user, project: project]}
|
||||
end
|
||||
@ -44,7 +42,7 @@ defmodule AccentTest.GraphQL.Resolvers.Collaborator do
|
||||
|
||||
test "update", %{project: project, user: user} do
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
collaborator = Repo.insert!(%Collaborator{email: "test@example.com", role: "reviewer", project_id: project.id})
|
||||
collaborator = Factory.insert(Collaborator, email: "test@example.com", role: "reviewer", project_id: project.id)
|
||||
|
||||
{:ok, result} = Resolver.update(collaborator, %{role: "owner"}, context)
|
||||
|
||||
@ -54,7 +52,7 @@ defmodule AccentTest.GraphQL.Resolvers.Collaborator do
|
||||
|
||||
test "delete", %{project: project, user: user} do
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
collaborator = Repo.insert!(%Collaborator{email: "test@example.com", role: "reviewer", project_id: project.id})
|
||||
collaborator = Factory.insert(Collaborator, email: "test@example.com", role: "reviewer", project_id: project.id)
|
||||
|
||||
{:ok, result} = Resolver.delete(collaborator, %{}, context)
|
||||
|
||||
|
@ -16,17 +16,15 @@ defmodule AccentTest.GraphQL.Resolvers.Comment do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar"})
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar")
|
||||
|
||||
{:ok, [user: user, project: project, translation: translation]}
|
||||
end
|
||||
@ -55,7 +53,7 @@ defmodule AccentTest.GraphQL.Resolvers.Comment do
|
||||
end
|
||||
|
||||
test "delete", %{translation: translation, user: user} do
|
||||
comment = Repo.insert!(%Comment{translation_id: translation.id, text: "test", user: user})
|
||||
comment = Factory.insert(Comment, translation_id: translation.id, text: "test", user: user)
|
||||
|
||||
assert get_in(Repo.all(Comment), [Access.all(), Access.key(:id)]) == [comment.id]
|
||||
|
||||
@ -66,7 +64,7 @@ defmodule AccentTest.GraphQL.Resolvers.Comment do
|
||||
end
|
||||
|
||||
test "update", %{translation: translation, user: user} do
|
||||
comment = Repo.insert!(%Comment{translation_id: translation.id, text: "test", user: user})
|
||||
comment = Factory.insert(Comment, translation_id: translation.id, text: "test", user: user)
|
||||
|
||||
assert get_in(Repo.all(Comment), [Access.all(), Access.key(:id)]) == [comment.id]
|
||||
|
||||
@ -77,7 +75,7 @@ defmodule AccentTest.GraphQL.Resolvers.Comment do
|
||||
end
|
||||
|
||||
test "list project", %{project: project, translation: translation, user: user} do
|
||||
comment = Repo.insert!(%Comment{translation_id: translation.id, text: "test", user: user})
|
||||
comment = Factory.insert(Comment, translation_id: translation.id, text: "test", user: user)
|
||||
|
||||
{:ok, result} = Resolver.list_project(project, %{}, %{})
|
||||
|
||||
@ -85,7 +83,7 @@ defmodule AccentTest.GraphQL.Resolvers.Comment do
|
||||
end
|
||||
|
||||
test "list translation", %{translation: translation, user: user} do
|
||||
comment = Repo.insert!(%Comment{translation_id: translation.id, text: "test", user: user})
|
||||
comment = Factory.insert(Comment, translation_id: translation.id, text: "test", user: user)
|
||||
|
||||
{:ok, result} = Resolver.list_translation(translation, %{}, %{})
|
||||
|
||||
|
@ -16,14 +16,12 @@ defmodule AccentTest.GraphQL.Resolvers.Document do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
document =
|
||||
Repo.insert!(%Document{
|
||||
@ -37,13 +35,13 @@ defmodule AccentTest.GraphQL.Resolvers.Document do
|
||||
end
|
||||
|
||||
test "delete", %{document: document, revision: revision, user: user} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
document_id: document.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
{:ok, result} = Resolver.delete(document, %{}, context)
|
||||
@ -87,14 +85,14 @@ defmodule AccentTest.GraphQL.Resolvers.Document do
|
||||
end
|
||||
|
||||
test "show project", %{document: document, project: project, revision: revision} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
document_id: document.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
conflicted: false
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.show_project(project, %{id: document.id}, %{})
|
||||
|
||||
@ -113,25 +111,25 @@ defmodule AccentTest.GraphQL.Resolvers.Document do
|
||||
updated_at: DateTime.add(document.updated_at, 3600, :second)
|
||||
})
|
||||
|
||||
_empty_document = Repo.insert!(%Document{project_id: project.id, path: "test3", format: "json"})
|
||||
_empty_document = Factory.insert(Document, project_id: project.id, path: "test3", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
document_id: document.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
conflicted: false
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
document_id: other_document.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
conflicted: true
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.list_project(project, %{exclude_empty_translations: true}, %{})
|
||||
|
||||
@ -142,17 +140,17 @@ defmodule AccentTest.GraphQL.Resolvers.Document do
|
||||
end
|
||||
|
||||
test "list project with many deleted documents", %{document: document, project: project, revision: revision} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
document_id: document.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
conflicted: false
|
||||
})
|
||||
)
|
||||
|
||||
for i <- 1..80 do
|
||||
Repo.insert!(%Document{project_id: project.id, path: "doc-#{i}", format: "json"})
|
||||
Factory.insert(Document, project_id: project.id, path: "doc-#{i}", format: "json")
|
||||
end
|
||||
|
||||
{:ok, result} = Resolver.list_project(project, %{exclude_empty_translations: true}, %{})
|
||||
|
@ -13,11 +13,9 @@ defmodule AccentTest.GraphQL.Resolvers.Integration do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
{:ok, [user: user, project: project]}
|
||||
end
|
||||
|
@ -7,7 +7,6 @@ defmodule AccentTest.GraphQL.Resolvers.Lint do
|
||||
alias Accent.Lint.Message
|
||||
alias Accent.Lint.Replacement
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
alias Accent.Translation
|
||||
alias Accent.User
|
||||
@ -17,15 +16,13 @@ defmodule AccentTest.GraphQL.Resolvers.Lint do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision =
|
||||
Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true, slug: "fr"})
|
||||
Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true, slug: "fr")
|
||||
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
|
||||
@ -34,23 +31,23 @@ defmodule AccentTest.GraphQL.Resolvers.Lint do
|
||||
|
||||
test "lint", %{revision: revision, context: context} do
|
||||
master_translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision: revision,
|
||||
conflicted: false,
|
||||
key: "ok2",
|
||||
corrected_text: "bar foo",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision: revision,
|
||||
master_translation: master_translation,
|
||||
conflicted: false,
|
||||
key: "ok",
|
||||
corrected_text: " bar foo",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.lint_batched_translation(translation, %{}, context)
|
||||
|
||||
|
@ -12,14 +12,12 @@ defmodule AccentTest.GraphQL.Resolvers.Operation do
|
||||
alias Accent.Translation
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
context = %{context: %{conn: %Plug.Conn{assigns: %{current_user: user}}}}
|
||||
|
||||
{:ok, [user: user, project: project, revision: revision, context: context]}
|
||||
@ -27,13 +25,13 @@ defmodule AccentTest.GraphQL.Resolvers.Operation do
|
||||
|
||||
test "rollback", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "baz",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
previous_translation = %PreviousTranslation{
|
||||
conflicted: false,
|
||||
|
@ -4,7 +4,6 @@ defmodule AccentTest.GraphQL.Resolvers.Permission do
|
||||
|
||||
alias Accent.GraphQL.Resolvers.Permission, as: Resolver
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
|
||||
defmodule PlugConn do
|
||||
@ -12,11 +11,9 @@ defmodule AccentTest.GraphQL.Resolvers.Permission do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
{:ok, [user: user, project: project]}
|
||||
end
|
||||
|
@ -17,11 +17,9 @@ defmodule AccentTest.GraphQL.Resolvers.Project do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
@ -37,7 +35,7 @@ defmodule AccentTest.GraphQL.Resolvers.Project do
|
||||
end
|
||||
|
||||
test "list viewer", %{user: user, project: project} do
|
||||
Repo.insert!(%Project{main_color: "#f00", name: "Other project"})
|
||||
Factory.insert(Project, main_color: "#f00", name: "Other project")
|
||||
|
||||
{:ok, result} = Resolver.list_viewer(user, %{}, %{})
|
||||
|
||||
@ -50,7 +48,7 @@ defmodule AccentTest.GraphQL.Resolvers.Project do
|
||||
end
|
||||
|
||||
test "list viewer search", %{user: user, language: language} do
|
||||
Repo.insert!(%Project{main_color: "#f00", name: "Other project"})
|
||||
Factory.insert(Project, main_color: "#f00", name: "Other project")
|
||||
|
||||
{:ok, project_two} =
|
||||
ProjectCreator.create(
|
||||
@ -113,7 +111,7 @@ defmodule AccentTest.GraphQL.Resolvers.Project do
|
||||
end
|
||||
|
||||
test "list viewer ordering", %{user: user, language: language, project: project_one} do
|
||||
Repo.insert!(%Project{main_color: "#f00", name: "Other project"})
|
||||
Factory.insert(Project, main_color: "#f00", name: "Other project")
|
||||
|
||||
{:ok, project_two} =
|
||||
ProjectCreator.create(
|
||||
@ -203,7 +201,7 @@ defmodule AccentTest.GraphQL.Resolvers.Project do
|
||||
|
||||
test "get latest activity", %{user: user, project: project} do
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
operation = Repo.insert!(%Operation{user_id: user.id, project_id: project.id, action: "sync"})
|
||||
operation = Factory.insert(Operation, user_id: user.id, project_id: project.id, action: "sync")
|
||||
|
||||
{:ok, latest_activity} = Resolver.last_activity(project, %{}, context)
|
||||
|
||||
@ -212,7 +210,7 @@ defmodule AccentTest.GraphQL.Resolvers.Project do
|
||||
|
||||
test "lint_translations", %{user: user, project: project} do
|
||||
[revision] = project.revisions
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "a", proposed_text: " A", corrected_text: " A"})
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "a", proposed_text: " A", corrected_text: " A")
|
||||
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
|
||||
@ -229,16 +227,16 @@ defmodule AccentTest.GraphQL.Resolvers.Project do
|
||||
|
||||
test "lint_translations on current version only", %{user: user, project: project} do
|
||||
[revision] = project.revisions
|
||||
version = Repo.insert!(%Version{project_id: project.id, name: "foo", tag: "bar", user_id: user.id})
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "a", proposed_text: " A", corrected_text: " A"})
|
||||
version = Factory.insert(Version, project_id: project.id, name: "foo", tag: "bar", user_id: user.id)
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "a", proposed_text: " A", corrected_text: " A")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
version_id: version.id,
|
||||
revision_id: revision.id,
|
||||
key: "b",
|
||||
proposed_text: " B",
|
||||
corrected_text: " B"
|
||||
})
|
||||
)
|
||||
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
|
||||
|
@ -15,15 +15,13 @@ defmodule AccentTest.GraphQL.Resolvers.Revision do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
english_language = Repo.insert!(%Language{name: "english"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
english_language = Factory.insert(Language, name: "english")
|
||||
project = Factory.insert(Project)
|
||||
|
||||
master_revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
master_revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
slave_revision =
|
||||
Repo.insert!(%Revision{
|
||||
@ -50,7 +48,7 @@ defmodule AccentTest.GraphQL.Resolvers.Revision do
|
||||
|
||||
test "create", %{project: project, user: user} do
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
language = Repo.insert!(%Language{name: "spanish"})
|
||||
language = Factory.insert(Language, name: "spanish")
|
||||
|
||||
{:ok, result} = Resolver.create(project, %{language_id: language.id}, context)
|
||||
|
||||
@ -75,13 +73,13 @@ defmodule AccentTest.GraphQL.Resolvers.Revision do
|
||||
test "correct all", %{master_revision: revision, user: user} do
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
conflicted: true
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.correct_all(revision, %{}, context)
|
||||
|
||||
@ -93,13 +91,13 @@ defmodule AccentTest.GraphQL.Resolvers.Revision do
|
||||
test "uncorrect all", %{master_revision: revision, user: user} do
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
conflicted: false
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.uncorrect_all(revision, %{}, context)
|
||||
|
||||
|
@ -20,21 +20,19 @@ defmodule AccentTest.GraphQL.Resolvers.TranslationCommentSubscription do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
{:ok, [user: user, project: project, revision: revision]}
|
||||
end
|
||||
|
||||
test "create", %{user: user, revision: revision} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar"})
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar")
|
||||
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
|
||||
@ -46,10 +44,10 @@ defmodule AccentTest.GraphQL.Resolvers.TranslationCommentSubscription do
|
||||
|
||||
test "delete", %{user: user, revision: revision} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar"})
|
||||
Factory.insert(Translation, revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar")
|
||||
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
subscription = Repo.insert!(%TranslationCommentsSubscription{user_id: user.id, translation_id: translation.id})
|
||||
subscription = Factory.insert(TranslationCommentsSubscription, user_id: user.id, translation_id: translation.id)
|
||||
|
||||
{:ok, result} = Resolver.delete(subscription, %{}, context)
|
||||
|
||||
|
@ -17,14 +17,12 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
context = %{context: %{conn: %PlugConn{assigns: %{current_user: user}}}}
|
||||
|
||||
{:ok, [user: user, project: project, revision: revision, context: context]}
|
||||
@ -42,13 +40,13 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "correct", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.correct(translation, %{text: "Corrected text"}, context)
|
||||
|
||||
@ -60,13 +58,13 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "uncorrect", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: false,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.uncorrect(translation, %{text: "baz"}, context)
|
||||
|
||||
@ -79,13 +77,13 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "update", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.update(translation, %{text: "Updated text"}, context)
|
||||
|
||||
@ -97,13 +95,13 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "show project", %{project: project, revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.show_project(project, %{id: translation.id}, context)
|
||||
|
||||
@ -118,13 +116,13 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "show project unknown project", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.show_project(%Project{id: Ecto.UUID.generate()}, %{id: translation.id}, context)
|
||||
|
||||
@ -133,22 +131,22 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "list revision", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "hidden",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
locked: true
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.list_revision(revision, %{}, context)
|
||||
|
||||
@ -157,21 +155,21 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "list revision with query", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "aux",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.list_revision(revision, %{query: "bar"}, context)
|
||||
|
||||
@ -179,27 +177,27 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
end
|
||||
|
||||
test "list revision with document", %{project: project, revision: revision, context: context} do
|
||||
document = Repo.insert!(%Document{path: "bar", format: "json", project_id: project.id})
|
||||
other_document = Repo.insert!(%Document{path: "foo", format: "json", project_id: project.id})
|
||||
document = Factory.insert(Document, path: "bar", format: "json", project_id: project.id)
|
||||
other_document = Factory.insert(Document, path: "foo", format: "json", project_id: project.id)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: other_document.id
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.list_revision(revision, %{document: document.id}, context)
|
||||
|
||||
@ -208,22 +206,22 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "list revision with order", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "aaaaaa",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
other_translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "bbbbb",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.list_revision(revision, %{order: "-key"}, context)
|
||||
|
||||
@ -232,21 +230,21 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
|
||||
test "list revision with conflicted", %{revision: revision, context: context} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: false,
|
||||
key: "bar",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "foo",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.list_revision(revision, %{is_conflicted: false}, context)
|
||||
|
||||
@ -254,27 +252,27 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
end
|
||||
|
||||
test "list revision with version", %{project: project, revision: revision, user: user, context: context} do
|
||||
version = Repo.insert!(%Version{name: "bar", tag: "v1.0", project_id: project.id, user_id: user.id})
|
||||
other_version = Repo.insert!(%Version{name: "foo", tag: "v2.0", project_id: project.id, user_id: user.id})
|
||||
version = Factory.insert(Version, name: "bar", tag: "v1.0", project_id: project.id, user_id: user.id)
|
||||
other_version = Factory.insert(Version, name: "foo", tag: "v2.0", project_id: project.id, user_id: user.id)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
version_id: version.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
version_id: other_version.id
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.list_revision(revision, %{version: version.id}, context)
|
||||
|
||||
@ -282,33 +280,33 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
end
|
||||
|
||||
test "related translations", %{project: project, revision: revision, context: context} do
|
||||
english_language = Repo.insert!(%Language{name: "english"})
|
||||
english_language = Factory.insert(Language, name: "english")
|
||||
|
||||
other_revision =
|
||||
Repo.insert!(%Revision{
|
||||
Factory.insert(Revision,
|
||||
language_id: english_language.id,
|
||||
project_id: project.id,
|
||||
master: false,
|
||||
master_revision_id: revision.id
|
||||
})
|
||||
)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
other_translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: other_revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.related_translations(translation, %{}, context)
|
||||
|
||||
@ -316,33 +314,33 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
end
|
||||
|
||||
test "master translation", %{project: project, revision: revision, context: context} do
|
||||
english_language = Repo.insert!(%Language{name: "english"})
|
||||
english_language = Factory.insert(Language, name: "english")
|
||||
|
||||
other_revision =
|
||||
Repo.insert!(%Revision{
|
||||
Factory.insert(Revision,
|
||||
language_id: english_language.id,
|
||||
project_id: project.id,
|
||||
master: false,
|
||||
master_revision_id: revision.id
|
||||
})
|
||||
)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
other_translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: other_revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.master_translation(other_translation, %{}, context)
|
||||
|
||||
@ -350,32 +348,32 @@ defmodule AccentTest.GraphQL.Resolvers.Translation do
|
||||
end
|
||||
|
||||
test "master translation as master", %{project: project, revision: revision, context: context} do
|
||||
english_language = Repo.insert!(%Language{name: "english"})
|
||||
english_language = Factory.insert(Language, name: "english")
|
||||
|
||||
other_revision =
|
||||
Repo.insert!(%Revision{
|
||||
Factory.insert(Revision,
|
||||
language_id: english_language.id,
|
||||
project_id: project.id,
|
||||
master: false,
|
||||
master_revision_id: revision.id
|
||||
})
|
||||
)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar"
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: other_revision.id,
|
||||
conflicted: true,
|
||||
key: "ok",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo"
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, result} = Resolver.master_translation(translation, %{}, context)
|
||||
|
||||
|
@ -4,7 +4,6 @@ defmodule AccentTest.GraphQL.Resolvers.Version do
|
||||
|
||||
alias Accent.GraphQL.Resolvers.Version, as: Resolver
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
alias Accent.Version
|
||||
|
||||
@ -13,13 +12,11 @@ defmodule AccentTest.GraphQL.Resolvers.Version do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
version = Repo.insert!(%Version{name: "version1", tag: "v1", project_id: project.id, user_id: user.id})
|
||||
version = Factory.insert(Version, name: "version1", tag: "v1", project_id: project.id, user_id: user.id)
|
||||
|
||||
{:ok, [user: user, project: project, version: version]}
|
||||
end
|
||||
|
@ -5,7 +5,6 @@ defmodule AccentTest.GraphQL.Resolvers.Viewer do
|
||||
alias Accent.GraphQL.Resolvers.Viewer, as: Resolver
|
||||
alias Accent.Language
|
||||
alias Accent.ProjectCreator
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
|
||||
defmodule PlugConn do
|
||||
@ -13,11 +12,9 @@ defmodule AccentTest.GraphQL.Resolvers.Viewer do
|
||||
defstruct [:assigns]
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
@ -4,12 +4,11 @@ defmodule AccentTest.Hook do
|
||||
|
||||
alias Accent.Hook
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
|
||||
setup do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "Test"})
|
||||
user = Repo.insert!(%User{fullname: "Test", email: "foo@test.com"})
|
||||
project = Factory.insert(Project, main_color: "#f00", name: "Test")
|
||||
user = Factory.insert(User, fullname: "Test", email: "foo@test.com")
|
||||
payload = %{test: "hook"}
|
||||
context = %Hook.Context{project_id: project.id, user_id: user.id, event: "event", payload: payload}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule AccentTest.Hook.Outbounds.Discord do
|
||||
@moduledoc false
|
||||
use Accent.RepoCase, async: true
|
||||
use Accent.RepoCase, async: false
|
||||
|
||||
import Mock
|
||||
|
||||
@ -11,8 +11,8 @@ defmodule AccentTest.Hook.Outbounds.Discord do
|
||||
alias Accent.User
|
||||
|
||||
setup do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "Test"})
|
||||
user = Repo.insert!(%User{fullname: "Test", email: "foo@test.com"})
|
||||
project = Factory.insert(Project, main_color: "#f00", name: "Test")
|
||||
user = Factory.insert(User, fullname: "Test", email: "foo@test.com")
|
||||
|
||||
Repo.insert!(%Integration{
|
||||
project: project,
|
||||
|
@ -17,20 +17,20 @@ defmodule AccentTest.Hook.Outbounds.Email do
|
||||
alias Accent.User
|
||||
|
||||
setup do
|
||||
language = Repo.insert!(%Language{name: "Test"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "Test"})
|
||||
user = Repo.insert!(%User{fullname: "Test", email: "foo@test.com"})
|
||||
revision = Repo.insert!(%Revision{project_id: project.id, language_id: language.id, master: true})
|
||||
language = Factory.insert(Language, name: "Test")
|
||||
project = Factory.insert(Project, main_color: "#f00", name: "Test")
|
||||
user = Factory.insert(User, fullname: "Test", email: "foo@test.com")
|
||||
revision = Factory.insert(Revision, project_id: project.id, language_id: language.id, master: true)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "foo", corrected_text: "bar", proposed_text: "bar", revision_id: revision.id})
|
||||
Factory.insert(Translation, key: "foo", corrected_text: "bar", proposed_text: "bar", revision_id: revision.id)
|
||||
|
||||
[project: project, translation: translation, user: user]
|
||||
end
|
||||
|
||||
test "commenter subscribed", %{project: project, translation: translation, user: user} do
|
||||
Repo.insert!(%TranslationCommentsSubscription{translation_id: translation.id, user_id: user.id})
|
||||
comment = Repo.insert!(%Comment{translation_id: translation.id, user_id: user.id, text: "This is a comment"})
|
||||
Factory.insert(TranslationCommentsSubscription, translation_id: translation.id, user_id: user.id)
|
||||
comment = Factory.insert(Comment, translation_id: translation.id, user_id: user.id, text: "This is a comment")
|
||||
comment = Repo.preload(comment, [:user, translation: [revision: :project]])
|
||||
|
||||
payload = %{
|
||||
@ -52,9 +52,9 @@ defmodule AccentTest.Hook.Outbounds.Email do
|
||||
end
|
||||
|
||||
test "comment", %{project: project, translation: translation, user: user} do
|
||||
Repo.insert!(%TranslationCommentsSubscription{translation_id: translation.id, user_id: user.id})
|
||||
commenter = Repo.insert!(%User{fullname: "Commenter", email: "comment@test.com"})
|
||||
comment = Repo.insert!(%Comment{translation_id: translation.id, user_id: commenter.id, text: "This is a comment"})
|
||||
Factory.insert(TranslationCommentsSubscription, translation_id: translation.id, user_id: user.id)
|
||||
commenter = Factory.insert(User, fullname: "Commenter", email: "comment@test.com")
|
||||
comment = Factory.insert(Comment, translation_id: translation.id, user_id: commenter.id, text: "This is a comment")
|
||||
|
||||
payload = %{
|
||||
"text" => comment.text,
|
||||
@ -75,7 +75,7 @@ defmodule AccentTest.Hook.Outbounds.Email do
|
||||
end
|
||||
|
||||
test "collaborator", %{project: project, user: user} do
|
||||
collaborator = Repo.insert!(%Collaborator{email: "collab@test.com", project_id: project.id})
|
||||
collaborator = Factory.insert(Collaborator, email: "collab@test.com", project_id: project.id)
|
||||
|
||||
payload = %{
|
||||
"collaborator" => %{
|
||||
|
@ -7,7 +7,7 @@ end
|
||||
|
||||
defmodule AccentTest.Hook.Outbounds.Slack do
|
||||
@moduledoc false
|
||||
use Accent.RepoCase, async: true
|
||||
use Accent.RepoCase, async: false
|
||||
|
||||
import Mock
|
||||
|
||||
@ -18,8 +18,8 @@ defmodule AccentTest.Hook.Outbounds.Slack do
|
||||
alias Accent.User
|
||||
|
||||
setup do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "Test"})
|
||||
user = Repo.insert!(%User{fullname: "Test", email: "foo@test.com"})
|
||||
project = Factory.insert(Project, main_color: "#f00", name: "Test")
|
||||
user = Factory.insert(User, fullname: "Test", email: "foo@test.com")
|
||||
|
||||
Repo.insert!(%Integration{
|
||||
project: project,
|
||||
|
@ -15,13 +15,13 @@ defmodule AccentTest.Hook.Outbounds.Websocket do
|
||||
alias Accent.UserSocket
|
||||
|
||||
setup do
|
||||
language = Repo.insert!(%Language{name: "Test"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "Test"})
|
||||
user = Repo.insert!(%User{fullname: "Test", email: "foo@test.com", permissions: %{project.id => "admin"}})
|
||||
revision = Repo.insert!(%Revision{project_id: project.id, language_id: language.id, master: true})
|
||||
language = Factory.insert(Language, name: "Test")
|
||||
project = Factory.insert(Project, main_color: "#f00", name: "Test")
|
||||
user = Factory.insert(User, fullname: "Test", email: "foo@test.com", permissions: %{project.id => "admin"})
|
||||
revision = Factory.insert(Revision, project_id: project.id, language_id: language.id, master: true)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "foo", corrected_text: "bar", proposed_text: "bar", revision_id: revision.id})
|
||||
Factory.insert(Translation, key: "foo", corrected_text: "bar", proposed_text: "bar", revision_id: revision.id)
|
||||
|
||||
{:ok, _, socket} =
|
||||
UserSocket
|
||||
@ -32,8 +32,8 @@ defmodule AccentTest.Hook.Outbounds.Websocket do
|
||||
end
|
||||
|
||||
test "comment", %{project: project, translation: translation, user: user} do
|
||||
commenter = Repo.insert!(%User{fullname: "Commenter", email: "comment@test.com"})
|
||||
comment = Repo.insert!(%Comment{translation_id: translation.id, user_id: commenter.id, text: "This is a comment"})
|
||||
commenter = Factory.insert(User, fullname: "Commenter", email: "comment@test.com")
|
||||
comment = Factory.insert(Comment, translation_id: translation.id, user_id: commenter.id, text: "This is a comment")
|
||||
comment = Repo.preload(comment, [:user, translation: [revision: :project]])
|
||||
|
||||
payload = %{
|
||||
@ -91,7 +91,7 @@ defmodule AccentTest.Hook.Outbounds.Websocket do
|
||||
end
|
||||
|
||||
test "collaborator", %{project: project, user: user} do
|
||||
collaborator = Repo.insert!(%Collaborator{email: "collab@test.com", project_id: project.id})
|
||||
collaborator = Factory.insert(Collaborator, email: "collab@test.com", project_id: project.id)
|
||||
|
||||
payload = %{
|
||||
"collaborator" => %{
|
||||
|
@ -12,24 +12,22 @@ defmodule AccentTest.Movement.Builders.NewSlave do
|
||||
alias Movement.Builders.NewSlave, as: NewSlaveBuilder
|
||||
alias Movement.Context
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [revision: revision, document: document, project: project]}
|
||||
end
|
||||
|
||||
test "builder fetch translations and process operations", %{revision: revision, project: project, document: document} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
@ -37,7 +35,7 @@ defmodule AccentTest.Movement.Builders.NewSlave do
|
||||
file_comment: "comment",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
context =
|
||||
%Context{}
|
||||
@ -70,7 +68,7 @@ defmodule AccentTest.Movement.Builders.NewSlave do
|
||||
document: document
|
||||
} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
@ -78,7 +76,7 @@ defmodule AccentTest.Movement.Builders.NewSlave do
|
||||
file_comment: "comment",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
context =
|
||||
%Context{}
|
||||
@ -95,7 +93,7 @@ defmodule AccentTest.Movement.Builders.NewSlave do
|
||||
|
||||
test "with removed translation", %{revision: revision, project: project, document: document} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
@ -103,8 +101,12 @@ defmodule AccentTest.Movement.Builders.NewSlave do
|
||||
file_comment: "comment",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id,
|
||||
conflicted: false,
|
||||
conflicted_text: "",
|
||||
value_type: "string",
|
||||
translated: true,
|
||||
removed: true
|
||||
})
|
||||
)
|
||||
|
||||
context =
|
||||
%Context{}
|
||||
@ -133,6 +135,7 @@ defmodule AccentTest.Movement.Builders.NewSlave do
|
||||
previous_translation: %PreviousTranslation{
|
||||
value_type: "string",
|
||||
removed: true,
|
||||
translated: true,
|
||||
conflicted: false,
|
||||
conflicted_text: "",
|
||||
corrected_text: "A",
|
||||
|
@ -11,24 +11,22 @@ defmodule AccentTest.Movement.Builders.NewVersion do
|
||||
alias Accent.Version
|
||||
alias Movement.Builders.NewVersion, as: NewVersionBuilder
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [revision: revision, document: document, project: project, user: user]}
|
||||
end
|
||||
|
||||
test "builder fetch translations and process operations", %{revision: revision, project: project, document: document} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
@ -38,7 +36,7 @@ defmodule AccentTest.Movement.Builders.NewVersion do
|
||||
locked: true,
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
context =
|
||||
%Movement.Context{}
|
||||
@ -70,10 +68,10 @@ defmodule AccentTest.Movement.Builders.NewVersion do
|
||||
end
|
||||
|
||||
test "builder with existing version", %{revision: revision, project: project, document: document, user: user} do
|
||||
version = Repo.insert!(%Version{user_id: user.id, tag: "v3.2", name: "Release", project_id: project.id})
|
||||
version = Factory.insert(Version, user_id: user.id, tag: "v3.2", name: "Release", project_id: project.id)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
@ -81,9 +79,9 @@ defmodule AccentTest.Movement.Builders.NewVersion do
|
||||
file_comment: "comment",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
@ -93,7 +91,7 @@ defmodule AccentTest.Movement.Builders.NewVersion do
|
||||
version_id: version.id,
|
||||
document_id: document.id,
|
||||
source_translation_id: translation.id
|
||||
})
|
||||
)
|
||||
|
||||
context =
|
||||
%Movement.Context{}
|
||||
|
@ -12,19 +12,17 @@ defmodule AccentTest.Movement.Builders.ProjectSync do
|
||||
alias Movement.Builders.ProjectSync, as: ProjectSyncBuilder
|
||||
alias Movement.Context
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
other_language = Repo.insert!(%Language{name: "French", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
other_language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
other_revision = Repo.insert!(%Revision{master: false, project_id: project.id, language_id: other_language.id})
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
other_revision = Factory.insert(Revision, master: false, project_id: project.id, language_id: other_language.id)
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [revision: revision, document: document, project: project, other_revision: other_revision]}
|
||||
end
|
||||
@ -35,9 +33,9 @@ defmodule AccentTest.Movement.Builders.ProjectSync do
|
||||
project: project,
|
||||
other_revision: other_revision
|
||||
} do
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id})
|
||||
Repo.insert!(%Translation{key: "b", proposed_text: "B", revision_id: revision.id, document_id: document.id})
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "C", revision_id: other_revision.id, document_id: document.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id)
|
||||
Factory.insert(Translation, key: "b", proposed_text: "B", revision_id: revision.id, document_id: document.id)
|
||||
Factory.insert(Translation, key: "a", proposed_text: "C", revision_id: other_revision.id, document_id: document.id)
|
||||
entries = [%Langue.Entry{key: "a", value: "B", value_type: "string"}]
|
||||
|
||||
context =
|
||||
|
@ -9,11 +9,9 @@ defmodule AccentTest.Movement.Builders.RevisionCorrectAll do
|
||||
alias Accent.User
|
||||
alias Movement.Builders.RevisionCorrectAll, as: RevisionCorrectAllBuilder
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "French", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
@ -24,7 +22,7 @@ defmodule AccentTest.Movement.Builders.RevisionCorrectAll do
|
||||
end
|
||||
|
||||
test "builder fetch translations and correct conflict", %{revision: revision} do
|
||||
translation = Repo.insert!(%Translation{key: "a", proposed_text: "A", conflicted: true, revision_id: revision.id})
|
||||
translation = Factory.insert(Translation, key: "a", proposed_text: "A", conflicted: true, revision_id: revision.id)
|
||||
|
||||
context =
|
||||
%Movement.Context{}
|
||||
@ -39,7 +37,7 @@ defmodule AccentTest.Movement.Builders.RevisionCorrectAll do
|
||||
end
|
||||
|
||||
test "builder fetch translations and ignore corrected translation", %{revision: revision} do
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", conflicted: false, revision_id: revision.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", conflicted: false, revision_id: revision.id)
|
||||
|
||||
context =
|
||||
%Movement.Context{}
|
||||
|
@ -11,20 +11,18 @@ defmodule AccentTest.Movement.Builders.RevisionMerge do
|
||||
alias Movement.Builders.RevisionMerge, as: RevisionMergeBuilder
|
||||
alias Movement.Context
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
test "builder fetch translations and use comparer" do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(revisions: [:language]) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id)
|
||||
|
||||
entries = [%Langue.Entry{key: "a", value: "B", value_type: "string"}]
|
||||
|
||||
|
@ -11,24 +11,22 @@ defmodule AccentTest.Movement.Builders.RevisionSync do
|
||||
alias Movement.Builders.RevisionSync, as: RevisionSyncBuilder
|
||||
alias Movement.Context
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [revision: revision, document: document]}
|
||||
end
|
||||
|
||||
test "builder fetch translations and use comparer", %{revision: revision, document: document} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id)
|
||||
|
||||
entries = [%Langue.Entry{key: "a", value: "B", value_type: "string"}]
|
||||
|
||||
@ -48,7 +46,7 @@ defmodule AccentTest.Movement.Builders.RevisionSync do
|
||||
|
||||
test "builder fetch translations and process to remove with empty entries", %{revision: revision, document: document} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id)
|
||||
|
||||
context =
|
||||
%Context{entries: []}
|
||||
@ -66,13 +64,13 @@ defmodule AccentTest.Movement.Builders.RevisionSync do
|
||||
|
||||
test "builder fetch translations and process to renew with entries", %{revision: revision, document: document} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id,
|
||||
removed: true
|
||||
})
|
||||
)
|
||||
|
||||
entries = [%Langue.Entry{key: "a", value: "B", value_type: "string"}]
|
||||
|
||||
|
@ -9,11 +9,9 @@ defmodule AccentTest.Movement.Builders.RevisionUncorrectAll do
|
||||
alias Accent.User
|
||||
alias Movement.Builders.RevisionUncorrectAll, as: RevisionUncorrectAllBuilder
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
@ -24,7 +22,7 @@ defmodule AccentTest.Movement.Builders.RevisionUncorrectAll do
|
||||
end
|
||||
|
||||
test "builder fetch translations and uncorrect conflict", %{revision: revision} do
|
||||
translation = Repo.insert!(%Translation{key: "a", proposed_text: "A", conflicted: false, revision_id: revision.id})
|
||||
translation = Factory.insert(Translation, key: "a", proposed_text: "A", conflicted: false, revision_id: revision.id)
|
||||
|
||||
context =
|
||||
%Movement.Context{}
|
||||
@ -39,7 +37,7 @@ defmodule AccentTest.Movement.Builders.RevisionUncorrectAll do
|
||||
end
|
||||
|
||||
test "builder fetch translations and ignore conflicted translation", %{revision: revision} do
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", conflicted: true, revision_id: revision.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", conflicted: true, revision_id: revision.id)
|
||||
|
||||
context =
|
||||
%Movement.Context{}
|
||||
|
@ -12,23 +12,21 @@ defmodule AccentTest.Movement.Builders.Rollback do
|
||||
alias Accent.User
|
||||
alias Movement.Builders.Rollback, as: RollbackBuilder
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [revision: revision, document: document, project: project]}
|
||||
end
|
||||
|
||||
test "builder process operations for batch", %{project: project} do
|
||||
operation = Repo.insert!(%Operation{project_id: project.id, batch: true, action: "sync"})
|
||||
operation = Factory.insert(Operation, project_id: project.id, batch: true, action: "sync")
|
||||
|
||||
context =
|
||||
%Movement.Context{}
|
||||
@ -43,16 +41,17 @@ defmodule AccentTest.Movement.Builders.Rollback do
|
||||
|
||||
test "builder process operations for translation", %{project: project, revision: revision, document: document} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "A",
|
||||
proposed_text: "TEXT",
|
||||
conflicted_text: "Ex-TEXT",
|
||||
corrected_text: "LOL",
|
||||
translated: true,
|
||||
removed: false,
|
||||
revision_id: revision.id,
|
||||
value_type: "string",
|
||||
placeholders: []
|
||||
})
|
||||
)
|
||||
|
||||
operation =
|
||||
%Operation{
|
||||
@ -88,6 +87,7 @@ defmodule AccentTest.Movement.Builders.Rollback do
|
||||
conflicted_text: translation.conflicted_text,
|
||||
conflicted: translation.conflicted,
|
||||
removed: translation.removed,
|
||||
translated: translation.translated,
|
||||
placeholders: translation.placeholders
|
||||
}
|
||||
end
|
||||
|
@ -12,19 +12,17 @@ defmodule AccentTest.Movement.Builders.SlaveConflictSync do
|
||||
alias Movement.Builders.SlaveConflictSync, as: SlaveConflictSyncBuilder
|
||||
alias Movement.Context
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
other_language = Repo.insert!(%Language{name: "French", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
other_language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
other_revision = Repo.insert!(%Revision{project_id: project.id, language_id: other_language.id})
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
other_revision = Factory.insert(Revision, project_id: project.id, language_id: other_language.id)
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [project: project, revision: revision, document: document, other_revision: other_revision]}
|
||||
end
|
||||
@ -35,10 +33,15 @@ defmodule AccentTest.Movement.Builders.SlaveConflictSync do
|
||||
other_revision: other_revision
|
||||
} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id)
|
||||
|
||||
other_translation =
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "C", revision_id: other_revision.id, document_id: document.id})
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "C",
|
||||
revision_id: other_revision.id,
|
||||
document_id: document.id
|
||||
)
|
||||
|
||||
context =
|
||||
%Context{operations: [%{key: "a", action: "conflict_on_proposed"}]}
|
||||
@ -60,18 +63,18 @@ defmodule AccentTest.Movement.Builders.SlaveConflictSync do
|
||||
document: document,
|
||||
other_revision: other_revision
|
||||
} do
|
||||
other_document = Repo.insert!(%Document{project_id: project.id, path: "other", format: "json"})
|
||||
other_document = Factory.insert(Document, project_id: project.id, path: "other", format: "json")
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id)
|
||||
|
||||
other_translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "C",
|
||||
revision_id: other_revision.id,
|
||||
document_id: other_document.id
|
||||
})
|
||||
)
|
||||
|
||||
context =
|
||||
%Context{operations: [%{key: "a", action: "conflict_on_proposed"}]}
|
||||
|
@ -36,8 +36,8 @@ defmodule AccentTest.Movement.Builders.TranslationUpdate do
|
||||
end
|
||||
|
||||
test "builder copy on latest version" do
|
||||
user = Repo.insert!(%User{email: "test@test.com"})
|
||||
language = Repo.insert!(%Language{name: "French", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User, email: "test@test.com")
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
@ -54,23 +54,23 @@ defmodule AccentTest.Movement.Builders.TranslationUpdate do
|
||||
})
|
||||
|
||||
source_translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
revision_id: revision.id,
|
||||
version_id: nil
|
||||
})
|
||||
)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
version_id: version.id,
|
||||
revision_id: revision.id,
|
||||
source_translation_id: source_translation.id
|
||||
})
|
||||
)
|
||||
|
||||
context =
|
||||
%Context{}
|
||||
|
@ -25,14 +25,14 @@ defmodule AccentTest.Migrator.Down do
|
||||
}
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_in_conflict",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: nil,
|
||||
proposed_text: "new proposed text",
|
||||
conflicted_text: "corrected_text",
|
||||
conflicted: true
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.down(
|
||||
Repo.insert!(%Operation{
|
||||
@ -62,14 +62,14 @@ defmodule AccentTest.Migrator.Down do
|
||||
}
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_in_proposed",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: nil,
|
||||
proposed_text: "new proposed text",
|
||||
conflicted_text: "proposed_text",
|
||||
conflicted: true
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.down(
|
||||
Repo.insert!(%Operation{
|
||||
@ -89,16 +89,16 @@ defmodule AccentTest.Migrator.Down do
|
||||
|
||||
test ":new" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_added_down",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: nil,
|
||||
proposed_text: "new text",
|
||||
conflicted_text: nil,
|
||||
conflicted: true
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.down(Repo.insert!(%Operation{action: "new", translation: translation}))
|
||||
Migrator.down(Factory.insert(Operation, action: "new", translation: translation))
|
||||
|
||||
new_translation = Repo.get!(Translation, translation.id)
|
||||
|
||||
@ -107,16 +107,16 @@ defmodule AccentTest.Migrator.Down do
|
||||
|
||||
test ":renew" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_added_down",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: nil,
|
||||
proposed_text: "new text",
|
||||
conflicted_text: nil,
|
||||
conflicted: true
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.down(Repo.insert!(%Operation{action: "renew", translation: translation}))
|
||||
Migrator.down(Factory.insert(Operation, action: "renew", translation: translation))
|
||||
|
||||
new_translation = Repo.get!(Translation, translation.id)
|
||||
|
||||
@ -125,18 +125,18 @@ defmodule AccentTest.Migrator.Down do
|
||||
|
||||
test ":remove" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
value_type: "",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
key: "to_be_added_down",
|
||||
corrected_text: nil,
|
||||
proposed_text: "new text",
|
||||
conflicted_text: nil,
|
||||
conflicted: true,
|
||||
placeholders: []
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.down(Repo.insert!(%Operation{action: "remove", translation: translation}))
|
||||
Migrator.down(Factory.insert(Operation, action: "remove", translation: translation))
|
||||
|
||||
new_translation = Repo.get!(Translation, translation.id)
|
||||
|
||||
|
@ -15,8 +15,8 @@ defmodule AccentTest.Movement.Persisters.Base do
|
||||
alias Movement.Persisters.Base, as: BasePersister
|
||||
|
||||
test "don’t overwrite revision" do
|
||||
revision = Repo.insert!(%Revision{})
|
||||
revision_two = Repo.insert!(%Revision{})
|
||||
revision = Factory.insert(Revision)
|
||||
revision_two = Factory.insert(Revision)
|
||||
|
||||
translation = %Translation{
|
||||
key: "a",
|
||||
@ -55,10 +55,10 @@ defmodule AccentTest.Movement.Persisters.Base do
|
||||
end
|
||||
|
||||
test "persist and execute operations" do
|
||||
user = Repo.insert!(%User{email: "test@test.com"})
|
||||
revision = Repo.insert!(%Revision{})
|
||||
user = Factory.insert(User, email: "test@test.com")
|
||||
revision = Factory.insert(Revision)
|
||||
|
||||
translation = Repo.insert!(%Translation{key: "a", proposed_text: "A", conflicted: true, revision_id: revision.id})
|
||||
translation = Factory.insert(Translation, key: "a", proposed_text: "A", conflicted: true, revision_id: revision.id)
|
||||
|
||||
operations = [
|
||||
%Movement.Operation{
|
||||
@ -92,10 +92,16 @@ defmodule AccentTest.Movement.Persisters.Base do
|
||||
end
|
||||
|
||||
test "new operation with removed translation" do
|
||||
revision = Repo.insert!(%Revision{})
|
||||
revision = Factory.insert(Revision)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", conflicted: true, removed: true, revision_id: revision.id})
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
conflicted: true,
|
||||
removed: true,
|
||||
revision_id: revision.id
|
||||
)
|
||||
|
||||
operations = [
|
||||
%Movement.Operation{
|
||||
@ -120,10 +126,16 @@ defmodule AccentTest.Movement.Persisters.Base do
|
||||
end
|
||||
|
||||
test "version operation with source translation" do
|
||||
revision = Repo.insert!(%Revision{})
|
||||
revision = Factory.insert(Revision)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", revision_id: revision.id, proposed_text: "A", conflicted: true, removed: true})
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
revision_id: revision.id,
|
||||
proposed_text: "A",
|
||||
conflicted: true,
|
||||
removed: true
|
||||
)
|
||||
|
||||
operations = [
|
||||
%Movement.Operation{
|
||||
@ -146,10 +158,16 @@ defmodule AccentTest.Movement.Persisters.Base do
|
||||
end
|
||||
|
||||
test "version operation add operation on source translation" do
|
||||
revision = Repo.insert!(%Revision{})
|
||||
revision = Factory.insert(Revision)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", revision_id: revision.id, proposed_text: "A", conflicted: true, removed: true})
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
revision_id: revision.id,
|
||||
proposed_text: "A",
|
||||
conflicted: true,
|
||||
removed: true
|
||||
)
|
||||
|
||||
operations = [
|
||||
%Movement.Operation{
|
||||
@ -177,20 +195,20 @@ defmodule AccentTest.Movement.Persisters.Base do
|
||||
end
|
||||
|
||||
test "update operation add operation on version source translation" do
|
||||
user = Repo.insert!(%User{email: "user@example.com"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "project"})
|
||||
revision = Repo.insert!(%Revision{project_id: project.id})
|
||||
version = Repo.insert!(%Version{name: "foo", tag: "0.1", project: project, user: user})
|
||||
user = Factory.insert(User, email: "user@example.com")
|
||||
project = Factory.insert(Project, main_color: "#f00", name: "project")
|
||||
revision = Factory.insert(Revision, project_id: project.id)
|
||||
version = Factory.insert(Version, name: "foo", tag: "0.1", project: project, user: user)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
revision_id: revision.id,
|
||||
proposed_text: "A",
|
||||
conflicted: true,
|
||||
removed: true,
|
||||
version: version
|
||||
})
|
||||
)
|
||||
|
||||
operations = [
|
||||
%Movement.Operation{
|
||||
|
@ -8,11 +8,9 @@ defmodule AccentTest.Movement.Persisters.NewSlave do
|
||||
alias Accent.User
|
||||
alias Movement.Persisters.NewSlave, as: NewSlavePersister
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
@ -23,7 +21,7 @@ defmodule AccentTest.Movement.Persisters.NewSlave do
|
||||
end
|
||||
|
||||
test "create revision success", %{project: project, revision: master_revision} do
|
||||
new_language = Repo.insert!(%Language{name: "French", slug: Ecto.UUID.generate()})
|
||||
new_language = Factory.insert(Language)
|
||||
|
||||
{:ok, {context, _}} =
|
||||
NewSlavePersister.persist(%Movement.Context{
|
||||
|
@ -15,11 +15,9 @@ defmodule AccentTest.Movement.Persisters.NewVersion do
|
||||
alias Movement.Context
|
||||
alias Movement.Persisters.NewVersion, as: NewVersionPersister
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(
|
||||
@ -28,7 +26,7 @@ defmodule AccentTest.Movement.Persisters.NewVersion do
|
||||
)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [revision: revision, document: document, project: project, user: user]}
|
||||
end
|
||||
@ -40,7 +38,7 @@ defmodule AccentTest.Movement.Persisters.NewVersion do
|
||||
document: document
|
||||
} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
@ -51,7 +49,7 @@ defmodule AccentTest.Movement.Persisters.NewVersion do
|
||||
conflicted: true,
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
operations = [
|
||||
%Movement.Operation{
|
||||
|
@ -10,14 +10,14 @@ defmodule Movement.Persisters.ProjectHookWorkerTest do
|
||||
alias Movement.Persisters.ProjectHookWorker, as: Worker
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(%User{email: "test@test.com"})
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User, email: "test@test.com")
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [revision: revision, document: document, project: project, user: user]}
|
||||
end
|
||||
@ -38,14 +38,14 @@ defmodule Movement.Persisters.ProjectHookWorkerTest do
|
||||
end
|
||||
|
||||
test "new_conflicts", %{user: user, project: project, revision: revision, document: document} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
conflicted: true,
|
||||
corrected_text: "Test",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
args = %{
|
||||
"project_id" => project.id,
|
||||
@ -75,14 +75,14 @@ defmodule Movement.Persisters.ProjectHookWorkerTest do
|
||||
end
|
||||
|
||||
test "complete_review", %{user: user, project: project, revision: revision, document: document} do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
conflicted: false,
|
||||
corrected_text: "Test",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
args = %{
|
||||
"project_id" => project.id,
|
||||
|
@ -14,24 +14,22 @@ defmodule AccentTest.Movement.Persisters.ProjectSync do
|
||||
alias Movement.Context
|
||||
alias Movement.Persisters.ProjectSync, as: ProjectSyncPersister
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [project: project, document: document, revision: revision, user: user]}
|
||||
end
|
||||
|
||||
test "persist operations", %{project: project, revision: revision, document: document, user: user} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id})
|
||||
Factory.insert(Translation, key: "a", proposed_text: "A", revision_id: revision.id, document_id: document.id)
|
||||
|
||||
operations = [
|
||||
%Movement.Operation{
|
||||
|
@ -15,31 +15,29 @@ defmodule AccentTest.Movement.Persisters.Rollback do
|
||||
alias Movement.Context
|
||||
alias Movement.Persisters.Rollback, as: RollbackPersister
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [project: project, document: document, revision: revision, user: user]}
|
||||
end
|
||||
|
||||
test "persist operations", %{project: project, revision: revision, document: document, user: user} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
conflicted: false,
|
||||
corrected_text: "Test",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
operation =
|
||||
Repo.insert!(%Accent.Operation{
|
||||
@ -97,13 +95,13 @@ defmodule AccentTest.Movement.Persisters.Rollback do
|
||||
|
||||
test "rollback batch", %{revision: revision} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
corrected_text: "B",
|
||||
conflicted: true,
|
||||
revision_id: revision.id,
|
||||
revision: revision
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Operation{
|
||||
action: "new",
|
||||
@ -113,7 +111,7 @@ defmodule AccentTest.Movement.Persisters.Rollback do
|
||||
revision_id: revision.id
|
||||
})
|
||||
|
||||
batch_operation = Repo.insert!(%Operation{action: "sync", batch: true, revision_id: revision.id})
|
||||
batch_operation = Factory.insert(Operation, action: "sync", batch: true, revision_id: revision.id)
|
||||
|
||||
operation =
|
||||
Repo.insert!(%Operation{
|
||||
@ -147,13 +145,13 @@ defmodule AccentTest.Movement.Persisters.Rollback do
|
||||
|
||||
test "rollback rollback does nothing", %{revision: revision} do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
corrected_text: "B",
|
||||
conflicted: true,
|
||||
revision_id: revision.id,
|
||||
revision: revision
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Operation{
|
||||
action: "new",
|
||||
|
@ -16,12 +16,12 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":correct" do
|
||||
user = Repo.insert!(%User{})
|
||||
revision = Repo.insert!(%Revision{})
|
||||
revision = Factory.insert(Revision)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_corrected",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
file_comment: "",
|
||||
corrected_text: nil,
|
||||
proposed_text: "proposed_text",
|
||||
@ -29,7 +29,7 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
conflicted: true,
|
||||
value_type: "string",
|
||||
removed: false
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
id: Ecto.UUID.generate(),
|
||||
@ -52,12 +52,12 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":merge_on_proposed_force" do
|
||||
user = Repo.insert!(%User{})
|
||||
revision = Repo.insert!(%Revision{})
|
||||
revision = Factory.insert(Revision)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_merged",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
file_comment: "",
|
||||
corrected_text: "corrected_text",
|
||||
proposed_text: "proposed_text",
|
||||
@ -65,7 +65,7 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
conflicted_text: nil,
|
||||
conflicted: true,
|
||||
removed: false
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
id: Ecto.UUID.generate(),
|
||||
@ -87,18 +87,18 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":merge_on_corrected" do
|
||||
user = Repo.insert!(%User{})
|
||||
revision = Repo.insert!(%Revision{})
|
||||
revision = Factory.insert(Revision)
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_merged",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: "corrected_text",
|
||||
proposed_text: "proposed_text",
|
||||
conflicted_text: nil,
|
||||
value_type: "string",
|
||||
conflicted: true
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
action: "merge_on_corrected",
|
||||
@ -118,9 +118,9 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":uncorrect" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_uncorrected",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
file_comment: "",
|
||||
file_index: 1,
|
||||
corrected_text: "new proposed text",
|
||||
@ -129,7 +129,7 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
conflicted: false,
|
||||
removed: false,
|
||||
value_type: "string"
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
action: "uncorrect_conflict",
|
||||
@ -149,9 +149,9 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":uncorrect with same corrected and proposed" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_uncorrected",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
file_comment: "",
|
||||
file_index: 1,
|
||||
corrected_text: "proposed_text",
|
||||
@ -161,7 +161,7 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
conflicted: false,
|
||||
translated: true,
|
||||
removed: false
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
action: "uncorrect_conflict",
|
||||
@ -181,16 +181,16 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":conflict_on_corrected" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_in_conflict",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
file_comment: "",
|
||||
file_index: 1,
|
||||
corrected_text: "corrected_text",
|
||||
proposed_text: "proposed_text",
|
||||
conflicted: false,
|
||||
removed: false
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
action: "conflict_on_corrected",
|
||||
@ -210,16 +210,16 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":conflict_on_slave" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_in_conflict",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
file_comment: "",
|
||||
file_index: 1,
|
||||
corrected_text: "corrected_text",
|
||||
proposed_text: "proposed_text",
|
||||
conflicted: false,
|
||||
removed: false
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
action: "conflict_on_slave",
|
||||
@ -238,14 +238,14 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":remove" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_removed",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: "corrected_text",
|
||||
proposed_text: "proposed_text",
|
||||
conflicted: false,
|
||||
removed: false
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
action: "remove",
|
||||
@ -260,14 +260,14 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":renew" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_renewed",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: "corrected_text",
|
||||
proposed_text: "proposed_text",
|
||||
conflicted: false,
|
||||
removed: true
|
||||
})
|
||||
)
|
||||
|
||||
operation =
|
||||
Repo.insert!(%Operation{
|
||||
@ -285,14 +285,14 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":rollback" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "to_be_rollbacked",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: "corrected_text",
|
||||
proposed_text: "proposed_text",
|
||||
conflicted: false,
|
||||
removed: true
|
||||
})
|
||||
)
|
||||
|
||||
operation =
|
||||
Repo.insert!(%Operation{
|
||||
@ -310,10 +310,10 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":conflict_on_proposed" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
value_type: "",
|
||||
key: "to_be_conflict_on_proposed",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
file_comment: "",
|
||||
file_index: 1,
|
||||
corrected_text: "corrected_text",
|
||||
@ -321,7 +321,7 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
conflicted: true,
|
||||
removed: false,
|
||||
placeholders: []
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
value_type: "",
|
||||
@ -345,15 +345,15 @@ defmodule AccentTest.Movement.Migrator.Up do
|
||||
|
||||
test ":updated_proposed" do
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "updated_proposed",
|
||||
revision: Repo.insert!(%Revision{}),
|
||||
revision: Factory.insert(Revision),
|
||||
corrected_text: "corrected_text",
|
||||
proposed_text: "proposed_text",
|
||||
conflicted_text: "conflict",
|
||||
conflicted: true,
|
||||
removed: false
|
||||
})
|
||||
)
|
||||
|
||||
Migrator.up(%Operation{
|
||||
action: "update_proposed",
|
||||
|
@ -5,12 +5,8 @@ defmodule AccentTest.Plugs.AssignCurrentUser do
|
||||
|
||||
alias Accent.AccessToken
|
||||
alias Accent.Plugs.AssignCurrentUser
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
@token %AccessToken{revoked_at: nil, token: "1234"}
|
||||
|
||||
defp call_plug(token) do
|
||||
:get
|
||||
|> conn("/foo")
|
||||
@ -20,11 +16,11 @@ defmodule AccentTest.Plugs.AssignCurrentUser do
|
||||
|
||||
test "assign current_user" do
|
||||
user =
|
||||
@user
|
||||
|> Repo.insert!()
|
||||
User
|
||||
|> Factory.insert()
|
||||
|> Map.put(:permissions, %{})
|
||||
|
||||
token = Repo.insert!(Map.put(@token, :user_id, user.id))
|
||||
token = Factory.insert(AccessToken, user_id: user.id)
|
||||
|
||||
assigned_user =
|
||||
token.token
|
||||
|
@ -30,16 +30,15 @@ defmodule AccentTest.Plugs.MovementContextParser do
|
||||
%Plug.Upload{content_type: "text/plain", filename: "unicode.strings", path: "test/support/invalid_unicode.strings"}
|
||||
end
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
|
||||
revision = project |> Repo.preload(:revisions) |> Map.get(:revisions) |> hd()
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "json")
|
||||
|
||||
{:ok, [project: project, document: document, revision: revision, language: language, user: user]}
|
||||
end
|
||||
|
@ -5,21 +5,20 @@ defmodule AccentTest.Scopes.Translation do
|
||||
alias Accent.Document
|
||||
alias Accent.Operation
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Scopes.Translation, as: Scope
|
||||
alias Accent.Translation
|
||||
|
||||
doctest Accent.Scopes.Translation
|
||||
|
||||
setup do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
project = Factory.insert(Project)
|
||||
|
||||
{:ok, [project: project]}
|
||||
end
|
||||
|
||||
describe "parse_added_last_sync/3" do
|
||||
test "existing sync", %{project: project} do
|
||||
sync = Repo.insert!(%Operation{project: project, action: "sync"})
|
||||
sync = Factory.insert(Operation, project_id: project.id, action: "sync")
|
||||
|
||||
query = Scope.parse_added_last_sync(Translation, true, project.id, nil)
|
||||
|
||||
@ -28,9 +27,9 @@ defmodule AccentTest.Scopes.Translation do
|
||||
end
|
||||
|
||||
test "existing sync with document", %{project: project} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "my-test", format: "xliff_1_2"})
|
||||
sync = Repo.insert!(%Operation{project: project, action: "sync", document: document})
|
||||
_other_sync = Repo.insert!(%Operation{project: project, action: "sync"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "my-test", format: "xliff_1_2")
|
||||
sync = Factory.insert(Operation, project_id: project.id, action: "sync", document_id: document.id)
|
||||
_other_sync = Factory.insert(Operation, project_id: project.id, action: "sync")
|
||||
|
||||
query = Scope.parse_added_last_sync(Translation, true, project.id, document.id)
|
||||
|
||||
@ -39,9 +38,14 @@ defmodule AccentTest.Scopes.Translation do
|
||||
end
|
||||
|
||||
test "many sync", %{project: project} do
|
||||
_ = Repo.insert!(%Operation{project: project, action: "sync", inserted_at: ~U[2018-01-02T00:00:00.000000Z]})
|
||||
sync = Repo.insert!(%Operation{project: project, action: "sync", inserted_at: ~U[2018-01-03T00:00:00.000000Z]})
|
||||
_ = Repo.insert!(%Operation{project: project, action: "sync", inserted_at: ~U[2018-01-01T00:00:00.000000Z]})
|
||||
_ =
|
||||
Factory.insert(Operation, project_id: project.id, action: "sync", inserted_at: ~U[2018-01-02T00:00:00.000000Z])
|
||||
|
||||
sync =
|
||||
Factory.insert(Operation, project_id: project.id, action: "sync", inserted_at: ~U[2018-01-03T00:00:00.000000Z])
|
||||
|
||||
_ =
|
||||
Factory.insert(Operation, project_id: project.id, action: "sync", inserted_at: ~U[2018-01-01T00:00:00.000000Z])
|
||||
|
||||
query = Scope.parse_added_last_sync(Translation, true, project.id, nil)
|
||||
|
||||
|
@ -16,12 +16,12 @@ defmodule AccentTest.Scopes.Version do
|
||||
end
|
||||
|
||||
defp insert_version(tag, project, user) do
|
||||
Repo.insert!(%Version{name: "foo", tag: tag, project_id: project.id, user_id: user.id})
|
||||
Factory.insert(Version, name: "foo", tag: tag, project_id: project.id, user_id: user.id)
|
||||
end
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(%User{email: "test@test.com"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User, email: "test@test.com")
|
||||
project = Factory.insert(Project)
|
||||
|
||||
{:ok, [user: user, project: project]}
|
||||
end
|
||||
|
@ -5,58 +5,56 @@ defmodule AccentTest.CollaboratorCreator do
|
||||
alias Accent.Collaborator
|
||||
alias Accent.CollaboratorCreator
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
|
||||
@email Faker.Internet.email()
|
||||
|
||||
test "create unknown email" do
|
||||
email = "test@test.com"
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "com"})
|
||||
assigner = Repo.insert!(%User{email: "lol@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
assigner = Factory.insert(User)
|
||||
role = "admin"
|
||||
|
||||
{:ok, collaborator} =
|
||||
CollaboratorCreator.create(%{
|
||||
"email" => email,
|
||||
"email" => @email,
|
||||
"assigner_id" => assigner.id,
|
||||
"role" => role,
|
||||
"project_id" => project.id
|
||||
})
|
||||
|
||||
assert collaborator.email === email
|
||||
assert collaborator.email === @email
|
||||
assert collaborator.assigner_id === assigner.id
|
||||
assert collaborator.role === role
|
||||
end
|
||||
|
||||
test "create known email" do
|
||||
email = "test@test.com"
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "com"})
|
||||
user = Repo.insert!(%User{email: email})
|
||||
assigner = Repo.insert!(%User{email: "lol@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
user = Factory.insert(User, email: @email)
|
||||
assigner = Factory.insert(User)
|
||||
role = "admin"
|
||||
|
||||
{:ok, collaborator} =
|
||||
CollaboratorCreator.create(%{
|
||||
"email" => email,
|
||||
"email" => @email,
|
||||
"assigner_id" => assigner.id,
|
||||
"role" => role,
|
||||
"project_id" => project.id
|
||||
})
|
||||
|
||||
assert collaborator.email === email
|
||||
assert collaborator.email === @email
|
||||
assert collaborator.user_id === user.id
|
||||
assert collaborator.assigner_id === assigner.id
|
||||
assert collaborator.role === role
|
||||
end
|
||||
|
||||
test "create invalid role" do
|
||||
email = "test@test.com"
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "com"})
|
||||
assigner = Repo.insert!(%User{email: "lol@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
assigner = Factory.insert(User)
|
||||
role = "test123"
|
||||
|
||||
{:error, collaborator} =
|
||||
CollaboratorCreator.create(%{
|
||||
"email" => email,
|
||||
"email" => @email,
|
||||
"assigner_id" => assigner.id,
|
||||
"role" => role,
|
||||
"project_id" => project.id
|
||||
@ -70,8 +68,8 @@ defmodule AccentTest.CollaboratorCreator do
|
||||
|
||||
test "create with insensitive email" do
|
||||
email = "TEST@test.com"
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "com"})
|
||||
assigner = Repo.insert!(%User{email: "lol@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
assigner = Factory.insert(User)
|
||||
role = "admin"
|
||||
|
||||
{:ok, collaborator} =
|
||||
@ -86,32 +84,30 @@ defmodule AccentTest.CollaboratorCreator do
|
||||
end
|
||||
|
||||
test "create with leading and trailing spaces in email" do
|
||||
email = " test@test.com "
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "com"})
|
||||
assigner = Repo.insert!(%User{email: "lol@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
assigner = Factory.insert(User)
|
||||
role = "admin"
|
||||
|
||||
{:ok, collaborator} =
|
||||
CollaboratorCreator.create(%{
|
||||
"email" => email,
|
||||
"email" => " #{@email} ",
|
||||
"assigner_id" => assigner.id,
|
||||
"role" => role,
|
||||
"project_id" => project.id
|
||||
})
|
||||
|
||||
assert collaborator.email === "test@test.com"
|
||||
assert collaborator.email === @email
|
||||
end
|
||||
|
||||
test "cannot create with already used email for project" do
|
||||
email = "test@test.com"
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "com"})
|
||||
assigner = Repo.insert!(%User{email: "lol@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
assigner = Factory.insert(User)
|
||||
role = "admin"
|
||||
Repo.insert!(%Collaborator{email: email, assigner_id: assigner.id, role: role, project_id: project.id})
|
||||
Factory.insert(Collaborator, email: @email, assigner_id: assigner.id, role: role, project_id: project.id)
|
||||
|
||||
{:error, changeset} =
|
||||
CollaboratorCreator.create(%{
|
||||
"email" => email,
|
||||
"email" => @email,
|
||||
"assigner_id" => assigner.id,
|
||||
"role" => role,
|
||||
"project_id" => project.id
|
||||
|
@ -9,15 +9,32 @@ defmodule AccentTest.CollaboratorNormalizer do
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
alias Accent.UserRemote.CollaboratorNormalizer
|
||||
alias Faker.Internet
|
||||
|
||||
test "create with many collaborations" do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "Ha"})
|
||||
project2 = Repo.insert!(%Project{main_color: "#f00", name: "Oh"})
|
||||
assigner = Repo.insert!(%User{email: "assigner@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
project2 = Factory.insert(Project)
|
||||
assigner = Factory.insert(User)
|
||||
|
||||
collaborators = [
|
||||
%Collaborator{role: "admin", project_id: project.id, assigner_id: assigner.id},
|
||||
%Collaborator{role: "developer", project_id: project2.id, assigner_id: assigner.id}
|
||||
struct!(
|
||||
Collaborator,
|
||||
Factory.build(Collaborator,
|
||||
email: Internet.email(),
|
||||
role: "admin",
|
||||
project_id: project.id,
|
||||
assigner_id: assigner.id
|
||||
)
|
||||
),
|
||||
struct!(
|
||||
Collaborator,
|
||||
Factory.build(Collaborator,
|
||||
email: Internet.email(),
|
||||
role: "developer",
|
||||
project_id: project2.id,
|
||||
assigner_id: assigner.id
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
collaborator_ids =
|
||||
@ -26,7 +43,7 @@ defmodule AccentTest.CollaboratorNormalizer do
|
||||
|> Enum.map(&Repo.insert!/1)
|
||||
|> Enum.map(&Map.get(&1, :id))
|
||||
|
||||
new_user = Repo.insert!(%User{email: "test@test.com"})
|
||||
new_user = Factory.insert(User, email: "test@test.com")
|
||||
|
||||
%User{} = CollaboratorNormalizer.normalize(new_user)
|
||||
|
||||
@ -36,13 +53,29 @@ defmodule AccentTest.CollaboratorNormalizer do
|
||||
end
|
||||
|
||||
test "create with case insensitive email" do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "Ha"})
|
||||
project2 = Repo.insert!(%Project{main_color: "#f00", name: "Oh"})
|
||||
assigner = Repo.insert!(%User{email: "assigner@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
project2 = Factory.insert(Project)
|
||||
assigner = Factory.insert(User)
|
||||
|
||||
collaborators = [
|
||||
%Collaborator{role: "admin", project_id: project.id, assigner_id: assigner.id},
|
||||
%Collaborator{role: "developer", project_id: project2.id, assigner_id: assigner.id}
|
||||
struct!(
|
||||
Collaborator,
|
||||
Factory.build(Collaborator,
|
||||
email: Internet.email(),
|
||||
role: "admin",
|
||||
project_id: project.id,
|
||||
assigner_id: assigner.id
|
||||
)
|
||||
),
|
||||
struct!(
|
||||
Collaborator,
|
||||
Factory.build(Collaborator,
|
||||
email: Internet.email(),
|
||||
role: "developer",
|
||||
project_id: project2.id,
|
||||
assigner_id: assigner.id
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
collaborator_ids =
|
||||
@ -51,7 +84,7 @@ defmodule AccentTest.CollaboratorNormalizer do
|
||||
|> Enum.map(&Repo.insert!/1)
|
||||
|> Enum.map(&Map.get(&1, :id))
|
||||
|
||||
new_user = Repo.insert!(%User{email: "Test@test.com"})
|
||||
new_user = Factory.insert(User, email: "Test@test.com")
|
||||
|
||||
%User{} = CollaboratorNormalizer.normalize(new_user)
|
||||
|
||||
@ -61,7 +94,7 @@ defmodule AccentTest.CollaboratorNormalizer do
|
||||
end
|
||||
|
||||
test "create without collaborations" do
|
||||
new_user = Repo.insert!(%User{email: "Test@test.com"})
|
||||
new_user = Factory.insert(User, email: "Test@test.com")
|
||||
|
||||
%User{} = CollaboratorNormalizer.normalize(new_user)
|
||||
|
||||
|
@ -5,20 +5,20 @@ defmodule AccentTest.CollaboratorUpdater do
|
||||
alias Accent.Collaborator
|
||||
alias Accent.CollaboratorUpdater
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
|
||||
test "update" do
|
||||
email = "test@test.com"
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "com"})
|
||||
assigner = Repo.insert!(%User{email: "lol@test.com"})
|
||||
project = Factory.insert(Project)
|
||||
assigner = Factory.insert(User)
|
||||
role = "admin"
|
||||
collaborator = Repo.insert!(%Collaborator{role: role, assigner: assigner, project: project, email: email})
|
||||
|
||||
collaborator =
|
||||
Factory.insert(Collaborator, role: role, assigner_id: assigner.id, project_id: project.id, email: assigner.email)
|
||||
|
||||
{:ok, updated_collaborator} = CollaboratorUpdater.update(collaborator, %{"role" => "reviewer"})
|
||||
|
||||
assert updated_collaborator.email === collaborator.email
|
||||
assert updated_collaborator.assigner_id === collaborator.assigner.id
|
||||
assert updated_collaborator.assigner_id === collaborator.assigner_id
|
||||
assert updated_collaborator.role === "reviewer"
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
defmodule AccentTest.IntegrationManager do
|
||||
@moduledoc false
|
||||
use Accent.RepoCase, async: true
|
||||
use Accent.RepoCase, async: false
|
||||
|
||||
import Mock
|
||||
|
||||
@ -17,11 +17,19 @@ defmodule AccentTest.IntegrationManager do
|
||||
|
||||
describe "execute" do
|
||||
setup do
|
||||
project = Repo.insert!(%Project{main_color: "red", name: "com"})
|
||||
user = Repo.insert!(%User{email: "test@test.com"})
|
||||
language = Repo.insert!(%Language{slug: "fr-custom", name: "Fr"})
|
||||
revision = Repo.insert!(%Revision{project: project, language: language})
|
||||
document = Repo.insert!(%Document{project: project, path: "foo", format: "gettext"})
|
||||
project = Factory.insert(Project)
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language, slug: "fr-custom")
|
||||
|
||||
revision =
|
||||
Factory.insert(Revision,
|
||||
master: true,
|
||||
master_revision_id: nil,
|
||||
project_id: project.id,
|
||||
language_id: language.id
|
||||
)
|
||||
|
||||
document = Factory.insert(Document, project_id: project.id, path: "foo", format: "gettext")
|
||||
|
||||
{:ok, [project: project, user: user, language: language, revision: revision, document: document]}
|
||||
end
|
||||
@ -32,30 +40,30 @@ defmodule AccentTest.IntegrationManager do
|
||||
document: document,
|
||||
project: project
|
||||
} do
|
||||
version = Repo.insert!(%Version{project: project, tag: "1.2.45", name: "vNext", user: user})
|
||||
version = Factory.insert(Version, project_id: project.id, tag: "1.2.45", name: "vNext", user_id: user.id)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
revision: revision,
|
||||
document: document,
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
document_id: document.id,
|
||||
key: "key",
|
||||
corrected_text: "value latest"
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
revision: revision,
|
||||
version: version,
|
||||
document: document,
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
version_id: version.id,
|
||||
document_id: document.id,
|
||||
key: "key",
|
||||
corrected_text: "value v1.2.45"
|
||||
})
|
||||
)
|
||||
|
||||
integration =
|
||||
Repo.insert!(%Integration{
|
||||
project: project,
|
||||
user: user,
|
||||
Factory.insert(Integration,
|
||||
project_id: project.id,
|
||||
user_id: user.id,
|
||||
service: "azure_storage_container",
|
||||
data: %{azure_storage_container_sas: "http://azure.blob.test/container?sas=1234"}
|
||||
})
|
||||
)
|
||||
|
||||
with_mock HTTPoison,
|
||||
put: fn url, {:file, file}, headers ->
|
||||
@ -87,15 +95,20 @@ defmodule AccentTest.IntegrationManager do
|
||||
document: document,
|
||||
project: project
|
||||
} do
|
||||
Repo.insert!(%Translation{revision: revision, document: document, key: "key", corrected_text: "value"})
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
document_id: document.id,
|
||||
key: "key",
|
||||
corrected_text: "value"
|
||||
)
|
||||
|
||||
integration =
|
||||
Repo.insert!(%Integration{
|
||||
project: project,
|
||||
user: user,
|
||||
Factory.insert(Integration,
|
||||
project_id: project.id,
|
||||
user_id: user.id,
|
||||
service: "azure_storage_container",
|
||||
data: %{azure_storage_container_sas: "http://azure.blob.test/container?sas=1234"}
|
||||
})
|
||||
)
|
||||
|
||||
with_mock HTTPoison,
|
||||
put: fn url, body, headers ->
|
||||
|
@ -12,44 +12,43 @@ defmodule AccentTest.OperationBatcher do
|
||||
alias Accent.User
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(%User{})
|
||||
revision = Repo.insert!(%Revision{})
|
||||
|
||||
translation_one =
|
||||
Repo.insert!(%Translation{key: "a", conflicted: true, revision_id: revision.id, revision: revision})
|
||||
|
||||
translation_two =
|
||||
Repo.insert!(%Translation{key: "b", conflicted: true, revision_id: revision.id, revision: revision})
|
||||
user = Factory.insert(User)
|
||||
revision = Factory.insert(Revision)
|
||||
translation_one = Factory.insert(Translation, key: "a", conflicted: true, revision_id: revision.id)
|
||||
translation_two = Factory.insert(Translation, key: "b", conflicted: true, revision_id: revision.id)
|
||||
|
||||
[user: user, revision: revision, translations: [translation_one, translation_two]]
|
||||
end
|
||||
|
||||
test "create batch with close operations", %{user: user, revision: revision, translations: [translation_one, _]} do
|
||||
operations =
|
||||
Enum.map(
|
||||
[
|
||||
%Operation{
|
||||
Factory.insert(Operation,
|
||||
action: "correct_conflict",
|
||||
key: "a",
|
||||
text: "B",
|
||||
translation_id: translation_one.id,
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
inserted_at: DateTime.utc_now()
|
||||
}
|
||||
]
|
||||
|> Enum.map(&Repo.insert!/1)
|
||||
|> Enum.map(&Map.get(&1, :id))
|
||||
)
|
||||
],
|
||||
&Map.get(&1, :id)
|
||||
)
|
||||
|
||||
operation =
|
||||
Repo.insert!(%Operation{
|
||||
Factory.insert(Operation,
|
||||
action: "correct_conflict",
|
||||
key: "a",
|
||||
text: "B",
|
||||
text: "C",
|
||||
translation_id: translation_one.id,
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
inserted_at: DateTime.utc_now()
|
||||
})
|
||||
)
|
||||
|
||||
batch_responses = OperationBatcher.batch(operation)
|
||||
|
||||
@ -74,58 +73,63 @@ defmodule AccentTest.OperationBatcher do
|
||||
translations: [translation_one, translation_two]
|
||||
} do
|
||||
batch_operation =
|
||||
Repo.insert!(%Operation{
|
||||
Factory.insert(Operation,
|
||||
action: "batch_correct_conflict",
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
stats: [%{"count" => 2, "action" => "correct_conflict"}],
|
||||
inserted_at:
|
||||
DateTime.utc_now()
|
||||
|> DateTime.to_naive()
|
||||
|> NaiveDateTime.add(-960, :second)
|
||||
|> DateTime.from_naive!("Etc/UTC")
|
||||
})
|
||||
)
|
||||
|
||||
operations =
|
||||
Enum.map(
|
||||
[
|
||||
%Operation{
|
||||
Factory.insert(Operation,
|
||||
action: "correct_conflict",
|
||||
key: "a",
|
||||
text: "B",
|
||||
translation_id: translation_one.id,
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
batch_operation_id: batch_operation.id,
|
||||
inserted_at:
|
||||
DateTime.utc_now()
|
||||
|> DateTime.to_naive()
|
||||
|> NaiveDateTime.add(-960, :second)
|
||||
|> DateTime.from_naive!("Etc/UTC")
|
||||
},
|
||||
%Operation{
|
||||
),
|
||||
Factory.insert(Operation,
|
||||
action: "correct_conflict",
|
||||
key: "b",
|
||||
text: "C",
|
||||
translation_id: translation_two.id,
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
batch_operation_id: batch_operation.id,
|
||||
inserted_at: DateTime.utc_now()
|
||||
}
|
||||
]
|
||||
|> Enum.map(&Repo.insert!/1)
|
||||
|> Enum.map(&Map.get(&1, :id))
|
||||
)
|
||||
],
|
||||
&Map.get(&1, :id)
|
||||
)
|
||||
|
||||
operation =
|
||||
Repo.insert!(%Operation{
|
||||
Factory.insert(Operation,
|
||||
action: "correct_conflict",
|
||||
key: "a",
|
||||
text: "B",
|
||||
translation_id: translation_one.id,
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
inserted_at: DateTime.utc_now()
|
||||
})
|
||||
)
|
||||
|
||||
batch_responses = Accent.OperationBatcher.batch(operation)
|
||||
|
||||
@ -158,6 +162,7 @@ defmodule AccentTest.OperationBatcher do
|
||||
translation_id: translation_one.id,
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
inserted_at:
|
||||
DateTime.utc_now()
|
||||
|> DateTime.to_naive()
|
||||
@ -171,6 +176,7 @@ defmodule AccentTest.OperationBatcher do
|
||||
translation_id: translation_two.id,
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
inserted_at:
|
||||
DateTime.utc_now()
|
||||
|> DateTime.to_naive()
|
||||
@ -182,15 +188,16 @@ defmodule AccentTest.OperationBatcher do
|
||||
|> Enum.map(&Map.get(&1, :id))
|
||||
|
||||
operation =
|
||||
Repo.insert!(%Operation{
|
||||
Factory.insert(Operation,
|
||||
action: "correct_conflict",
|
||||
key: "a",
|
||||
text: "B",
|
||||
translation_id: translation_one.id,
|
||||
user_id: user.id,
|
||||
revision_id: revision.id,
|
||||
project_id: revision.project_id,
|
||||
inserted_at: DateTime.utc_now()
|
||||
})
|
||||
)
|
||||
|
||||
batch_responses = Accent.OperationBatcher.batch(operation)
|
||||
|
||||
|
@ -10,8 +10,8 @@ defmodule AccentTest.ProjectCreator do
|
||||
require Ecto.Query
|
||||
|
||||
test "create with language and user" do
|
||||
language = Repo.insert!(%Language{name: "french"})
|
||||
user = Repo.insert!(%User{email: "lol@test.com"})
|
||||
language = Factory.insert(Language)
|
||||
user = Factory.insert(User)
|
||||
params = %{"main_color" => "#f00", "name" => "OK", "language_id" => language.id}
|
||||
|
||||
{:ok, project} = ProjectCreator.create(params: params, user: user)
|
||||
@ -23,8 +23,8 @@ defmodule AccentTest.ProjectCreator do
|
||||
end
|
||||
|
||||
test "create owner collaborator" do
|
||||
language = Repo.insert!(%Language{name: "french"})
|
||||
user = Repo.insert!(%User{email: "lol@test.com"})
|
||||
language = Factory.insert(Language)
|
||||
user = Factory.insert(User)
|
||||
params = %{"main_color" => "#f00", "name" => "OK", "language_id" => language.id}
|
||||
|
||||
{:ok, project} = ProjectCreator.create(params: params, user: user)
|
||||
@ -34,8 +34,8 @@ defmodule AccentTest.ProjectCreator do
|
||||
end
|
||||
|
||||
test "create bot collaborator" do
|
||||
language = Repo.insert!(%Language{name: "french"})
|
||||
user = Repo.insert!(%User{email: "lol@test.com"})
|
||||
language = Factory.insert(Language)
|
||||
user = Factory.insert(User)
|
||||
params = %{"main_color" => "#f00", "name" => "OK", "language_id" => language.id}
|
||||
|
||||
{:ok, project} = ProjectCreator.create(params: params, user: user)
|
||||
|
@ -11,13 +11,13 @@ defmodule AccentTest.ProjectDeleter do
|
||||
alias Accent.Revision
|
||||
|
||||
test "delete collaborators and operations" do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "french"})
|
||||
language = Repo.insert!(%Language{slug: "foo", name: "foo"})
|
||||
revision = Repo.insert!(%Revision{language_id: language.id, project_id: project.id})
|
||||
collaborator = Repo.insert!(%Collaborator{project_id: project.id, role: "reviewer"})
|
||||
project = Factory.insert(Project)
|
||||
language = Factory.insert(Language)
|
||||
revision = Factory.insert(Revision, language_id: language.id, project_id: project.id)
|
||||
collaborator = Factory.insert(Collaborator, project_id: project.id, role: "reviewer")
|
||||
|
||||
Repo.insert!(%Operation{project_id: project.id, action: "sync"})
|
||||
Repo.insert!(%Operation{revision_id: revision.id, action: "merge"})
|
||||
Factory.insert(Operation, project_id: project.id, action: "sync")
|
||||
Factory.insert(Operation, project_id: project.id, revision_id: revision.id, action: "merge")
|
||||
|
||||
assert project
|
||||
|> Ecto.assoc(:all_collaborators)
|
||||
|
@ -11,19 +11,19 @@ defmodule AccentTest.RevisionDeleter do
|
||||
alias Accent.Translation
|
||||
|
||||
setup do
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
english_language = Repo.insert!(%Language{name: "english"})
|
||||
project = Factory.insert(Project)
|
||||
french_language = Factory.insert(Language)
|
||||
english_language = Factory.insert(Language)
|
||||
|
||||
master_revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
master_revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
slave_revision =
|
||||
Repo.insert!(%Revision{
|
||||
Factory.insert(Revision,
|
||||
language_id: english_language.id,
|
||||
project_id: project.id,
|
||||
master: false,
|
||||
master_revision_id: master_revision.id
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, [master_revision: master_revision, slave_revision: slave_revision]}
|
||||
end
|
||||
@ -41,7 +41,7 @@ defmodule AccentTest.RevisionDeleter do
|
||||
end
|
||||
|
||||
test "delete operations", %{slave_revision: revision} do
|
||||
operation = Repo.insert!(%Operation{action: "new", key: "a", revision_id: revision.id})
|
||||
operation = Factory.insert(Operation, action: "new", key: "a", revision_id: revision.id)
|
||||
|
||||
Accent.Revisions.DeleteWorker.perform(%Oban.Job{args: %{"revision_id" => revision.id}})
|
||||
|
||||
@ -49,7 +49,7 @@ defmodule AccentTest.RevisionDeleter do
|
||||
end
|
||||
|
||||
test "delete translations", %{slave_revision: revision} do
|
||||
translation = Repo.insert!(%Translation{key: "a", revision_id: revision.id})
|
||||
translation = Factory.insert(Translation, key: "a", revision_id: revision.id)
|
||||
|
||||
Accent.Revisions.DeleteWorker.perform(%Oban.Job{args: %{"revision_id" => revision.id}})
|
||||
|
||||
|
@ -9,19 +9,19 @@ defmodule AccentTest.RevisionMasterPromoter do
|
||||
alias Accent.RevisionManager
|
||||
|
||||
setup do
|
||||
french_language = Repo.insert!(%Language{name: "french"})
|
||||
english_language = Repo.insert!(%Language{name: "english"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
french_language = Factory.insert(Language)
|
||||
english_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
master_revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
master_revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
slave_revision =
|
||||
Repo.insert!(%Revision{
|
||||
Factory.insert(Revision,
|
||||
language_id: english_language.id,
|
||||
project_id: project.id,
|
||||
master: false,
|
||||
master_revision_id: master_revision.id
|
||||
})
|
||||
)
|
||||
|
||||
{:ok, [master_revision: master_revision, slave_revision: slave_revision]}
|
||||
end
|
||||
|
@ -10,11 +10,9 @@ defmodule AccentTest.TranslationsRenderer do
|
||||
alias Accent.TranslationsRenderer
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
language = Repo.insert!(%Language{name: "English", slug: Ecto.UUID.generate()})
|
||||
user = Factory.insert(User)
|
||||
language = Factory.insert(Language)
|
||||
|
||||
{:ok, project} =
|
||||
ProjectCreator.create(params: %{main_color: "#f00", name: "My project", language_id: language.id}, user: user)
|
||||
@ -30,16 +28,16 @@ defmodule AccentTest.TranslationsRenderer do
|
||||
end
|
||||
|
||||
test "render json with filename", %{project: project, revision: revision} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "my-test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "my-test", format: "json")
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "B",
|
||||
corrected_text: "A",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
%{render: render} =
|
||||
TranslationsRenderer.render_translations(%{
|
||||
@ -60,28 +58,25 @@ defmodule AccentTest.TranslationsRenderer do
|
||||
end
|
||||
|
||||
test "render json with runtime error", %{project: project, revision: revision} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "my-test", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "my-test", format: "json")
|
||||
|
||||
translations =
|
||||
Enum.map(
|
||||
[
|
||||
%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a.nested.foo",
|
||||
proposed_text: "B",
|
||||
corrected_text: "A",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
},
|
||||
%Translation{
|
||||
),
|
||||
Factory.insert(Translation,
|
||||
key: "a.nested",
|
||||
proposed_text: "C",
|
||||
corrected_text: "D",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
}
|
||||
],
|
||||
&Repo.insert!/1
|
||||
)
|
||||
]
|
||||
|
||||
%{render: render} =
|
||||
TranslationsRenderer.render_translations(%{
|
||||
@ -97,16 +92,16 @@ defmodule AccentTest.TranslationsRenderer do
|
||||
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
test "render rails with locale", %{project: project, revision: revision} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "my-test", format: "rails_yml"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "my-test", format: "rails_yml")
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
%{render: render} =
|
||||
TranslationsRenderer.render_translations(%{
|
||||
@ -128,16 +123,16 @@ defmodule AccentTest.TranslationsRenderer do
|
||||
|
||||
test "render xliff and revision overrides on source revision", %{project: project, revision: revision} do
|
||||
revision = Repo.update!(Ecto.Changeset.change(revision, %{slug: "testtest"}))
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "my-test", format: "xliff_1_2"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "my-test", format: "xliff_1_2")
|
||||
|
||||
translation =
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
%{render: render} =
|
||||
TranslationsRenderer.render_translations(%{
|
||||
|
@ -12,6 +12,8 @@ defmodule Accent.ChannelCase do
|
||||
# Import conveniences for testing with connections
|
||||
import Phoenix.ChannelTest
|
||||
|
||||
alias Accent.Factory
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint Endpoint
|
||||
|
||||
|
@ -16,8 +16,6 @@ defmodule Accent.ConnCase do
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
alias Accent.Endpoint
|
||||
alias Accent.Repo
|
||||
alias Ecto.Adapters.SQL.Sandbox
|
||||
alias Phoenix.ConnTest
|
||||
|
||||
using do
|
||||
@ -29,18 +27,21 @@ defmodule Accent.ConnCase do
|
||||
import Phoenix.ConnTest
|
||||
import Plug.Conn
|
||||
|
||||
alias Accent.Factory
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint Endpoint
|
||||
end
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Sandbox.checkout(Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Sandbox.mode(Repo, {:shared, self()})
|
||||
end
|
||||
setup_sandbox(tags)
|
||||
|
||||
{:ok, conn: ConnTest.build_conn()}
|
||||
end
|
||||
|
||||
def setup_sandbox(tags) do
|
||||
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Accent.Repo, shared: not tags[:async])
|
||||
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
|
||||
end
|
||||
end
|
||||
|
48
test/support/factory.ex
Normal file
48
test/support/factory.ex
Normal file
@ -0,0 +1,48 @@
|
||||
defmodule Accent.Factory do
|
||||
@moduledoc false
|
||||
use Factori,
|
||||
repo: Accent.Repo,
|
||||
mappings: [
|
||||
Accent.Factory.Mappings.Document,
|
||||
Accent.Factory.Mappings.Operation,
|
||||
Accent.Factory.Mappings.Translation,
|
||||
Accent.Factory.Mappings.Project,
|
||||
Factori.Mapping.Embed,
|
||||
Factori.Mapping.Enum,
|
||||
Factori.Mapping.Faker
|
||||
]
|
||||
|
||||
defmodule Mappings do
|
||||
@moduledoc false
|
||||
defmodule Project do
|
||||
@moduledoc false
|
||||
@behaviour Factori.Mapping
|
||||
|
||||
def match(%{table_name: "projects", name: :locked_file_operations}), do: false
|
||||
end
|
||||
|
||||
defmodule Document do
|
||||
@moduledoc false
|
||||
@behaviour Factori.Mapping
|
||||
|
||||
def match(%{table_name: "documents", name: :format}), do: "json"
|
||||
def match(%{table_name: "documents", name: :path}), do: "translations"
|
||||
end
|
||||
|
||||
defmodule Operation do
|
||||
@moduledoc false
|
||||
@behaviour Factori.Mapping
|
||||
|
||||
def match(%{table_name: "operations", name: :rollbacked}), do: false
|
||||
def match(%{table_name: "operations", name: :batch}), do: false
|
||||
end
|
||||
|
||||
defmodule Translation do
|
||||
@moduledoc false
|
||||
@behaviour Factori.Mapping
|
||||
|
||||
def match(%{table_name: "translations", name: :locked}), do: false
|
||||
def match(%{table_name: "translations", name: :removed}), do: false
|
||||
end
|
||||
end
|
||||
end
|
@ -6,6 +6,8 @@ defmodule Accent.RepoCase do
|
||||
quote do
|
||||
use Oban.Testing, repo: Accent.Repo
|
||||
|
||||
alias Accent.Factory
|
||||
|
||||
def to_worker_args(struct) do
|
||||
struct
|
||||
|> Jason.encode!()
|
||||
@ -15,12 +17,13 @@ defmodule Accent.RepoCase do
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Accent.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Accent.Repo, {:shared, self()})
|
||||
end
|
||||
setup_sandbox(tags)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
def setup_sandbox(tags) do
|
||||
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Accent.Repo, shared: not tags[:async])
|
||||
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,5 @@
|
||||
alias Ecto.Adapters.SQL.Sandbox
|
||||
|
||||
defmodule Accent.FormatterTestHelper do
|
||||
@moduledoc false
|
||||
def test_parse(variant, parser) do
|
||||
@ -50,4 +52,9 @@ defmodule Langue.Expectation.Case do
|
||||
end
|
||||
|
||||
ExUnit.start()
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Accent.Repo, :manual)
|
||||
|
||||
Sandbox.checkout(Accent.Repo)
|
||||
Accent.Factory.bootstrap()
|
||||
Sandbox.checkin(Accent.Repo)
|
||||
|
||||
Sandbox.mode(Accent.Repo, :manual)
|
||||
|
@ -5,15 +5,14 @@ defmodule AccentTest.ProjectChannel do
|
||||
alias Accent.AccessToken
|
||||
alias Accent.Collaborator
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
alias Accent.UserSocket
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(%User{email: "test@test.com"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
user = Factory.insert(User, email: "test@test.com")
|
||||
project = Factory.insert(Project)
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token")
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
socket = socket(UserSocket, "will-autenticated-user", %{})
|
||||
{:ok, socket} = UserSocket.connect(%{"token" => "Bearer #{access_token.token}"}, socket)
|
||||
|
||||
@ -33,8 +32,8 @@ defmodule AccentTest.ProjectChannel do
|
||||
end
|
||||
|
||||
test "join with unauthorized user", %{project: project} do
|
||||
user = Repo.insert!(%User{email: "test2@test.com"})
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token-2"})
|
||||
user = Factory.insert(User, email: "test2@test.com")
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token-2")
|
||||
|
||||
socket = socket(UserSocket, "unauthorized-user", %{})
|
||||
{:ok, socket} = UserSocket.connect(%{"token" => "Bearer #{access_token.token}"}, socket)
|
||||
|
@ -2,12 +2,11 @@ defmodule AccentTest.UserSocket do
|
||||
use Accent.ChannelCase, async: true
|
||||
|
||||
alias Accent.AccessToken
|
||||
alias Accent.Repo
|
||||
alias Accent.User
|
||||
alias Accent.UserSocket
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(%User{email: "test@test.com"})
|
||||
user = Factory.insert(User, email: "test@test.com")
|
||||
|
||||
{:ok, user: user}
|
||||
end
|
||||
@ -20,7 +19,7 @@ defmodule AccentTest.UserSocket do
|
||||
end
|
||||
|
||||
test "connect with valid token", %{user: user} do
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token")
|
||||
|
||||
socket = socket(UserSocket, "nonautenticated-user", %{})
|
||||
{:ok, socket} = UserSocket.connect(%{"token" => "Bearer #{access_token.token}"}, socket)
|
||||
|
@ -4,7 +4,6 @@ defmodule AccentTest.BadgeController do
|
||||
import Mock
|
||||
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
|
||||
defp behave_like_valid_response(response) do
|
||||
assert response.status == 200
|
||||
@ -14,7 +13,7 @@ defmodule AccentTest.BadgeController do
|
||||
|
||||
setup do
|
||||
id = Ecto.UUID.generate()
|
||||
project = Repo.insert!(%Project{id: id, name: "project", main_color: "#f00"})
|
||||
project = Factory.insert(Project, id: id, name: "project", main_color: "#f00")
|
||||
badge_generate_mock = [generate: fn _, _ -> {:ok, "<svg></svg>"} end]
|
||||
|
||||
{:ok, %{project: project, badge_generate_mock: badge_generate_mock}}
|
||||
|
@ -4,34 +4,31 @@ defmodule AccentTest.ExportController do
|
||||
alias Accent.Document
|
||||
alias Accent.Language
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
alias Accent.Translation
|
||||
alias Accent.User
|
||||
alias Accent.Version
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
{:ok, [user: user, project: project, revision: revision, language: french_language]}
|
||||
end
|
||||
|
||||
test "export inline", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
inline_render: true,
|
||||
@ -53,15 +50,15 @@ defmodule AccentTest.ExportController do
|
||||
end
|
||||
|
||||
test "export basic", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
project_id: project.id,
|
||||
@ -82,8 +79,8 @@ defmodule AccentTest.ExportController do
|
||||
end
|
||||
|
||||
test "export unknown language for the project", %{conn: conn, project: project} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
language = Repo.insert!(%Language{name: "chinese", slug: Ecto.UUID.generate()})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
language = Factory.insert(Language)
|
||||
|
||||
params = %{
|
||||
project_id: project.id,
|
||||
@ -98,24 +95,24 @@ defmodule AccentTest.ExportController do
|
||||
end
|
||||
|
||||
test "export document", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
other_document = Repo.insert!(%Document{project_id: project.id, path: "test3", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
other_document = Factory.insert(Document, project_id: project.id, path: "test3", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: other_document.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
project_id: project.id,
|
||||
@ -143,25 +140,25 @@ defmodule AccentTest.ExportController do
|
||||
end
|
||||
|
||||
test "export version", %{conn: conn, user: user, project: project, revision: revision, language: language} do
|
||||
version = Repo.insert!(%Version{project_id: project.id, user_id: user.id, name: "Current", tag: "master"})
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
version = Factory.insert(Version, project_id: project.id, user_id: user.id, name: "Current", tag: "master")
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: document.id,
|
||||
version_id: version.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
version: "master",
|
||||
@ -181,25 +178,25 @@ defmodule AccentTest.ExportController do
|
||||
end
|
||||
|
||||
test "export without version", %{conn: conn, user: user, project: project, revision: revision, language: language} do
|
||||
version = Repo.insert!(%Version{project_id: project.id, user_id: user.id, name: "Current", tag: "master"})
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
version = Factory.insert(Version, project_id: project.id, user_id: user.id, name: "Current", tag: "master")
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: document.id,
|
||||
version_id: version.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
project_id: project.id,
|
||||
@ -218,7 +215,7 @@ defmodule AccentTest.ExportController do
|
||||
end
|
||||
|
||||
test "export with unknown version", %{conn: conn, project: project, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
params = %{
|
||||
version: "foo",
|
||||
@ -234,23 +231,23 @@ defmodule AccentTest.ExportController do
|
||||
end
|
||||
|
||||
test "export with order", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
order_by: "key",
|
||||
@ -271,25 +268,25 @@ defmodule AccentTest.ExportController do
|
||||
end
|
||||
|
||||
test "export with default order", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id,
|
||||
file_index: 2
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: document.id,
|
||||
file_index: 1
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
order_by: "",
|
||||
@ -312,25 +309,25 @@ defmodule AccentTest.ExportController do
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
test "export with language overrides", %{conn: conn, project: project, revision: revision} do
|
||||
revision = Repo.update!(Ecto.Changeset.change(revision, %{slug: "testtest"}))
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "rails_yml"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "rails_yml")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id,
|
||||
file_index: 2
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: document.id,
|
||||
file_index: 1
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
order_by: "",
|
||||
@ -356,9 +353,9 @@ defmodule AccentTest.ExportController do
|
||||
revision: revision,
|
||||
language: language
|
||||
} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test", format: "android_xml"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test", format: "android_xml")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "days.one",
|
||||
corrected_text: "bar",
|
||||
@ -366,9 +363,9 @@ defmodule AccentTest.ExportController do
|
||||
plural: true,
|
||||
document_id: document.id,
|
||||
file_index: 2
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "days.other",
|
||||
corrected_text: "foo",
|
||||
@ -376,7 +373,7 @@ defmodule AccentTest.ExportController do
|
||||
plural: true,
|
||||
document_id: document.id,
|
||||
file_index: 1
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
order_by: "",
|
||||
|
@ -4,33 +4,30 @@ defmodule AccentTest.ExportJIPTController do
|
||||
alias Accent.Document
|
||||
alias Accent.Language
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
alias Accent.Translation
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
{:ok, [user: user, project: project, revision: revision, language: french_language]}
|
||||
end
|
||||
|
||||
test "export inline", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
inline_render: true,
|
||||
@ -52,15 +49,15 @@ defmodule AccentTest.ExportJIPTController do
|
||||
end
|
||||
|
||||
test "export basic", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
project_id: project.id,
|
||||
@ -81,24 +78,24 @@ defmodule AccentTest.ExportJIPTController do
|
||||
end
|
||||
|
||||
test "export document", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
other_document = Repo.insert!(%Document{project_id: project.id, path: "test3", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
other_document = Factory.insert(Document, project_id: project.id, path: "test3", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: other_document.id
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
project_id: project.id,
|
||||
@ -129,25 +126,25 @@ defmodule AccentTest.ExportJIPTController do
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
test "export with language overrides", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
revision = Repo.update!(Ecto.Changeset.change(revision, %{slug: "testtest"}))
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "rails_yml"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "rails_yml")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "ok",
|
||||
corrected_text: "bar",
|
||||
proposed_text: "bar",
|
||||
document_id: document.id,
|
||||
file_index: 2
|
||||
})
|
||||
)
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
corrected_text: "foo",
|
||||
proposed_text: "foo",
|
||||
document_id: document.id,
|
||||
file_index: 1
|
||||
})
|
||||
)
|
||||
|
||||
params = %{
|
||||
order_by: "",
|
||||
|
@ -5,17 +5,14 @@ defmodule AccentTest.FormatController do
|
||||
alias Accent.Document
|
||||
alias Accent.Language
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
alias Accent.Translation
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
{:ok, [user: user, project: project, access_token: access_token]}
|
||||
end
|
||||
@ -74,8 +71,8 @@ defmodule AccentTest.FormatController do
|
||||
end
|
||||
|
||||
test "format order_by same as export", %{conn: conn, project: project, access_token: access_token} do
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
french_language = Factory.insert(Language)
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "application/json",
|
||||
@ -97,7 +94,7 @@ defmodule AccentTest.FormatController do
|
||||
|> put_req_header("authorization", "Bearer #{access_token.token}")
|
||||
|> post(format_path(conn, :format), body)
|
||||
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "ordering", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "ordering", format: "json")
|
||||
|
||||
params = %{
|
||||
order_by: "key",
|
||||
@ -110,13 +107,13 @@ defmodule AccentTest.FormatController do
|
||||
content = Jason.decode!(File.read!(file.path))
|
||||
|
||||
for {key, value} <- content do
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: key,
|
||||
corrected_text: value,
|
||||
proposed_text: value,
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
export_response =
|
||||
|
@ -6,30 +6,27 @@ defmodule AccentTest.LintController do
|
||||
alias Accent.Document
|
||||
alias Accent.Language
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
def file(filename \\ "simple.json") do
|
||||
%Plug.Upload{content_type: "application/json", filename: filename, path: "test/support/formatter/json/lint.json"}
|
||||
end
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token")
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
{:ok, [access_token: access_token, user: user, project: project, revision: revision, language: french_language]}
|
||||
end
|
||||
|
||||
test "lint document", %{access_token: access_token, conn: conn, project: project, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
|
@ -9,29 +9,26 @@ defmodule AccentTest.MergeControllerMock do
|
||||
alias Accent.Document
|
||||
alias Accent.Language
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
def file(filename \\ "simple.json") do
|
||||
%Plug.Upload{content_type: "application/json", filename: filename, path: "test/support/formatter/json/simple.json"}
|
||||
end
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token")
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
{:ok, [access_token: access_token, project: project, language: french_language]}
|
||||
end
|
||||
|
||||
test "sync with failure", %{access_token: access_token, conn: conn, project: project, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
|
@ -14,20 +14,18 @@ defmodule AccentTest.MergeController do
|
||||
alias Accent.Translation
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
def file(filename \\ "simple.json") do
|
||||
%Plug.Upload{content_type: "application/json", filename: filename, path: "test/support/formatter/json/simple.json"}
|
||||
end
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token")
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
{:ok, [access_token: access_token, user: user, project: project, revision: revision, language: french_language]}
|
||||
end
|
||||
@ -40,16 +38,16 @@ defmodule AccentTest.MergeController do
|
||||
revision: revision,
|
||||
language: language
|
||||
} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
@ -83,16 +81,16 @@ defmodule AccentTest.MergeController do
|
||||
revision: revision,
|
||||
language: language
|
||||
} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
@ -125,16 +123,16 @@ defmodule AccentTest.MergeController do
|
||||
revision: revision,
|
||||
language: language
|
||||
} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "modified",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
@ -171,16 +169,16 @@ defmodule AccentTest.MergeController do
|
||||
revision: revision,
|
||||
language: language
|
||||
} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
|
@ -6,40 +6,37 @@ defmodule AccentTest.PeekController do
|
||||
alias Accent.Document
|
||||
alias Accent.Language
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
alias Accent.Translation
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
def file(filename \\ "simple.json") do
|
||||
%Plug.Upload{content_type: "application/json", filename: filename, path: "test/support/formatter/json/simple.json"}
|
||||
end
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token")
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
revision = Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
revision = Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
|
||||
{:ok, [access_token: access_token, user: user, project: project, revision: revision, language: french_language]}
|
||||
end
|
||||
|
||||
test "merge", %{access_token: access_token, conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
@ -74,16 +71,16 @@ defmodule AccentTest.PeekController do
|
||||
revision: revision,
|
||||
language: language
|
||||
} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
@ -118,16 +115,16 @@ defmodule AccentTest.PeekController do
|
||||
revision: revision,
|
||||
language: language
|
||||
} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
@ -155,16 +152,16 @@ defmodule AccentTest.PeekController do
|
||||
revision: revision,
|
||||
language: language
|
||||
} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: false,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
@ -194,16 +191,16 @@ defmodule AccentTest.PeekController do
|
||||
end
|
||||
|
||||
test "sync", %{access_token: access_token, conn: conn, project: project, revision: revision, language: language} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "test2", format: "json"})
|
||||
document = Factory.insert(Document, project_id: project.id, path: "test2", format: "json")
|
||||
|
||||
Repo.insert!(%Translation{
|
||||
Factory.insert(Translation,
|
||||
revision_id: revision.id,
|
||||
key: "test",
|
||||
conflicted: true,
|
||||
corrected_text: "initial",
|
||||
proposed_text: "initial",
|
||||
document_id: document.id
|
||||
})
|
||||
)
|
||||
|
||||
body = %{
|
||||
file: file(),
|
||||
|
@ -8,24 +8,21 @@ defmodule AccentTest.SyncControllerMock do
|
||||
alias Accent.Collaborator
|
||||
alias Accent.Language
|
||||
alias Accent.Project
|
||||
alias Accent.Repo
|
||||
alias Accent.Revision
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
def file(filename \\ "simple.json") do
|
||||
%Plug.Upload{content_type: "application/json", filename: filename, path: "test/support/formatter/json/simple.json"}
|
||||
end
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token")
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
{:ok, [access_token: access_token, project: project, language: french_language]}
|
||||
end
|
||||
|
||||
|
@ -13,20 +13,18 @@ defmodule AccentTest.SyncController do
|
||||
alias Accent.Revision
|
||||
alias Accent.User
|
||||
|
||||
@user %User{email: "test@test.com"}
|
||||
|
||||
def file(filename \\ "simple.json") do
|
||||
%Plug.Upload{content_type: "application/json", filename: filename, path: "test/support/formatter/json/simple.json"}
|
||||
end
|
||||
|
||||
setup do
|
||||
user = Repo.insert!(@user)
|
||||
access_token = Repo.insert!(%AccessToken{user_id: user.id, token: "test-token"})
|
||||
french_language = Repo.insert!(%Language{name: "french", slug: Ecto.UUID.generate()})
|
||||
project = Repo.insert!(%Project{main_color: "#f00", name: "My project"})
|
||||
user = Factory.insert(User)
|
||||
access_token = Factory.insert(AccessToken, user_id: user.id, token: "test-token")
|
||||
french_language = Factory.insert(Language)
|
||||
project = Factory.insert(Project)
|
||||
|
||||
Repo.insert!(%Collaborator{project_id: project.id, user_id: user.id, role: "admin"})
|
||||
Repo.insert!(%Revision{language_id: french_language.id, project_id: project.id, master: true})
|
||||
Factory.insert(Collaborator, project_id: project.id, user_id: user.id, role: "admin")
|
||||
Factory.insert(Revision, language_id: french_language.id, project_id: project.id, master: true)
|
||||
{:ok, [access_token: access_token, user: user, project: project, language: french_language]}
|
||||
end
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -4,6 +4,8 @@ import {action} from '@ember/object';
|
||||
interface Args {
|
||||
errors: any;
|
||||
project: any;
|
||||
bucket: string | null;
|
||||
pathPrefix: string | null;
|
||||
onChangeBucket: (value: string) => void;
|
||||
onChangePathPrefix: (value: string) => void;
|
||||
onChangeRegion: (value: string) => void;
|
||||
|
@ -515,6 +515,7 @@
|
||||
"aws_s3_region": "Region",
|
||||
"aws_s3_access_key_id": "Access Key ID",
|
||||
"aws_s3_secret_access_key": "Secret Access Key",
|
||||
"aws_s3_minimum_policy": "Minimum policy",
|
||||
"url": "URL"
|
||||
},
|
||||
"empty_description": {
|
||||
|
@ -531,6 +531,7 @@
|
||||
"aws_s3_region": "Région",
|
||||
"aws_s3_access_key_id": "Access Key ID",
|
||||
"aws_s3_secret_access_key": "Secret Access Key",
|
||||
"aws_s3_minimum_policy": "Permissions minimums",
|
||||
"url": "URL"
|
||||
},
|
||||
"empty_description": {
|
||||
|
File diff suppressed because one or more lines are too long
@ -39,7 +39,7 @@
|
||||
</div>
|
||||
<div local-class='policy'>
|
||||
<label local-class='policy-title'>
|
||||
Minimum policy
|
||||
{{t 'components.project_settings.integrations.data.aws_s3_minimum_policy'}}
|
||||
</label>
|
||||
|
||||
<div local-class='policy-render'>
|
||||
|
Loading…
Reference in New Issue
Block a user