Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ivan Tashkinov
pleroma
Commits
a9181ec7
Verified
Commit
a9181ec7
authored
6 years ago
by
Lee Starnes
Committed by
Haelwenn
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Ensure filters have a filter_id
Closes #313
parent
b0238500
Branches
bugfix/filter_id
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/filter_test.exs
+80
-11
80 additions, 11 deletions
test/filter_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs
+2
-0
2 additions, 0 deletions
test/web/mastodon_api/mastodon_api_controller_test.exs
with
82 additions
and
11 deletions
test/filter_test.exs
+
80
−
11
View file @
a9181ec7
...
...
@@ -5,19 +5,88 @@ defmodule Pleroma.FilterTest do
import
Pleroma
.
Factory
import
Ecto
.
Query
test
"creating a filter"
do
user
=
insert
(
:user
)
describe
"creating filters"
do
test
"creating one filter"
do
user
=
insert
(
:user
)
query
=
%
Pleroma
.
Filter
{
user_id:
user
.
id
,
filter_id:
42
,
phrase:
"knights"
,
context:
[
"home"
]
}
query
=
%
Pleroma
.
Filter
{
user_id:
user
.
id
,
filter_id:
42
,
phrase:
"knights"
,
context:
[
"home"
]
}
{
:ok
,
%
Pleroma
.
Filter
{}
=
filter
}
=
Pleroma
.
Filter
.
create
(
query
)
result
=
Pleroma
.
Filter
.
get
(
filter
.
filter_id
,
user
)
assert
query
.
phrase
==
result
.
phrase
end
test
"creating one filter without a pre-defined filter_id"
do
user
=
insert
(
:user
)
query
=
%
Pleroma
.
Filter
{
user_id:
user
.
id
,
phrase:
"knights"
,
context:
[
"home"
]
}
{
:ok
,
%
Pleroma
.
Filter
{}
=
filter
}
=
Pleroma
.
Filter
.
create
(
query
)
# Should start at 1
assert
filter
.
filter_id
==
1
end
test
"creating additional filters uses previous highest filter_id + 1"
do
user
=
insert
(
:user
)
query_one
=
%
Pleroma
.
Filter
{
user_id:
user
.
id
,
filter_id:
42
,
phrase:
"knights"
,
context:
[
"home"
]
}
{
:ok
,
%
Pleroma
.
Filter
{}
=
filter_one
}
=
Pleroma
.
Filter
.
create
(
query_one
)
query_two
=
%
Pleroma
.
Filter
{
user_id:
user
.
id
,
# No filter_id
phrase:
"who"
,
context:
[
"home"
]
}
{
:ok
,
%
Pleroma
.
Filter
{}
=
filter_two
}
=
Pleroma
.
Filter
.
create
(
query_two
)
assert
filter_two
.
filter_id
==
filter_one
.
filter_id
+
1
end
test
"filter_id is unique per user"
do
user_one
=
insert
(
:user
)
user_two
=
insert
(
:user
)
query_one
=
%
Pleroma
.
Filter
{
user_id:
user_one
.
id
,
phrase:
"knights"
,
context:
[
"home"
]
}
{
:ok
,
%
Pleroma
.
Filter
{}
=
filter_one
}
=
Pleroma
.
Filter
.
create
(
query_one
)
query_two
=
%
Pleroma
.
Filter
{
user_id:
user_two
.
id
,
phrase:
"who"
,
context:
[
"home"
]
}
{
:ok
,
%
Pleroma
.
Filter
{}
=
filter_two
}
=
Pleroma
.
Filter
.
create
(
query_two
)
assert
filter_one
.
filter_id
==
1
assert
filter_two
.
filter_id
==
1
result_one
=
Pleroma
.
Filter
.
get
(
filter_one
.
filter_id
,
user_one
)
assert
result_one
.
phrase
==
filter_one
.
phrase
{
:ok
,
%
Pleroma
.
Filter
{}
=
filter
}
=
Pleroma
.
Filter
.
create
(
query
)
result
=
Pleroma
.
Filter
.
get
(
filter
.
filter_id
,
user
)
assert
query
.
phrase
==
result
.
phrase
result_two
=
Pleroma
.
Filter
.
get
(
filter
_two
.
filter_id
,
user_two
)
assert
result_two
.
phrase
==
filter_two
.
phrase
end
end
test
"deleting a filter"
do
...
...
This diff is collapsed.
Click to expand it.
test/web/mastodon_api/mastodon_api_controller_test.exs
+
2
−
0
View file @
a9181ec7
...
...
@@ -280,6 +280,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert
response
=
json_response
(
conn
,
200
)
assert
response
[
"phrase"
]
==
filter
.
phrase
assert
response
[
"context"
]
==
filter
.
context
assert
response
[
"id"
]
!=
nil
assert
response
[
"id"
]
!=
""
end
test
"fetching a list of filters"
,
%{
conn:
conn
}
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment