discourse/plugins/discourse-topic-voting/test/javascripts/acceptance/category-edit-test.js
Natalie Tay 105aa3213a
FIX: Remove topic voting custom field from category logs when there is no change (#36832)
Currently, when the topic voting plugin is enabled, in staff action logs
for "change category settings"
(`/admin/logs/staff_action_logs?filters=%7B"action_name"%3A"change_category_settings"%2C"action_id"%3A26%7D`),
we keep seeing this even though there are no changes to topic voting.

This commit prevents the custom field from being logged when there is no
real change.
2025-12-22 21:29:32 +08:00

58 lines
1.8 KiB
JavaScript
Vendored

import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import pretender from "discourse/tests/helpers/create-pretender";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Category Edit | Topic Voting", function (needs) {
needs.user();
needs.settings({ topic_voting_enabled: true });
test("Enabling topic voting sends boolean true", async function (assert) {
await visit("/c/bug/edit/settings");
await click(".enable-topic-voting input[type='checkbox']");
await click("#save-category");
const payload = JSON.parse(
pretender.handledRequests[pretender.handledRequests.length - 1]
.requestBody
);
assert.true(
payload.custom_fields.enable_topic_voting,
"enable_topic_voting should be boolean true"
);
});
test("Disabling topic voting sends boolean false", async function (assert) {
await visit("/c/bug/edit/settings");
// twice to toggle false
await click(".enable-topic-voting input[type='checkbox']");
await click(".enable-topic-voting input[type='checkbox']");
await click("#save-category");
const payload = JSON.parse(
pretender.handledRequests[pretender.handledRequests.length - 1]
.requestBody
);
assert.false(
payload.custom_fields.enable_topic_voting,
"enable_topic_voting should be boolean false"
);
});
test("Modifying other settings does not include enable_topic_voting", async function (assert) {
await visit("/c/bug/edit/settings");
await click("#save-category");
const payload = JSON.parse(
pretender.handledRequests[pretender.handledRequests.length - 1]
.requestBody
);
assert.strictEqual(
payload.custom_fields?.enable_topic_voting,
undefined,
"enable_topic_voting should not be in payload when not modified"
);
});
});