Skip to content

Commit aee73ea

Browse files
committed
Remove app_version requirment for App Rating
1 parent 7d2c15c commit aee73ea

File tree

7 files changed

+50
-7
lines changed

7 files changed

+50
-7
lines changed

lib/plexus/ratings.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ defmodule Plexus.Ratings do
4949
optional(:notes) => String.t(),
5050
android_version: String.t(),
5151
app_package: String.t(),
52-
app_version: String.t(),
52+
app_version: String.t() | nil,
5353
app_build_number: non_neg_integer(),
5454
rom_name: String.t(),
5555
rom_build: String.t(),

lib/plexus/schemas/rating.ex

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ defmodule Plexus.Schemas.Rating do
2727
@required [
2828
:android_version,
2929
:app_package,
30-
:app_version,
3130
:app_build_number,
3231
:rom_name,
3332
:rom_build,
3433
:rating_type,
3534
:installation_source,
3635
:score
3736
]
38-
@optional [:notes]
37+
@optional [:app_version, :notes]
3938
@doc false
4039
def changeset(%Rating{} = rating, attrs) do
4140
rating

lib/plexus_web/controllers/api/v1/rating_controller.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ defmodule PlexusWeb.API.V1.RatingController do
4343
schema = %{
4444
android_version: {:string, [required: true]},
4545
app_package: {:string, [required: true]},
46-
app_version: {:string, [required: true]},
46+
app_version: {:string, [required: false]},
4747
app_build_number: {:integer, [required: true]},
4848
rom_name: {:string, [required: true]},
4949
rom_build: {:string, [required: true]},

lib/plexus_web/controllers/api/v1/rating_json.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule PlexusWeb.API.V1.RatingJSON do
1919
id: rating.id,
2020
android_version: rating.android_version,
2121
app_package: rating.app_package,
22-
app_version: rating.app_version,
22+
app_version: rating.app_version || "",
2323
app_build_number: rating.app_build_number,
2424
rom_name: rating.rom_name,
2525
rom_build: rating.rom_build,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Plexus.Repo.Migrations.MakeRatingAppVersionNullable do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:ratings) do
6+
modify :app_version, :string, null: true, from: {:string, null: true}
7+
end
8+
end
9+
end

test/plexus/ratings_test.exs

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ defmodule Plexus.RatingsTest do
1010
@invalid_attrs %{
1111
app_package: "",
1212
app_build_number: nil,
13-
app_version: nil,
1413
rating_type: nil,
1514
rom_name: nil,
1615
rom_build: nil,
@@ -64,6 +63,24 @@ defmodule Plexus.RatingsTest do
6463
assert rating.rom_build == "some ROM build"
6564
end
6665

66+
test "handles optional app_version" do
67+
app = app_fixture()
68+
69+
valid_attrs = %{
70+
app_package: app.package,
71+
android_version: "some android_version",
72+
app_build_number: 42,
73+
app_version: nil,
74+
rating_type: :native,
75+
score: 3,
76+
installation_source: "fdroid",
77+
rom_name: "some ROM name",
78+
rom_build: "some ROM build"
79+
}
80+
81+
assert {:ok, %Rating{}} = Ratings.create_rating(valid_attrs)
82+
end
83+
6784
test "invalid data returns error changeset" do
6885
assert {:error, _reason} = Ratings.create_rating(@invalid_attrs)
6986
end

test/plexus_web/controllers/api/v1/rating_controller_test.exs

+19-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ defmodule PlexusWeb.API.V1.RatingControllerTest do
7676
} = json_response(conn, 200)["data"]
7777
end
7878

79+
test "handles null/empty app_verison", %{conn: conn} do
80+
%{package: app_package} = app_fixture()
81+
attrs = Map.put(@create_attrs, :app_package, app_package)
82+
83+
conn =
84+
post(conn, ~p"/api/v1/apps/#{app_package}/ratings",
85+
rating: Map.put(attrs, :app_version, nil)
86+
)
87+
88+
assert %{"app_version" => ""} = json_response(conn, 201)["data"]
89+
90+
conn =
91+
post(conn, ~p"/api/v1/apps/#{app_package}/ratings",
92+
rating: Map.put(attrs, :app_version, "")
93+
)
94+
95+
assert %{"app_version" => ""} = json_response(conn, 201)["data"]
96+
end
97+
7998
test "renders errors when data is invalid", %{conn: conn} do
8099
app = app_fixture()
81100
conn = post(conn, ~p"/api/v1/apps/#{app}/ratings", rating: @invalid_attrs)
@@ -84,7 +103,6 @@ defmodule PlexusWeb.API.V1.RatingControllerTest do
84103
"errors" => %{
85104
"android_version" => ["can't be blank"],
86105
"app_build_number" => ["can't be blank"],
87-
"app_version" => ["can't be blank"],
88106
"rom_name" => ["can't be blank"],
89107
"rom_build" => ["can't be blank"],
90108
"installation_source" => ["can't be blank"],

0 commit comments

Comments
 (0)