Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add test to check if user tips are saved once (#19084)

Bianca Nenciu3ec7b2a76935
diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js
index 1843ce0d467..ad38126f8e4 100644
--- a/app/assets/javascripts/discourse/app/models/user.js
+++ b/app/assets/javascripts/discourse/app/models/user.js
@@ -447,18 +447,21 @@ const User = RestModel.extend({
type: "PUT",
})
.then((result) => {
- this.set("bio_excerpt", result.user.bio_excerpt);
- const userProps = getProperties(
- result.user.user_option || this.user_option,
- "enable_quoting",
- "enable_defer",
- "external_links_in_new_tab",
- "dynamic_favicon",
- "seen_popups",
- "skip_new_user_tips"
- );
- User.current()?.setProperties(userProps);
this.setProperties(updatedState);
+ this.setProperties(getProperties(result.user, "bio_excerpt"));
+ if (User.current() === this && result.user.user_option) {
+ this.setProperties(
+ getProperties(
+ result.user.user_option,
+ "enable_quoting",
+ "enable_defer",
+ "external_links_in_new_tab",
+ "dynamic_favicon",
+ "seen_popups",
+ "skip_new_user_tips"
+ )
+ );
+ }
return result;
})
.finally(() => {
diff --git a/app/assets/javascripts/discourse/tests/unit/models/user-test.js b/app/assets/javascripts/discourse/tests/unit/models/user-test.js
index 836a1933b03..77b54ab6260 100644
--- a/app/assets/javascripts/discourse/tests/unit/models/user-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/models/user-test.js
@@ -4,6 +4,8 @@ import User from "discourse/models/user";
import PreloadStore from "discourse/lib/preload-store";
import sinon from "sinon";
import { settled } from "@ember/test-helpers";
+import Site from "discourse/models/site";
+import pretender, { response } from "discourse/tests/helpers/create-pretender";
module("Unit | Model | user", function () {
test("staff", function (assert) {
@@ -179,4 +181,27 @@ module("Unit | Model | user", function () {
"_clearStatusTimerId wasn't set"
);
});
+
+ test("hideUserTipForever() makes a single request", async function (assert) {
+ Site.current().set("user_tips", { first_notification: 1 });
+ const user = User.create({ username: "test" });
+
+ let requestsCount = 0;
+ pretender.put("/u/test.json", () => {
+ requestsCount += 1;
+ return response(200, {
+ user: {
+ user_option: {
+ seen_popups: [1],
+ },
+ },
+ });
+ });
+
+ await user.hideUserTipForever("first_notification");
+ assert.strictEqual(requestsCount, 1);
+
+ await user.hideUserTipForever("first_notification");
+ assert.strictEqual(requestsCount, 1);
+ });
});