mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:52:45 +08:00
FIX: call UserBadge.grant with badgeReason in admin interface (#23753)
Regression from https://github.com/discourse/discourse/pull/23668 where we stopped passing in `this.badgeReason` to the badge granting function. This PR fixes that and adds a unit test to cover that code path.
This commit is contained in:
parent
790f6b1121
commit
bfe078c520
|
@ -73,8 +73,13 @@ export default class AdminUserBadgesController extends Controller {
|
|||
|
||||
@action
|
||||
performGrantBadge() {
|
||||
UserBadge.grant(this.selectedBadgeId, this.get("user.username")).then(
|
||||
UserBadge.grant(
|
||||
this.selectedBadgeId,
|
||||
this.get("user.username"),
|
||||
this.badgeReason
|
||||
).then(
|
||||
(newBadge) => {
|
||||
this.set("badgeReason", "");
|
||||
this.userBadges.pushObject(newBadge);
|
||||
next(() => {
|
||||
// Update the selected badge ID after the combobox has re-rendered.
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { module, test } from "qunit";
|
||||
import { setupTest } from "ember-qunit";
|
||||
import Badge from "discourse/models/badge";
|
||||
import UserBadge from "discourse/models/user-badge";
|
||||
import { settled } from "@ember/test-helpers";
|
||||
import sinon from "sinon";
|
||||
|
||||
module("Unit | Controller | admin-user-badges", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
@ -58,4 +61,55 @@ module("Unit | Controller | admin-user-badges", function (hooks) {
|
|||
);
|
||||
assert.deepEqual(badgeNames, sortedNames, "sorts badges by name");
|
||||
});
|
||||
|
||||
test("performGrantBadge", async function (assert) {
|
||||
const GrantBadgeStub = sinon.stub(UserBadge, "grant");
|
||||
const controller = this.owner.lookup("controller:admin-user-badges");
|
||||
const store = this.owner.lookup("service:store");
|
||||
|
||||
const badgeToGrant = store.createRecord("badge", {
|
||||
id: 3,
|
||||
name: "Granted Badge",
|
||||
enabled: true,
|
||||
manually_grantable: true,
|
||||
});
|
||||
|
||||
const otherBadge = store.createRecord("badge", {
|
||||
id: 4,
|
||||
name: "Other Badge",
|
||||
enabled: true,
|
||||
manually_grantable: true,
|
||||
});
|
||||
|
||||
const badgeReason = "Test Reason";
|
||||
|
||||
const user = { username: "jb", name: "jack black", id: 42 };
|
||||
|
||||
controller.setProperties({
|
||||
model: [],
|
||||
adminUser: { model: user },
|
||||
badgeReason,
|
||||
selectedBadgeId: badgeToGrant.id,
|
||||
badges: [badgeToGrant, otherBadge],
|
||||
});
|
||||
|
||||
const newUserBadge = store.createRecord("badge", {
|
||||
id: 88,
|
||||
badge_id: badgeToGrant.id,
|
||||
user_id: user.id,
|
||||
});
|
||||
|
||||
GrantBadgeStub.returns(Promise.resolve(newUserBadge));
|
||||
controller.performGrantBadge();
|
||||
await settled();
|
||||
|
||||
assert.ok(
|
||||
GrantBadgeStub.calledWith(badgeToGrant.id, user.username, badgeReason)
|
||||
);
|
||||
|
||||
assert.equal(controller.badgeReason, "");
|
||||
assert.equal(controller.userBadges.length, 1);
|
||||
assert.equal(controller.userBadges[0].id, newUserBadge.id);
|
||||
assert.equal(controller.selectedBadgeId, otherBadge.id);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user