FIX: Reset likeAction when updating a cached post from JSON data (#29971)

This commit addresses an issue where the like button would not be updated properly when reloading a post that lost the only like it had received.
This commit is contained in:
Sérgio Saquetim 2024-11-28 17:20:20 -03:00 committed by GitHub
parent a710d3f377
commit d3595b6118
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View File

@ -63,6 +63,7 @@ function trackedPostProperty(target, propertyKey, descriptor) {
export default class Post extends RestModel {
static munge(json) {
json.likeAction = null;
if (json.actions_summary) {
const lookup = EmberObject.create();

View File

@ -116,4 +116,21 @@ module("Unit | Model | post", function (hooks) {
);
assert.strictEqual(post.version, 2, "the version number increased");
});
test("likeAction", function (assert) {
const post = this.store.createRecord("post", {
id: 1173,
});
post.likeAction = { count: 1 };
assert.deepEqual(post.likeAction, { count: 1 }, "likeAction set");
// creating a new record with the same id should reset the likeAction in the original post because instance
// is cached and the information required to properly generate the field is not available in the new JSON data
this.store.createRecord("post", {
id: 1173,
});
assert.ok(post.likeAction === null, "likeAction was reset to null");
});
});