Skip to content

Commit e4b02bf

Browse files
authored
FEATURE: added reorder_categories (#256)
added reorder_categories calling /categories/reorder endpoint
1 parent d99dc6a commit e4b02bf

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/discourse_api/api/categories.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def update_category(args = {})
6868
response["body"]["category"] if response["body"]
6969
end
7070

71+
def reorder_categories(args = {})
72+
params = API.params(args).required(:mapping)
73+
post("/categories/reorder", params)
74+
end
75+
7176
def delete_category(id)
7277
response = delete("/categories/#{id}")
7378
response[:body]["success"]

spec/discourse_api/api/categories_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,28 @@
182182
end
183183
end
184184

185+
describe "#reorder_categories" do
186+
before do
187+
stub_post("#{host}/categories/reorder").to_return(
188+
body: fixture("notification_success.json"),
189+
headers: {
190+
content_type: "application/json",
191+
},
192+
)
193+
end
194+
195+
it "makes a categories reordering request" do
196+
payload = { "1": 2, "2": 3, "3": 4, "4": 1 }
197+
response = subject.reorder_categories(mapping: payload.to_json)
198+
expect(
199+
a_post("#{host}/categories/reorder").with(
200+
body: "mapping=#{CGI.escape(payload.to_json.to_s)}",
201+
),
202+
).to have_been_made
203+
expect(response["success"]).to eq("OK")
204+
end
205+
end
206+
185207
describe "#category_set_user_notification" do
186208
before do
187209
stub_post("#{host}/category/1/notifications").to_return(

0 commit comments

Comments
 (0)