@quenty/gameproductservice 14.66.4 → 14.66.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +2 -2
- package/src/Shared/Ownership/PlayerAssetOwnershipTracker.lua +49 -0
- package/src/Shared/Ownership/PlayerAssetOwnershipTracker.spec.lua +130 -0
- package/src/Shared/Trackers/PlayerProductManagerBase.lua +64 -7
- package/src/Shared/Trackers/PlayerProductManagerBase.spec.lua +118 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [14.66.5](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.66.4...@quenty/gameproductservice@14.66.5) (2026-07-30)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **gameproductservice:** stop ownership queries spamming the log with failures they cannot avoid ([#778](https://github.com/Quenty/NevermoreEngine/issues/778)) ([2413adb](https://github.com/Quenty/NevermoreEngine/commit/2413adbabcfbd4df3dc639c1ef40ec2ffcfe0571))
|
|
11
|
+
|
|
6
12
|
## [14.66.4](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.66.3...@quenty/gameproductservice@14.66.4) (2026-07-29)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @quenty/gameproductservice
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/gameproductservice",
|
|
3
|
-
"version": "14.66.
|
|
3
|
+
"version": "14.66.5",
|
|
4
4
|
"description": "Generalized monetization system for handling products and purchases correctly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"@quenty/valueobject": "13.36.1",
|
|
65
65
|
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "b985ac16c20fa828f27d98ed3dccbcecdea38f81"
|
|
68
68
|
}
|
|
@@ -110,6 +110,48 @@ function PlayerAssetOwnershipTracker:SetQueryOwnershipCallback(promiseOwnsAsset:
|
|
|
110
110
|
self._ownershipCallback.Value = promiseOwnsAsset
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
+
--[=[
|
|
114
|
+
Names an asset this tracker could not answer for. Reached once per query rather than once per
|
|
115
|
+
consumer of it: every caller and every subscriber attaches its own continuation to the same cached
|
|
116
|
+
query, so a rejection nobody handles is reported once per continuation -- hundreds of anonymous
|
|
117
|
+
"[Promise] - Uncaught exception" lines for one failure.
|
|
118
|
+
|
|
119
|
+
A query never made -- no callback for this realm -- is not reported: the rejection it returns says
|
|
120
|
+
so in full, and a realm that cannot ask is not a fault.
|
|
121
|
+
|
|
122
|
+
@param assetId number
|
|
123
|
+
@param err any
|
|
124
|
+
@private
|
|
125
|
+
]=]
|
|
126
|
+
function PlayerAssetOwnershipTracker._warnQueryFailed(self: any, assetId: number, err: any): ()
|
|
127
|
+
-- An empty rejection is our own teardown cancelling the query, not the query failing.
|
|
128
|
+
if err == nil then
|
|
129
|
+
return
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
warn(
|
|
133
|
+
string.format(
|
|
134
|
+
"[PlayerAssetOwnershipTracker] - Ownership query failed for assetType %q assetId %d: %s",
|
|
135
|
+
tostring(self._assetType),
|
|
136
|
+
assetId,
|
|
137
|
+
tostring(err)
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
--[=[
|
|
143
|
+
Swallows a query failure on behalf of one subscriber. Named rather than inline because it is the
|
|
144
|
+
whole of what stops the noise: [PlayerAssetOwnershipTracker._warnQueryFailed] has already named the
|
|
145
|
+
failure once, and every subscriber after it lands on the same rejection with nothing to add.
|
|
146
|
+
|
|
147
|
+
Nothing is emitted, so the observable stays silent -- unresolved, which is not the same as "does not
|
|
148
|
+
own it".
|
|
149
|
+
|
|
150
|
+
@param _err any
|
|
151
|
+
@private
|
|
152
|
+
]=]
|
|
153
|
+
function PlayerAssetOwnershipTracker._consumeObservedQueryFailure(_self: any, _err: any): () end
|
|
154
|
+
|
|
113
155
|
function PlayerAssetOwnershipTracker:_promiseQueryAssetId(assetId: number): Promise.Promise<boolean>?
|
|
114
156
|
assert(type(assetId) == "number", "Bad assetId")
|
|
115
157
|
|
|
@@ -143,6 +185,11 @@ function PlayerAssetOwnershipTracker:_promiseQueryAssetId(assetId: number): Prom
|
|
|
143
185
|
if ownsItem then
|
|
144
186
|
self:SetOwnership(assetId, true)
|
|
145
187
|
end
|
|
188
|
+
end, function(err)
|
|
189
|
+
-- Reported here, at the one place the query is actually made, and consumed so the failure is
|
|
190
|
+
-- named once rather than once per consumer. Callers still see it: the rejection is handed to
|
|
191
|
+
-- each of them through their own continuation on this promise.
|
|
192
|
+
(self :: any):_warnQueryFailed(assetId, err)
|
|
146
193
|
end)
|
|
147
194
|
|
|
148
195
|
self._assetOwnershipPromiseCache[assetId] = promise
|
|
@@ -366,6 +413,8 @@ function PlayerAssetOwnershipTracker._observeBaseOwnsAssetId(self: any, assetId:
|
|
|
366
413
|
maid:GiveTask(self._ownedAssetIdSet:ObserveContains(assetId):Subscribe(function(value)
|
|
367
414
|
sub:Fire(value)
|
|
368
415
|
end))
|
|
416
|
+
end, function(err)
|
|
417
|
+
self:_consumeObservedQueryFailure(err)
|
|
369
418
|
end)
|
|
370
419
|
|
|
371
420
|
return maid
|
|
@@ -23,6 +23,7 @@ local Promise = require("Promise")
|
|
|
23
23
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
24
24
|
local Signal = require("Signal")
|
|
25
25
|
|
|
26
|
+
local afterEach = Jest.Globals.afterEach
|
|
26
27
|
local describe = Jest.Globals.describe
|
|
27
28
|
local expect = Jest.Globals.expect
|
|
28
29
|
local it = Jest.Globals.it
|
|
@@ -436,6 +437,135 @@ describe("PlayerAssetOwnershipTracker:SetOwnershipOverride() combined keys", fun
|
|
|
436
437
|
end)
|
|
437
438
|
end)
|
|
438
439
|
|
|
440
|
+
describe("PlayerAssetOwnershipTracker query failures", function()
|
|
441
|
+
--[[
|
|
442
|
+
Both seams the tracker handles a failure through, counted rather than watched: `warn` cannot be
|
|
443
|
+
intercepted from here, and an unhandled rejection announces itself in the log rather than to the
|
|
444
|
+
test. So the claim is pinned structurally -- the failure is reported once at the query, and every
|
|
445
|
+
subscriber's continuation is consumed -- which is exactly what deleting either handler undoes.
|
|
446
|
+
|
|
447
|
+
Spied on the class, so an instance built inside `func` is already covered. Restored in afterEach
|
|
448
|
+
as well: a test killed mid-yield would otherwise leave the recorder installed for the whole run.
|
|
449
|
+
]]
|
|
450
|
+
local trackerClass: any = PlayerAssetOwnershipTracker
|
|
451
|
+
local realWarn = trackerClass._warnQueryFailed
|
|
452
|
+
local realConsume = trackerClass._consumeObservedQueryFailure
|
|
453
|
+
|
|
454
|
+
local reports: { any } = {}
|
|
455
|
+
local consumed: { any } = {}
|
|
456
|
+
|
|
457
|
+
local function recordFailureHandling(): ()
|
|
458
|
+
table.clear(reports)
|
|
459
|
+
table.clear(consumed)
|
|
460
|
+
|
|
461
|
+
trackerClass._warnQueryFailed = function(_self, assetId, err)
|
|
462
|
+
table.insert(reports, { assetId = assetId, err = err })
|
|
463
|
+
end
|
|
464
|
+
trackerClass._consumeObservedQueryFailure = function(_self, err)
|
|
465
|
+
table.insert(consumed, err)
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
afterEach(function()
|
|
470
|
+
trackerClass._warnQueryFailed = realWarn
|
|
471
|
+
trackerClass._consumeObservedQueryFailure = realConsume
|
|
472
|
+
end)
|
|
473
|
+
|
|
474
|
+
it("should report once at the query and consume every subscriber's copy", function()
|
|
475
|
+
local context = setup()
|
|
476
|
+
recordFailureHandling()
|
|
477
|
+
|
|
478
|
+
-- Pending until we say otherwise, which is the shape the live failure had: a marketplace call
|
|
479
|
+
-- still out when the subscribers attach. An already-rejected promise would let Then hand back the
|
|
480
|
+
-- parent instead of a child, so no consumer would have a rejection to leave unhandled and the
|
|
481
|
+
-- test would pass with the handlers deleted.
|
|
482
|
+
local pending = Promise.new()
|
|
483
|
+
context.tracker:SetQueryOwnershipCallback(function()
|
|
484
|
+
return pending
|
|
485
|
+
end)
|
|
486
|
+
|
|
487
|
+
local values = {}
|
|
488
|
+
-- Typed `any`: the test place holds more than one copy of Subscription (a package graph
|
|
489
|
+
-- duplicated per dependent), and a list inferred from one copy rejects another.
|
|
490
|
+
local subs: { any } = {}
|
|
491
|
+
for _ = 1, 3 do
|
|
492
|
+
table.insert(
|
|
493
|
+
subs,
|
|
494
|
+
context.tracker:ObserveOwnsAsset(KEY_TO_ID.swordKey):Subscribe(function(value)
|
|
495
|
+
table.insert(values, value)
|
|
496
|
+
end)
|
|
497
|
+
)
|
|
498
|
+
end
|
|
499
|
+
|
|
500
|
+
local asked = context.tracker:PromiseOwnsAsset("swordKey")
|
|
501
|
+
pending:Reject("cloud refused")
|
|
502
|
+
|
|
503
|
+
expect(PromiseTestUtils.awaitSettled(asked, 5)).toEqual(true)
|
|
504
|
+
-- Yielded, not merely awaited: reading the outcome is this caller consuming its own copy, which is
|
|
505
|
+
-- what a real caller does with the promise it asked for. Bound first, because Yield returns the
|
|
506
|
+
-- rejection alongside the outcome and expect takes one argument.
|
|
507
|
+
local askedOk = asked:Yield()
|
|
508
|
+
expect(askedOk).toEqual(false)
|
|
509
|
+
|
|
510
|
+
expect(PromiseTestUtils.awaitValue(function()
|
|
511
|
+
return #consumed >= 3
|
|
512
|
+
end, 5)).toEqual(true)
|
|
513
|
+
|
|
514
|
+
-- One report for the query, one consumption per subscriber.
|
|
515
|
+
expect(#reports).toEqual(1)
|
|
516
|
+
expect(reports[1].assetId).toEqual(KEY_TO_ID.swordKey)
|
|
517
|
+
expect(reports[1].err).toEqual("cloud refused")
|
|
518
|
+
expect(#consumed).toEqual(3)
|
|
519
|
+
|
|
520
|
+
-- An unresolvable asset emits nothing at all: silence reads as unresolved, where `false` would
|
|
521
|
+
-- read as "does not own it" and turn a failed lookup into a refusal.
|
|
522
|
+
expect(#values).toEqual(0)
|
|
523
|
+
|
|
524
|
+
for _, sub in subs do
|
|
525
|
+
sub:Destroy()
|
|
526
|
+
end
|
|
527
|
+
context.destroy()
|
|
528
|
+
end)
|
|
529
|
+
|
|
530
|
+
it("should not report an asset it was never given a callback to query", function()
|
|
531
|
+
local context = setup()
|
|
532
|
+
recordFailureHandling()
|
|
533
|
+
|
|
534
|
+
-- No callback set: this realm cannot ask, rather than having asked and failed, so the rejection
|
|
535
|
+
-- explains itself and nothing is reported.
|
|
536
|
+
local outcome = PromiseTestUtils.awaitOutcome(context.tracker:PromiseOwnsAsset("swordKey"), 5)
|
|
537
|
+
expect(outcome).toEqual("rejected")
|
|
538
|
+
|
|
539
|
+
expect(#reports).toEqual(0)
|
|
540
|
+
context.destroy()
|
|
541
|
+
end)
|
|
542
|
+
|
|
543
|
+
it("should not report a query cancelled by teardown as a failure", function()
|
|
544
|
+
local context = setup()
|
|
545
|
+
recordFailureHandling()
|
|
546
|
+
|
|
547
|
+
local pending = Promise.new()
|
|
548
|
+
context.tracker:SetQueryOwnershipCallback(function()
|
|
549
|
+
return pending
|
|
550
|
+
end)
|
|
551
|
+
|
|
552
|
+
local asked = context.tracker:PromiseOwnsAsset("swordKey")
|
|
553
|
+
|
|
554
|
+
-- Destroying the tracker rejects the query with nothing, which is teardown rather than a refusal.
|
|
555
|
+
-- The real _warnQueryFailed drops it on the nil check; here we see it arrive and assert the shape.
|
|
556
|
+
context.destroy()
|
|
557
|
+
expect(PromiseTestUtils.awaitSettled(asked, 5)).toEqual(true)
|
|
558
|
+
local askedOk = asked:Yield()
|
|
559
|
+
expect(askedOk).toEqual(false)
|
|
560
|
+
|
|
561
|
+
for _, report in reports do
|
|
562
|
+
expect(report.err).toEqual(nil)
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
pending:Destroy()
|
|
566
|
+
end)
|
|
567
|
+
end)
|
|
568
|
+
|
|
439
569
|
describe("PlayerAssetOwnershipTracker:ObserveOwnsAsset() overrides", function()
|
|
440
570
|
it("should emit the override value and revert to the cloud query when cleared", function()
|
|
441
571
|
local context = setup()
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
local require = require(script.Parent.loader).load(script)
|
|
9
9
|
|
|
10
10
|
local MarketplaceService = game:GetService("MarketplaceService")
|
|
11
|
+
local Players = game:GetService("Players")
|
|
12
|
+
local RunService = game:GetService("RunService")
|
|
11
13
|
|
|
12
14
|
local BaseObject = require("BaseObject")
|
|
13
15
|
local GameConfigAssetTypeUtils = require("GameConfigAssetTypeUtils")
|
|
@@ -135,6 +137,21 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
135
137
|
end
|
|
136
138
|
end))
|
|
137
139
|
|
|
140
|
+
membershipOwnership:SetQueryOwnershipCallback(function(membershipType)
|
|
141
|
+
local playerMembershipType = if PlayerMock.isMock(self._player)
|
|
142
|
+
then PlayerMock.read(self._player, "MembershipType")
|
|
143
|
+
else self._player.MembershipType
|
|
144
|
+
return Promise.resolved(playerMembershipType == membershipType)
|
|
145
|
+
end)
|
|
146
|
+
|
|
147
|
+
-- Everything below asks the cloud, which a client may only do about its own player (see
|
|
148
|
+
-- _canQueryCloudOwnership). Left unwired otherwise, so an unanswerable query rejects naming the
|
|
149
|
+
-- missing callback rather than spending a doomed request per player per asset. Membership is wired
|
|
150
|
+
-- above either way: it reads a replicated property rather than asking anybody.
|
|
151
|
+
if not self:_canQueryCloudOwnership() then
|
|
152
|
+
return self
|
|
153
|
+
end
|
|
154
|
+
|
|
138
155
|
-- Configure gamepass to be a bit special
|
|
139
156
|
passOwnership:SetQueryOwnershipCallback(function(gamePassId)
|
|
140
157
|
local userId = if PlayerMock.isMock(self._player)
|
|
@@ -161,13 +178,6 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
161
178
|
end)
|
|
162
179
|
end)
|
|
163
180
|
|
|
164
|
-
membershipOwnership:SetQueryOwnershipCallback(function(membershipType)
|
|
165
|
-
local playerMembershipType = if PlayerMock.isMock(self._player)
|
|
166
|
-
then PlayerMock.read(self._player, "MembershipType")
|
|
167
|
-
else self._player.MembershipType
|
|
168
|
-
return Promise.resolved(playerMembershipType == membershipType)
|
|
169
|
-
end)
|
|
170
|
-
|
|
171
181
|
-- Paid-access game ownership is queried through PlayerOwnsAssetAsync
|
|
172
182
|
gameOwnership:SetQueryOwnershipCallback(function(assetId)
|
|
173
183
|
return MarketplaceUtils.promisePlayerOwnsAssetAsync(self._player, assetId)
|
|
@@ -176,6 +186,53 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
176
186
|
return self
|
|
177
187
|
end
|
|
178
188
|
|
|
189
|
+
--[=[
|
|
190
|
+
Whether this realm can ask the cloud about this player's ownership.
|
|
191
|
+
|
|
192
|
+
A client process may only ask about its own player: UserOwnsGamePassAsync refuses outright ("can only
|
|
193
|
+
query local player") and the inventory endpoints answer HTTP 403. It holds a manager for everybody
|
|
194
|
+
regardless -- the PlayerProductManager tag replicates, so the binder builds one per player -- so
|
|
195
|
+
wiring the queries there spends a request per player per asset to reach the same refusal every time.
|
|
196
|
+
|
|
197
|
+
Asked of the process rather than of the tie realm, because the engine's restriction is the process's:
|
|
198
|
+
a bag told it is [TieRealms].SHARED is still a client where a marketplace call is concerned, and
|
|
199
|
+
[PlayerProductManagerClient] gates its bulk-purchase listener on RunService for the same reason.
|
|
200
|
+
|
|
201
|
+
Ownership overrides are unaffected: they replicate and short-circuit the query, so a client still
|
|
202
|
+
answers for another player wherever the server has said something (see [PlayerAssetOwnershipTracker]).
|
|
203
|
+
|
|
204
|
+
A [PlayerMock] never reaches the engine -- its ownership is read through PlayerMock.readLookup -- so a
|
|
205
|
+
simulated player stays answerable anywhere, which is what lets a headless test drive ownership for
|
|
206
|
+
players other than the one standing in for the local one.
|
|
207
|
+
|
|
208
|
+
@return boolean
|
|
209
|
+
@private
|
|
210
|
+
]=]
|
|
211
|
+
function PlayerProductManagerBase._canQueryCloudOwnership(self: PlayerProductManagerBase): boolean
|
|
212
|
+
if not PlayerProductManagerBase._isClientProcess() then
|
|
213
|
+
return true
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
if PlayerMock.isMock(self._player) then
|
|
217
|
+
return true
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
local localPlayer = Players.LocalPlayer or PlayerMock.getMockedLocalPlayer()
|
|
221
|
+
|
|
222
|
+
-- No local player to be is not a client to speak for: left able to ask, rather than unwiring
|
|
223
|
+
-- ownership for the very player this manager is about.
|
|
224
|
+
return localPlayer == nil or self._player == localPlayer
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
--[[
|
|
228
|
+
Whether this is a client process, behind a seam because a test needs to drive both: --cloud runs
|
|
229
|
+
server-side, where the client branch would otherwise be unreachable. Mirrors
|
|
230
|
+
[TeleportServiceUtils]._isServer, which exists for the same reason.
|
|
231
|
+
]]
|
|
232
|
+
function PlayerProductManagerBase._isClientProcess(): boolean
|
|
233
|
+
return RunService:IsClient() and not RunService:IsServer()
|
|
234
|
+
end
|
|
235
|
+
|
|
179
236
|
--[=[
|
|
180
237
|
Applies a gamepass prompt result to this realm's tracker, exactly as the engine's
|
|
181
238
|
PromptGamePassPurchaseFinished handler would. Only invoked for a [PlayerMock] (see the
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
Unit coverage for PlayerProductManagerBase._canQueryCloudOwnership: whether this process can ask the
|
|
4
|
+
cloud about a given player's ownership. A client holds a PlayerProductManager for every player -- the
|
|
5
|
+
tag replicates, so the binder builds one per player -- but may only ask the marketplace about its own,
|
|
6
|
+
so this is what keeps a doomed request per player per asset from being made at all.
|
|
7
|
+
|
|
8
|
+
Driven against a fake `self` rather than a constructed manager: the predicate reads only `_player`, and
|
|
9
|
+
building a manager would need a ServiceBag, the GameConfig graph, and a real Player the cloud test
|
|
10
|
+
place has none of. A designated [PlayerMock] stands in for the local player, and the process seam
|
|
11
|
+
stands in for being a client -- a --cloud run is a server, so the client branch is otherwise
|
|
12
|
+
unreachable.
|
|
13
|
+
|
|
14
|
+
@class PlayerProductManagerBase.spec.lua
|
|
15
|
+
]]
|
|
16
|
+
local require = require(script.Parent.loader).load(script)
|
|
17
|
+
|
|
18
|
+
local Jest = require("Jest")
|
|
19
|
+
local PlayerMock = require("PlayerMock")
|
|
20
|
+
local PlayerProductManagerBase = require("PlayerProductManagerBase")
|
|
21
|
+
local Workspace = game:GetService("Workspace")
|
|
22
|
+
|
|
23
|
+
local afterEach = Jest.Globals.afterEach
|
|
24
|
+
local describe = Jest.Globals.describe
|
|
25
|
+
local expect = Jest.Globals.expect
|
|
26
|
+
local it = Jest.Globals.it
|
|
27
|
+
local jest = Jest.Globals.jest
|
|
28
|
+
|
|
29
|
+
-- Spied once and re-implemented between tests rather than restored and re-spied, matching
|
|
30
|
+
-- TeleportServiceUtils.spec: jest.restoreAllMocks clears the spy state but not the per-object mock
|
|
31
|
+
-- registry, so a second spyOn of the same method hands back the cached mock without reinstalling it.
|
|
32
|
+
local realIsClientProcess = (PlayerProductManagerBase :: any)._isClientProcess
|
|
33
|
+
local isClientProcessSpy = jest.spyOn(PlayerProductManagerBase :: any, "_isClientProcess")
|
|
34
|
+
|
|
35
|
+
local function pretendClientProcess(): ()
|
|
36
|
+
isClientProcessSpy.mockReturnValue(true)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
local function pretendServerProcess(): ()
|
|
40
|
+
isClientProcessSpy.mockReturnValue(false)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
local created: { any } = {}
|
|
44
|
+
|
|
45
|
+
afterEach(function()
|
|
46
|
+
isClientProcessSpy.mockImplementation(realIsClientProcess)
|
|
47
|
+
PlayerMock.setMockedLocalPlayer(nil)
|
|
48
|
+
|
|
49
|
+
for _, instance in created do
|
|
50
|
+
instance:Destroy()
|
|
51
|
+
end
|
|
52
|
+
table.clear(created)
|
|
53
|
+
end)
|
|
54
|
+
|
|
55
|
+
local function canQueryCloudOwnership(player: any): boolean
|
|
56
|
+
return (PlayerProductManagerBase :: any)._canQueryCloudOwnership({ _player = player })
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
-- A Folder without the mock tag: PlayerMock.isMock requires both, so this fails it and stands in for a
|
|
60
|
+
-- real player, which a server-run spec cannot otherwise have.
|
|
61
|
+
local function newNonMockPlayer(): any
|
|
62
|
+
local player = Instance.new("Folder")
|
|
63
|
+
player.Name = "NotAPlayerMock"
|
|
64
|
+
table.insert(created, player)
|
|
65
|
+
return player
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
local function newMock(): any
|
|
69
|
+
local mock: any = PlayerMock.new()
|
|
70
|
+
table.insert(created, mock)
|
|
71
|
+
return mock
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
-- Parented before designating: the designation is a CollectionService tag, and GetTagged only resolves
|
|
75
|
+
-- instances in the DataModel.
|
|
76
|
+
local function designateLocal(mock: any): ()
|
|
77
|
+
mock.Parent = Workspace
|
|
78
|
+
PlayerMock.setMockedLocalPlayer(mock)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe("PlayerProductManagerBase._canQueryCloudOwnership()", function()
|
|
82
|
+
it("should let a server process ask about anybody", function()
|
|
83
|
+
designateLocal(newMock())
|
|
84
|
+
pretendServerProcess()
|
|
85
|
+
|
|
86
|
+
expect(canQueryCloudOwnership(newNonMockPlayer())).toEqual(true)
|
|
87
|
+
end)
|
|
88
|
+
|
|
89
|
+
it("should refuse a client process asking about a player that is not its own", function()
|
|
90
|
+
designateLocal(newMock())
|
|
91
|
+
pretendClientProcess()
|
|
92
|
+
|
|
93
|
+
expect(canQueryCloudOwnership(newNonMockPlayer())).toEqual(false)
|
|
94
|
+
end)
|
|
95
|
+
|
|
96
|
+
it("should let a client process ask about its own player", function()
|
|
97
|
+
local localMock = newMock()
|
|
98
|
+
designateLocal(localMock)
|
|
99
|
+
pretendClientProcess()
|
|
100
|
+
|
|
101
|
+
expect(canQueryCloudOwnership(localMock)).toEqual(true)
|
|
102
|
+
end)
|
|
103
|
+
|
|
104
|
+
it("should let a client process ask about another mock, which never reaches the engine", function()
|
|
105
|
+
designateLocal(newMock())
|
|
106
|
+
pretendClientProcess()
|
|
107
|
+
|
|
108
|
+
expect(canQueryCloudOwnership(newMock())).toEqual(true)
|
|
109
|
+
end)
|
|
110
|
+
|
|
111
|
+
it("should let a client process with no local player ask", function()
|
|
112
|
+
pretendClientProcess()
|
|
113
|
+
|
|
114
|
+
-- No player to be is not a client to speak for: left able to ask, rather than unwiring ownership
|
|
115
|
+
-- for the very player the manager is about.
|
|
116
|
+
expect(canQueryCloudOwnership(newNonMockPlayer())).toEqual(true)
|
|
117
|
+
end)
|
|
118
|
+
end)
|