Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
6cbe6372
Commit
6cbe6372
authored
Jan 09, 2019
by
minibikini
Browse files
improve tests
parent
44a1e694
Changes
2
Hide whitespace changes
Inline
Side-by-side
test/web/common_api/common_api_test.exs
View file @
6cbe6372
# Pleroma: A lightweight social networking server
# Copyright © 2017-201
8
Pleroma Authors <https://pleroma.social/>
# Copyright © 2017-201
9
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
Web
.
CommonAPI
.
Test
do
...
...
@@ -98,30 +98,26 @@ test "favoriting a status twice returns an error" do
end
describe
"pinned statuses"
do
test
"pin status"
do
setup
do
Pleroma
.
Config
.
put
([
:instance
,
:max_pinned_statuses
],
1
)
user
=
insert
(
:user
)
user
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
as
ser
t
{
:ok
,
^
activity
}
=
CommonAPI
.
pin
(
activity
.
id
,
user
)
[
u
ser
:
user
,
activity
:
activity
]
end
test
"only self-authored can be pinned"
do
Pleroma
.
Config
.
put
([
:instance
,
:max_pinned_statuses
],
1
)
user_one
=
insert
(
:user
)
user_two
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
user_one
,
%{
"status"
=>
"HI!!!"
})
assert
{
:error
,
"Could not pin"
}
=
CommonAPI
.
pin
(
activity
.
id
,
user_two
)
test
"pin status"
,
%{
user:
user
,
activity:
activity
}
do
assert
{
:ok
,
^
activity
}
=
CommonAPI
.
pin
(
activity
.
id
,
user
)
end
test
"max pinned statuses"
do
Pleroma
.
Config
.
put
([
:instance
,
:max_pinned_statuses
],
1
)
test
"only self-authored can be pinned"
,
%{
activity:
activity
}
do
user
=
insert
(
:user
)
{
:ok
,
activity_one
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
assert
{
:error
,
"Could not pin"
}
=
CommonAPI
.
pin
(
activity
.
id
,
user
)
end
test
"max pinned statuses"
,
%{
user:
user
,
activity:
activity_one
}
do
{
:ok
,
activity_two
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
assert
{
:ok
,
^
activity_one
}
=
CommonAPI
.
pin
(
activity_one
.
id
,
user
)
...
...
@@ -132,11 +128,7 @@ test "max pinned statuses" do
CommonAPI
.
pin
(
activity_two
.
id
,
user
)
end
test
"unpin status"
do
Pleroma
.
Config
.
put
([
:instance
,
:max_pinned_statuses
],
1
)
user
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
test
"unpin status"
,
%{
user:
user
,
activity:
activity
}
do
{
:ok
,
activity
}
=
CommonAPI
.
pin
(
activity
.
id
,
user
)
assert
{
:ok
,
^
activity
}
=
CommonAPI
.
unpin
(
activity
.
id
,
user
)
...
...
test/web/mastodon_api/mastodon_api_controller_test.exs
View file @
6cbe6372
# Pleroma: A lightweight social networking server
# Copyright © 2017-201
8
Pleroma Authors <https://pleroma.social/>
# Copyright © 2017-201
9
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma
.
Web
.
MastodonAPI
.
MastodonAPIControllerTest
do
...
...
@@ -1473,88 +1473,74 @@ test "put settings", %{conn: conn} do
end
describe
"pinned statuses"
do
test
"returns pinned statuses"
,
%{
conn:
conn
}
do
setup
do
Pleroma
.
Config
.
put
([
:instance
,
:max_pinned_statuses
],
1
)
user
=
insert
(
:user
)
user
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
[
user:
user
,
activity:
activity
]
end
test
"returns pinned statuses"
,
%{
conn:
conn
,
user:
user
,
activity:
activity
}
do
{
:ok
,
_
}
=
CommonAPI
.
pin
(
activity
.
id
,
user
)
result
=
conn
|>
assign
(
:user
,
user
)
|>
get
(
"/api/v1/accounts/
#{
user
.
id
}
/statuses?pinned=true"
)
|>
Map
.
get
(
:resp_body
)
|>
Jason
.
decode!
()
|>
json_response
(
200
)
id_str
=
Integer
.
to_string
(
activity
.
id
)
id_str
=
to_string
(
activity
.
id
)
assert
[%{
"id"
=>
^
id_str
,
"pinned"
=>
true
}]
=
result
end
test
"pin status"
,
%{
conn:
conn
}
do
Pleroma
.
Config
.
put
([
:instance
,
:max_pinned_statuses
],
1
)
user
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
id_str
=
Integer
.
to_string
(
activity
.
id
)
test
"pin status"
,
%{
conn:
conn
,
user:
user
,
activity:
activity
}
do
id_str
=
to_string
(
activity
.
id
)
assert
%{
"id"
=>
^
id_str
,
"pinned"
=>
true
}
=
conn
|>
assign
(
:user
,
user
)
|>
post
(
"/api/v1/statuses/
#{
activity
.
id
}
/pin"
)
|>
Map
.
get
(
:resp_body
)
|>
Jason
.
decode!
()
|>
json_response
(
200
)
assert
[%{
"id"
=>
^
id_str
,
"pinned"
=>
true
}]
=
conn
|>
assign
(
:user
,
user
)
|>
get
(
"/api/v1/accounts/
#{
user
.
id
}
/statuses?pinned=true"
)
|>
Map
.
get
(
:resp_body
)
|>
Jason
.
decode!
()
|>
json_response
(
200
)
end
test
"unpin status"
,
%{
conn:
conn
}
do
Pleroma
.
Config
.
put
([
:instance
,
:max_pinned_statuses
],
1
)
user
=
insert
(
:user
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
test
"unpin status"
,
%{
conn:
conn
,
user:
user
,
activity:
activity
}
do
{
:ok
,
_
}
=
CommonAPI
.
pin
(
activity
.
id
,
user
)
id_str
=
Integer
.
to_string
(
activity
.
id
)
id_str
=
to_string
(
activity
.
id
)
user
=
refresh_record
(
user
)
assert
%{
"id"
=>
^
id_str
,
"pinned"
=>
false
}
=
conn
|>
assign
(
:user
,
user
)
|>
post
(
"/api/v1/statuses/
#{
activity
.
id
}
/unpin"
)
|>
Map
.
get
(
:resp_body
)
|>
Jason
.
decode!
()
|>
json_response
(
200
)
assert
[]
=
conn
|>
assign
(
:user
,
user
)
|>
get
(
"/api/v1/accounts/
#{
user
.
id
}
/statuses?pinned=true"
)
|>
Map
.
get
(
:resp_body
)
|>
Jason
.
decode!
()
|>
json_response
(
200
)
end
test
"max pinned statuses"
,
%{
conn:
conn
}
do
Pleroma
.
Config
.
put
([
:instance
,
:max_pinned_statuses
],
1
)
user
=
insert
(
:user
)
{
:ok
,
activity_one
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
test
"max pinned statuses"
,
%{
conn:
conn
,
user:
user
,
activity:
activity_one
}
do
{
:ok
,
activity_two
}
=
CommonAPI
.
post
(
user
,
%{
"status"
=>
"HI!!!"
})
id_str_one
=
Integer
.
to_string
(
activity_one
.
id
)
id_str_one
=
to_string
(
activity_one
.
id
)
assert
%{
"id"
=>
^
id_str_one
,
"pinned"
=>
true
}
=
conn
|>
assign
(
:user
,
user
)
|>
post
(
"/api/v1/statuses/
#{
id_str_one
}
/pin"
)
|>
Map
.
get
(
:resp_body
)
|>
Jason
.
decode!
()
|>
json_response
(
200
)
user
=
refresh_record
(
user
)
...
...
@@ -1562,8 +1548,7 @@ test "max pinned statuses", %{conn: conn} do
conn
|>
assign
(
:user
,
user
)
|>
post
(
"/api/v1/statuses/
#{
activity_two
.
id
}
/pin"
)
|>
Map
.
get
(
:resp_body
)
|>
Jason
.
decode!
()
|>
json_response
(
400
)
end
end
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment