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