FIX: make sure every user instance has correct status tracking counter

This commit is contained in:
Andrei Prigorshnev 2022-07-26 18:42:55 +04:00 committed by GitHub
parent fccbe5c604
commit 47917c0be4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View File

@ -1178,6 +1178,32 @@ User.reopenClass(Singleton, {
},
});
User.reopenClass({
create(args) {
args = args || {};
this.deleteStatusTrackingFields(args);
return this._super(args);
},
deleteStatusTrackingFields(args) {
// every user instance has to have it's own tracking fields
// when creating a new user model
// its _subscribersCount and _clearStatusTimerId fields
// should be equal to 0 and null
// here we makes sure that even if these fields
// will be passed in args they won't be set anyway
//
// this is something that could be implemented by making these fields private,
// but EmberObject doesn't support private fields
if (args.hasOwnProperty("_subscribersCount")) {
delete args._subscribersCount;
}
if (args.hasOwnProperty("_clearStatusTimerId")) {
delete args._clearStatusTimerId;
}
},
});
// user status tracking
User.reopen(Evented, {
_subscribersCount: 0,

View File

@ -163,4 +163,20 @@ module("Unit | Model | user", function () {
user2.stopTrackingStatus();
}
});
test("create() doesn't set internal status tracking fields", function (assert) {
const user = User.create({
_subscribersCount: 10,
_clearStatusTimerId: 100,
});
assert.notOk(
user.hasOwnProperty("_subscribersCount"),
"_subscribersCount wasn't set"
);
assert.notOk(
user.hasOwnProperty("_clearStatusTimerId"),
"_clearStatusTimerId wasn't set"
);
});
});