@quenty/gameproductservice 14.59.0 → 14.61.0
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 +14 -0
- package/package.json +30 -27
- package/src/Client/GameProductServiceClient.lua +22 -18
- package/src/Client/Manager/PlayerProductManagerClient.lua +19 -8
- package/src/Server/GameProductService.lua +11 -10
- package/src/Server/GameProductService.spec.lua +460 -0
- package/src/Shared/GameProductDataService.lua +15 -14
- package/src/Shared/GameProductDataService.spec.lua +6 -8
- package/src/Shared/Ownership/PlayerAssetOwnershipTracker.spec.lua +7 -11
- package/src/Shared/Trackers/PlayerAssetMarketTracker.spec.lua +0 -8
- package/src/Shared/Trackers/PlayerProductManagerBase.lua +41 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
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.61.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.60.0...@quenty/gameproductservice@14.61.0) (2026-07-23)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- Safey tests ([881e7a9](https://github.com/Quenty/NevermoreEngine/commit/881e7a9c9ca8c51d30b4791b84668425955f318d))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- Add baseline player-mock and support across Nevermore for mocked players. ([567d121](https://github.com/Quenty/NevermoreEngine/commit/567d121ffc014b42391554088189a1a6296dda83))
|
|
15
|
+
|
|
16
|
+
# [14.60.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.59.0...@quenty/gameproductservice@14.60.0) (2026-07-22)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @quenty/gameproductservice
|
|
19
|
+
|
|
6
20
|
# [14.59.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.58.0...@quenty/gameproductservice@14.59.0) (2026-07-21)
|
|
7
21
|
|
|
8
22
|
**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.
|
|
3
|
+
"version": "14.61.0",
|
|
4
4
|
"description": "Generalized monetization system for handling products and purchases correctly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -30,36 +30,39 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@quenty/attributeutils": "14.
|
|
34
|
-
"@quenty/avatareditorutils": "7.
|
|
35
|
-
"@quenty/baseobject": "10.
|
|
36
|
-
"@quenty/binder": "14.
|
|
37
|
-
"@quenty/brio": "14.
|
|
38
|
-
"@quenty/cmdrservice": "13.
|
|
33
|
+
"@quenty/attributeutils": "14.33.0",
|
|
34
|
+
"@quenty/avatareditorutils": "7.43.0",
|
|
35
|
+
"@quenty/baseobject": "10.15.0",
|
|
36
|
+
"@quenty/binder": "14.41.0",
|
|
37
|
+
"@quenty/brio": "14.33.0",
|
|
38
|
+
"@quenty/cmdrservice": "13.51.0",
|
|
39
39
|
"@quenty/enumutils": "3.4.6",
|
|
40
|
-
"@quenty/gameconfig": "12.
|
|
41
|
-
"@quenty/instanceutils": "13.
|
|
40
|
+
"@quenty/gameconfig": "12.57.0",
|
|
41
|
+
"@quenty/instanceutils": "13.33.0",
|
|
42
42
|
"@quenty/loader": "10.11.0",
|
|
43
|
-
"@quenty/maid": "3.
|
|
44
|
-
"@quenty/marketplaceutils": "11.
|
|
45
|
-
"@quenty/nevermore-test-runner": "1.
|
|
46
|
-
"@quenty/observablecollection": "12.
|
|
47
|
-
"@quenty/
|
|
48
|
-
"@quenty/
|
|
49
|
-
"@quenty/
|
|
50
|
-
"@quenty/
|
|
51
|
-
"@quenty/
|
|
52
|
-
"@quenty/
|
|
53
|
-
"@quenty/
|
|
54
|
-
"@quenty/
|
|
55
|
-
"@quenty/
|
|
43
|
+
"@quenty/maid": "3.11.0",
|
|
44
|
+
"@quenty/marketplaceutils": "11.25.0",
|
|
45
|
+
"@quenty/nevermore-test-runner": "1.5.0",
|
|
46
|
+
"@quenty/observablecollection": "12.42.0",
|
|
47
|
+
"@quenty/permissionprovider": "14.44.0",
|
|
48
|
+
"@quenty/playerbinder": "14.41.0",
|
|
49
|
+
"@quenty/playermock": "1.1.0",
|
|
50
|
+
"@quenty/playerutils": "8.36.0",
|
|
51
|
+
"@quenty/promise": "10.21.0",
|
|
52
|
+
"@quenty/promisemaid": "5.21.0",
|
|
53
|
+
"@quenty/receiptprocessing": "7.37.0",
|
|
54
|
+
"@quenty/remoting": "12.36.0",
|
|
55
|
+
"@quenty/rx": "13.31.0",
|
|
56
|
+
"@quenty/rxbinderutils": "14.41.0",
|
|
57
|
+
"@quenty/servicebag": "11.20.0",
|
|
56
58
|
"@quenty/signal": "7.13.1",
|
|
57
|
-
"@quenty/statestack": "14.
|
|
58
|
-
"@quenty/
|
|
59
|
+
"@quenty/statestack": "14.35.0",
|
|
60
|
+
"@quenty/steputils": "3.7.0",
|
|
61
|
+
"@quenty/string": "3.4.0",
|
|
59
62
|
"@quenty/table": "3.9.2",
|
|
60
|
-
"@quenty/tie": "10.
|
|
61
|
-
"@quenty/valueobject": "13.
|
|
63
|
+
"@quenty/tie": "10.44.0",
|
|
64
|
+
"@quenty/valueobject": "13.34.0",
|
|
62
65
|
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
63
66
|
},
|
|
64
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "1de37218a2bedb8e3f8614a2e09bba9eddc812da"
|
|
65
68
|
}
|
|
@@ -20,6 +20,7 @@ local GameConfigAssetTypeUtils = require("GameConfigAssetTypeUtils")
|
|
|
20
20
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
21
21
|
local Maid = require("Maid")
|
|
22
22
|
local Observable = require("Observable")
|
|
23
|
+
local PlayerMock = require("PlayerMock")
|
|
23
24
|
local Promise = require("Promise")
|
|
24
25
|
local ServiceBag = require("ServiceBag")
|
|
25
26
|
local Signal = require("Signal")
|
|
@@ -77,7 +78,7 @@ end
|
|
|
77
78
|
function GameProductServiceClient.Start(self: GameProductServiceClient): ()
|
|
78
79
|
local function forwardSignal(origSignal: any, signal: any)
|
|
79
80
|
self._maid:GiveTask(origSignal:Connect(function(player, ...)
|
|
80
|
-
if player == Players.LocalPlayer then
|
|
81
|
+
if player == Players.LocalPlayer or player == PlayerMock.getMockedLocalPlayer() then
|
|
81
82
|
signal:Fire(...)
|
|
82
83
|
end
|
|
83
84
|
end))
|
|
@@ -141,7 +142,7 @@ function GameProductServiceClient.HasPlayerPurchasedThisSession(
|
|
|
141
142
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
142
143
|
idOrKey: string | number
|
|
143
144
|
): boolean
|
|
144
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
145
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
145
146
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
146
147
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
147
148
|
|
|
@@ -162,7 +163,7 @@ function GameProductServiceClient.PromisePromptPurchase(
|
|
|
162
163
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
163
164
|
idOrKey: string | number
|
|
164
165
|
): Promise.Promise<boolean>
|
|
165
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
166
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
166
167
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
167
168
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
168
169
|
|
|
@@ -177,7 +178,9 @@ end
|
|
|
177
178
|
@return Observable<boolean>
|
|
178
179
|
]=]
|
|
179
180
|
function GameProductServiceClient:ObserveServerOnlyPromptingEnabled(): Observable.Observable<boolean>
|
|
180
|
-
return self._gameProductDataService:ObserveServerOnlyPrompting(
|
|
181
|
+
return self._gameProductDataService:ObserveServerOnlyPrompting(
|
|
182
|
+
Players.LocalPlayer or PlayerMock.getMockedLocalPlayer()
|
|
183
|
+
)
|
|
181
184
|
end
|
|
182
185
|
|
|
183
186
|
--[=[
|
|
@@ -194,7 +197,7 @@ function GameProductServiceClient.PromisePlayerOwnership(
|
|
|
194
197
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
195
198
|
idOrKey: string | number
|
|
196
199
|
): Promise.Promise<boolean>
|
|
197
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
200
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
198
201
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
199
202
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
200
203
|
|
|
@@ -221,7 +224,7 @@ function GameProductServiceClient.ObservePlayerOwnership(
|
|
|
221
224
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
222
225
|
idOrKey: string | number
|
|
223
226
|
): Observable.Observable<boolean>
|
|
224
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
227
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
225
228
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
226
229
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
227
230
|
|
|
@@ -238,7 +241,7 @@ function GameProductServiceClient.PromisePlayerIsPromptOpen(
|
|
|
238
241
|
self: GameProductServiceClient,
|
|
239
242
|
player: Player
|
|
240
243
|
): Promise.Promise<boolean>
|
|
241
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
244
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
242
245
|
assert(self ~= (GameProductServiceClient :: any), "Use serviceBag")
|
|
243
246
|
assert(self._serviceBag, "Not initialized")
|
|
244
247
|
|
|
@@ -255,7 +258,7 @@ function GameProductServiceClient.PromisePlayerPromptClosed(
|
|
|
255
258
|
self: GameProductServiceClient,
|
|
256
259
|
player: Player
|
|
257
260
|
): Promise.Promise<boolean>
|
|
258
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
261
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
259
262
|
assert(self ~= (GameProductServiceClient :: any), "Use serviceBag")
|
|
260
263
|
assert(self._serviceBag, "Not initialized")
|
|
261
264
|
|
|
@@ -278,7 +281,7 @@ function GameProductServiceClient.PromisePlayerOwnershipOrPrompt(
|
|
|
278
281
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
279
282
|
idOrKey: string | number
|
|
280
283
|
): Promise.Promise<boolean>
|
|
281
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
284
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
282
285
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
283
286
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
284
287
|
|
|
@@ -300,18 +303,19 @@ function GameProductServiceClient.PromiseGamePassOrProductUnlockOrPrompt(
|
|
|
300
303
|
assert(type(gamePassIdOrKey) == "number" or type(gamePassIdOrKey) == "string", "Bad gamePassIdOrKey")
|
|
301
304
|
assert(type(productIdOrKey) == "number" or type(productIdOrKey) == "string", "Bad productIdOrKey")
|
|
302
305
|
|
|
303
|
-
|
|
306
|
+
local localPlayer = Players.LocalPlayer or PlayerMock.getMockedLocalPlayer()
|
|
307
|
+
|
|
308
|
+
if self:HasPlayerPurchasedThisSession(localPlayer, GameConfigAssetTypes.PRODUCT, productIdOrKey) then
|
|
304
309
|
return Promise.resolved(true)
|
|
305
310
|
end
|
|
306
311
|
|
|
307
|
-
return self:PromisePlayerOwnership(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
end)
|
|
312
|
+
return self:PromisePlayerOwnership(localPlayer, GameConfigAssetTypes.PASS, gamePassIdOrKey):Then(function(owns)
|
|
313
|
+
if owns then
|
|
314
|
+
return true
|
|
315
|
+
else
|
|
316
|
+
return self:PromisePromptPurchase(localPlayer, GameConfigAssetTypes.PRODUCT, productIdOrKey)
|
|
317
|
+
end
|
|
318
|
+
end)
|
|
315
319
|
end
|
|
316
320
|
|
|
317
321
|
function GameProductServiceClient.Destroy(self: GameProductServiceClient): ()
|
|
@@ -8,6 +8,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
8
8
|
|
|
9
9
|
local MarketplaceService = game:GetService("MarketplaceService")
|
|
10
10
|
local Players = game:GetService("Players")
|
|
11
|
+
local RunService = game:GetService("RunService")
|
|
11
12
|
|
|
12
13
|
local AvatarEditorInventoryServiceClient = require("AvatarEditorInventoryServiceClient")
|
|
13
14
|
local Binder = require("Binder")
|
|
@@ -15,6 +16,7 @@ local CatalogSearchServiceCache = require("CatalogSearchServiceCache")
|
|
|
15
16
|
local EnumUtils = require("EnumUtils")
|
|
16
17
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
17
18
|
local MarketplaceUtils = require("MarketplaceUtils")
|
|
19
|
+
local PlayerMock = require("PlayerMock")
|
|
18
20
|
local PlayerProductManagerBase = require("PlayerProductManagerBase")
|
|
19
21
|
local PlayerProductManagerInterface = require("PlayerProductManagerInterface")
|
|
20
22
|
local Promise = require("Promise")
|
|
@@ -77,7 +79,7 @@ function PlayerProductManagerClient.new(player: Player, serviceBag: ServiceBag.S
|
|
|
77
79
|
self._avatarEditorInventoryServiceClient = self._serviceBag:GetService(AvatarEditorInventoryServiceClient :: any)
|
|
78
80
|
self._catalogSearchServiceCache = self._serviceBag:GetService(CatalogSearchServiceCache :: any)
|
|
79
81
|
|
|
80
|
-
if self._obj == Players.LocalPlayer then
|
|
82
|
+
if self._obj == Players.LocalPlayer or self._obj == PlayerMock.getMockedLocalPlayer() then
|
|
81
83
|
self._remoting = self._maid:Add(Remoting.new(self._obj, "PlayerProductManager", Remoting.Realms.CLIENT))
|
|
82
84
|
|
|
83
85
|
self:_setupAssetTracker()
|
|
@@ -87,7 +89,11 @@ function PlayerProductManagerClient.new(player: Player, serviceBag: ServiceBag.S
|
|
|
87
89
|
self:_setupBundleTracker()
|
|
88
90
|
self:_connectGamePassTracker()
|
|
89
91
|
|
|
90
|
-
|
|
92
|
+
if RunService:IsClient() then
|
|
93
|
+
-- PromptBulkPurchaseFinished may only be subscribed from a local script; headless
|
|
94
|
+
-- (a server-run spec driving a mock local player) it can never fire anyway.
|
|
95
|
+
self:_connectBulkPurchaseMarketplace()
|
|
96
|
+
end
|
|
91
97
|
end
|
|
92
98
|
|
|
93
99
|
local impl = self._maid:Add((PlayerProductManagerInterface :: any).Client:Implement(self._obj, self))
|
|
@@ -241,22 +247,27 @@ function PlayerProductManagerClient._setupProductTracker(self: any): ()
|
|
|
241
247
|
end
|
|
242
248
|
|
|
243
249
|
function PlayerProductManagerClient._connectGamePassTracker(self: any): ()
|
|
244
|
-
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.PASS)
|
|
245
|
-
|
|
246
250
|
self._maid:GiveTask(
|
|
247
251
|
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, isPurchased)
|
|
248
252
|
assert(type(isPurchased) == "boolean", "Bad isPurchased")
|
|
249
253
|
|
|
250
254
|
if player == self._obj then
|
|
251
|
-
|
|
252
|
-
tracker:HandlePurchaseEvent(gamePassId, isPurchased)
|
|
253
|
-
|
|
254
|
-
self._remoting.PromptGamePassPurchaseFinished:FireServer(gamePassId, isPurchased)
|
|
255
|
+
self:_handleGamePassPromptFinished(gamePassId, isPurchased)
|
|
255
256
|
end
|
|
256
257
|
end)
|
|
257
258
|
)
|
|
258
259
|
end
|
|
259
260
|
|
|
261
|
+
function PlayerProductManagerClient._handleGamePassPromptFinished(
|
|
262
|
+
self: any,
|
|
263
|
+
gamePassId: number,
|
|
264
|
+
isPurchased: boolean
|
|
265
|
+
): ()
|
|
266
|
+
PlayerProductManagerBase._handleGamePassPromptFinished(self, gamePassId, isPurchased)
|
|
267
|
+
|
|
268
|
+
self._remoting.PromptGamePassPurchaseFinished:FireServer(gamePassId, isPurchased)
|
|
269
|
+
end
|
|
270
|
+
|
|
260
271
|
function PlayerProductManagerClient._setupBundleTracker(self: any): ()
|
|
261
272
|
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.BUNDLE)
|
|
262
273
|
|
|
@@ -18,6 +18,7 @@ local GameConfigAssetTypeUtils = require("GameConfigAssetTypeUtils")
|
|
|
18
18
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
19
19
|
local Maid = require("Maid")
|
|
20
20
|
local Observable = require("Observable")
|
|
21
|
+
local PlayerMock = require("PlayerMock")
|
|
21
22
|
local Promise = require("Promise")
|
|
22
23
|
local ServiceBag = require("ServiceBag")
|
|
23
24
|
local Signal = require("Signal")
|
|
@@ -85,7 +86,7 @@ function GameProductService.ObservePlayerAssetPurchased(
|
|
|
85
86
|
idOrKey: string | number
|
|
86
87
|
): Observable.Observable<()>
|
|
87
88
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
88
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
89
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
89
90
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
90
91
|
|
|
91
92
|
return self._gameProductDataService:ObservePlayerAssetPurchased(player, assetType, idOrKey)
|
|
@@ -123,7 +124,7 @@ function GameProductService.HasPlayerPurchasedThisSession(
|
|
|
123
124
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
124
125
|
idOrKey: string | number
|
|
125
126
|
): boolean
|
|
126
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
127
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
127
128
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
128
129
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
129
130
|
|
|
@@ -140,7 +141,7 @@ function GameProductService.PromisePlayerIsPromptOpen(
|
|
|
140
141
|
self: GameProductService,
|
|
141
142
|
player: Player
|
|
142
143
|
): Promise.Promise<boolean>
|
|
143
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
144
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
144
145
|
assert(self._serviceBag, "Not initialized")
|
|
145
146
|
|
|
146
147
|
return self._gameProductDataService:PromisePlayerIsPromptOpen(player)
|
|
@@ -156,7 +157,7 @@ function GameProductService.PromisePlayerPromptClosed(
|
|
|
156
157
|
self: GameProductService,
|
|
157
158
|
player: Player
|
|
158
159
|
): Promise.Promise<boolean>
|
|
159
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
160
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
160
161
|
assert(self._serviceBag, "Not initialized")
|
|
161
162
|
|
|
162
163
|
return self._gameProductDataService:PromisePlayerPromptClosed(player)
|
|
@@ -176,7 +177,7 @@ function GameProductService.PromisePlayerPromptPurchase(
|
|
|
176
177
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
177
178
|
idOrKey: string | number
|
|
178
179
|
): Promise.Promise<boolean>
|
|
179
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
180
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
180
181
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
181
182
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
182
183
|
|
|
@@ -197,7 +198,7 @@ function GameProductService.PromisePlayerOwnership(
|
|
|
197
198
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
198
199
|
idOrKey: string | number
|
|
199
200
|
): Promise.Promise<boolean>
|
|
200
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
201
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
201
202
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
202
203
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
203
204
|
|
|
@@ -228,7 +229,7 @@ function GameProductService.SetPlayerOwnershipOverride(
|
|
|
228
229
|
idOrKey: string | number,
|
|
229
230
|
ownsAsset: boolean?
|
|
230
231
|
): Promise.Promise<()>
|
|
231
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
232
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
232
233
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
233
234
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
234
235
|
assert(type(ownsAsset) == "boolean" or ownsAsset == nil, "Bad ownsAsset")
|
|
@@ -251,7 +252,7 @@ function GameProductService.ClearPlayerOwnershipOverride(
|
|
|
251
252
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
252
253
|
idOrKey: string | number
|
|
253
254
|
): Promise.Promise<()>
|
|
254
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
255
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
255
256
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
256
257
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
257
258
|
|
|
@@ -274,7 +275,7 @@ function GameProductService.PromisePlayerOwnershipOrPrompt(
|
|
|
274
275
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
275
276
|
idOrKey: string | number
|
|
276
277
|
): Promise.Promise<boolean>
|
|
277
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
278
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
278
279
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
279
280
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
280
281
|
|
|
@@ -295,7 +296,7 @@ function GameProductService.ObservePlayerOwnership(
|
|
|
295
296
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
296
297
|
idOrKey: string | number
|
|
297
298
|
): Observable.Observable<boolean>
|
|
298
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
299
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
299
300
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
300
301
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
301
302
|
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
Dual-realm integration coverage for GameProductService. Boots a SERVER and a CLIENT ServiceBag
|
|
4
|
+
in the same DataModel (mirroring TelemetryServicePlayerFlow.spec) and drives ownership
|
|
5
|
+
end-to-end against a PlayerMock: PlayerBinder discovery, gamepass ownership resolved on both
|
|
6
|
+
realms from the ownership injected on the mock via PlayerMock.writeLookup
|
|
7
|
+
("MarketplaceService.UserOwnsGamePassAsync"), config-key resolution through GameConfigService,
|
|
8
|
+
and the server-authoritative ownership override winning over the injected cloud answer.
|
|
9
|
+
|
|
10
|
+
Prompting is covered end-to-end from both realms: the injected
|
|
11
|
+
"MarketplaceService.PromptGamePassPurchase" decision answers the prompt the engine cannot show
|
|
12
|
+
a mock, and a client-initiated accept replicates to the server over the production remoting
|
|
13
|
+
path (session purchase, ownership, and both realms' purchase signals).
|
|
14
|
+
|
|
15
|
+
@class GameProductService.spec.lua
|
|
16
|
+
]]
|
|
17
|
+
|
|
18
|
+
local require = require(script.Parent.loader).load(script)
|
|
19
|
+
|
|
20
|
+
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
21
|
+
local GameProductService = require("GameProductService")
|
|
22
|
+
local Jest = require("Jest")
|
|
23
|
+
local Maid = require("Maid")
|
|
24
|
+
local PermissionProviderUtils = require("PermissionProviderUtils")
|
|
25
|
+
local PlayerMock = require("PlayerMock")
|
|
26
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
27
|
+
local ServiceBag = require("ServiceBag")
|
|
28
|
+
local StepUtils = require("StepUtils")
|
|
29
|
+
|
|
30
|
+
local describe = Jest.Globals.describe
|
|
31
|
+
local expect = Jest.Globals.expect
|
|
32
|
+
local it = Jest.Globals.it
|
|
33
|
+
|
|
34
|
+
local MOCK_USER_ID = 55234567
|
|
35
|
+
local GAME_PASS_ID = 111222333
|
|
36
|
+
local OTHER_GAME_PASS_ID = 444555666
|
|
37
|
+
|
|
38
|
+
local remoteNameCounter = 0
|
|
39
|
+
|
|
40
|
+
local function setup()
|
|
41
|
+
local maid = Maid.new()
|
|
42
|
+
|
|
43
|
+
local serverBag = ServiceBag.new()
|
|
44
|
+
serverBag:GetService(require("TieRealmService") :: any):SetTieRealm(require("TieRealms").SERVER)
|
|
45
|
+
|
|
46
|
+
local gameProductService: any = serverBag:GetService(GameProductService)
|
|
47
|
+
local gameConfigService = serverBag:GetService(require("GameConfigService") :: any)
|
|
48
|
+
local playerMockService = serverBag:GetService(require("PlayerMockService") :: any)
|
|
49
|
+
local permissionService = serverBag:GetService(require("PermissionService") :: any)
|
|
50
|
+
serverBag:Init()
|
|
51
|
+
|
|
52
|
+
remoteNameCounter += 1
|
|
53
|
+
permissionService:SetProviderFromConfig(PermissionProviderUtils.createSingleUserConfig({
|
|
54
|
+
userId = MOCK_USER_ID,
|
|
55
|
+
remoteFunctionName = string.format("GameProductServiceSpecPermissionRemote%d", remoteNameCounter),
|
|
56
|
+
}))
|
|
57
|
+
serverBag:Start()
|
|
58
|
+
|
|
59
|
+
local clientBag = ServiceBag.new()
|
|
60
|
+
clientBag:GetService(require("TieRealmService") :: any):SetTieRealm(require("TieRealms").CLIENT)
|
|
61
|
+
local gameProductServiceClient: any = clientBag:GetService((require :: any)("GameProductServiceClient"))
|
|
62
|
+
local playerMockServiceClient = clientBag:GetService((require :: any)("PlayerMockServiceClient"))
|
|
63
|
+
clientBag:Init()
|
|
64
|
+
|
|
65
|
+
local playerMock = playerMockService:CreatePlayer({ UserId = MOCK_USER_ID })
|
|
66
|
+
playerMockServiceClient:SetLocalPlayer(playerMock)
|
|
67
|
+
clientBag:Start()
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
serverBag = serverBag,
|
|
71
|
+
clientBag = clientBag,
|
|
72
|
+
gameProductService = gameProductService,
|
|
73
|
+
gameProductServiceClient = gameProductServiceClient,
|
|
74
|
+
gameConfigService = gameConfigService,
|
|
75
|
+
playerMock = playerMock,
|
|
76
|
+
awaitBool = function(promise: any): boolean
|
|
77
|
+
expect(PromiseTestUtils.awaitSettled(promise, 10)).toEqual(true)
|
|
78
|
+
local ok, value = promise:Yield()
|
|
79
|
+
expect(ok).toEqual(true)
|
|
80
|
+
return value
|
|
81
|
+
end,
|
|
82
|
+
destroy = function(_self)
|
|
83
|
+
clientBag:Destroy()
|
|
84
|
+
serverBag:Destroy()
|
|
85
|
+
maid:DoCleaning()
|
|
86
|
+
end,
|
|
87
|
+
}
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
describe("GameProductService dual-realm boot", function()
|
|
91
|
+
it("boots both the server and client product graphs", function()
|
|
92
|
+
local controller = setup()
|
|
93
|
+
|
|
94
|
+
expect(controller.gameProductService).never.toBeNil()
|
|
95
|
+
expect(controller.gameProductServiceClient).never.toBeNil()
|
|
96
|
+
|
|
97
|
+
controller:destroy()
|
|
98
|
+
end)
|
|
99
|
+
end)
|
|
100
|
+
|
|
101
|
+
describe("PlayerProductManager discovers a PlayerMock", function()
|
|
102
|
+
it("binds PlayerProductManager to a PlayerMock without a manual Bind", function()
|
|
103
|
+
local controller = setup()
|
|
104
|
+
local binder = controller.serverBag:GetService((require :: any)("PlayerProductManager"))
|
|
105
|
+
|
|
106
|
+
PromiseTestUtils.awaitValue(function()
|
|
107
|
+
return binder:Get(controller.playerMock) ~= nil
|
|
108
|
+
end, 10)
|
|
109
|
+
|
|
110
|
+
expect(binder:Get(controller.playerMock)).never.toBeNil()
|
|
111
|
+
|
|
112
|
+
controller:destroy()
|
|
113
|
+
end)
|
|
114
|
+
end)
|
|
115
|
+
|
|
116
|
+
describe("GameProductService server ownership from an injected lookup", function()
|
|
117
|
+
it("resolves false for an uninjected gamepass and true for an injected one", function()
|
|
118
|
+
local controller = setup()
|
|
119
|
+
PlayerMock.writeLookup(controller.playerMock, "MarketplaceService.UserOwnsGamePassAsync", GAME_PASS_ID, true)
|
|
120
|
+
|
|
121
|
+
expect(
|
|
122
|
+
controller.awaitBool(
|
|
123
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
124
|
+
controller.playerMock,
|
|
125
|
+
GameConfigAssetTypes.PASS,
|
|
126
|
+
OTHER_GAME_PASS_ID
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
).toEqual(false)
|
|
130
|
+
expect(
|
|
131
|
+
controller.awaitBool(
|
|
132
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
133
|
+
controller.playerMock,
|
|
134
|
+
GameConfigAssetTypes.PASS,
|
|
135
|
+
GAME_PASS_ID
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
).toEqual(true)
|
|
139
|
+
|
|
140
|
+
controller:destroy()
|
|
141
|
+
end)
|
|
142
|
+
|
|
143
|
+
it("resolves ownership queried by a configured asset key", function()
|
|
144
|
+
local controller = setup()
|
|
145
|
+
controller.gameConfigService:AddPass("test_pass", GAME_PASS_ID)
|
|
146
|
+
PlayerMock.writeLookup(controller.playerMock, "MarketplaceService.UserOwnsGamePassAsync", GAME_PASS_ID, true)
|
|
147
|
+
|
|
148
|
+
expect(
|
|
149
|
+
controller.awaitBool(
|
|
150
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
151
|
+
controller.playerMock,
|
|
152
|
+
GameConfigAssetTypes.PASS,
|
|
153
|
+
"test_pass"
|
|
154
|
+
)
|
|
155
|
+
)
|
|
156
|
+
).toEqual(true)
|
|
157
|
+
|
|
158
|
+
controller:destroy()
|
|
159
|
+
end)
|
|
160
|
+
|
|
161
|
+
it("rejects an unconfigured asset key", function()
|
|
162
|
+
local controller = setup()
|
|
163
|
+
|
|
164
|
+
local outcome = PromiseTestUtils.awaitOutcome(
|
|
165
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
166
|
+
controller.playerMock,
|
|
167
|
+
GameConfigAssetTypes.PASS,
|
|
168
|
+
"never_configured_pass"
|
|
169
|
+
),
|
|
170
|
+
10
|
|
171
|
+
)
|
|
172
|
+
expect(outcome).toEqual("rejected")
|
|
173
|
+
|
|
174
|
+
controller:destroy()
|
|
175
|
+
end)
|
|
176
|
+
end)
|
|
177
|
+
|
|
178
|
+
describe("GameProductService ownership override", function()
|
|
179
|
+
it("wins over the injected cloud answer", function()
|
|
180
|
+
local controller = setup()
|
|
181
|
+
PlayerMock.writeLookup(controller.playerMock, "MarketplaceService.UserOwnsGamePassAsync", GAME_PASS_ID, true)
|
|
182
|
+
|
|
183
|
+
controller.awaitBool(
|
|
184
|
+
controller.gameProductService:SetPlayerOwnershipOverride(
|
|
185
|
+
controller.playerMock,
|
|
186
|
+
GameConfigAssetTypes.PASS,
|
|
187
|
+
GAME_PASS_ID,
|
|
188
|
+
false
|
|
189
|
+
) :: any
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
expect(
|
|
193
|
+
controller.awaitBool(
|
|
194
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
195
|
+
controller.playerMock,
|
|
196
|
+
GameConfigAssetTypes.PASS,
|
|
197
|
+
GAME_PASS_ID
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
).toEqual(false)
|
|
201
|
+
|
|
202
|
+
controller:destroy()
|
|
203
|
+
end)
|
|
204
|
+
|
|
205
|
+
it("clears back to the injected cloud answer", function()
|
|
206
|
+
local controller = setup()
|
|
207
|
+
PlayerMock.writeLookup(controller.playerMock, "MarketplaceService.UserOwnsGamePassAsync", GAME_PASS_ID, true)
|
|
208
|
+
|
|
209
|
+
controller.awaitBool(
|
|
210
|
+
controller.gameProductService:SetPlayerOwnershipOverride(
|
|
211
|
+
controller.playerMock,
|
|
212
|
+
GameConfigAssetTypes.PASS,
|
|
213
|
+
GAME_PASS_ID,
|
|
214
|
+
false
|
|
215
|
+
) :: any
|
|
216
|
+
)
|
|
217
|
+
controller.awaitBool(
|
|
218
|
+
controller.gameProductService:ClearPlayerOwnershipOverride(
|
|
219
|
+
controller.playerMock,
|
|
220
|
+
GameConfigAssetTypes.PASS,
|
|
221
|
+
GAME_PASS_ID
|
|
222
|
+
) :: any
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
expect(
|
|
226
|
+
controller.awaitBool(
|
|
227
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
228
|
+
controller.playerMock,
|
|
229
|
+
GameConfigAssetTypes.PASS,
|
|
230
|
+
GAME_PASS_ID
|
|
231
|
+
)
|
|
232
|
+
)
|
|
233
|
+
).toEqual(true)
|
|
234
|
+
|
|
235
|
+
controller:destroy()
|
|
236
|
+
end)
|
|
237
|
+
end)
|
|
238
|
+
|
|
239
|
+
describe("GameProductServiceClient ownership for the designated mock", function()
|
|
240
|
+
it("resolves the same injected ownership as the server realm", function()
|
|
241
|
+
local controller = setup()
|
|
242
|
+
PlayerMock.writeLookup(controller.playerMock, "MarketplaceService.UserOwnsGamePassAsync", GAME_PASS_ID, true)
|
|
243
|
+
|
|
244
|
+
expect(
|
|
245
|
+
controller.awaitBool(
|
|
246
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
247
|
+
controller.playerMock,
|
|
248
|
+
GameConfigAssetTypes.PASS,
|
|
249
|
+
GAME_PASS_ID
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
).toEqual(true)
|
|
253
|
+
expect(
|
|
254
|
+
controller.awaitBool(
|
|
255
|
+
controller.gameProductServiceClient:PromisePlayerOwnership(
|
|
256
|
+
controller.playerMock,
|
|
257
|
+
GameConfigAssetTypes.PASS,
|
|
258
|
+
GAME_PASS_ID
|
|
259
|
+
)
|
|
260
|
+
)
|
|
261
|
+
).toEqual(true)
|
|
262
|
+
|
|
263
|
+
controller:destroy()
|
|
264
|
+
end)
|
|
265
|
+
|
|
266
|
+
it("reports no session purchases for the mock on either realm", function()
|
|
267
|
+
local controller = setup()
|
|
268
|
+
|
|
269
|
+
expect(
|
|
270
|
+
controller.gameProductService:HasPlayerPurchasedThisSession(
|
|
271
|
+
controller.playerMock,
|
|
272
|
+
GameConfigAssetTypes.PASS,
|
|
273
|
+
GAME_PASS_ID
|
|
274
|
+
)
|
|
275
|
+
).toEqual(false)
|
|
276
|
+
expect(
|
|
277
|
+
controller.gameProductServiceClient:HasPlayerPurchasedThisSession(
|
|
278
|
+
controller.playerMock,
|
|
279
|
+
GameConfigAssetTypes.PASS,
|
|
280
|
+
GAME_PASS_ID
|
|
281
|
+
)
|
|
282
|
+
).toEqual(false)
|
|
283
|
+
|
|
284
|
+
controller:destroy()
|
|
285
|
+
end)
|
|
286
|
+
end)
|
|
287
|
+
|
|
288
|
+
describe("client-initiated gamepass prompt", function()
|
|
289
|
+
it("resolves true on accept, replicates to the server, and fires both realms' purchase signals", function()
|
|
290
|
+
local controller = setup()
|
|
291
|
+
PlayerMock.writeLookup(controller.playerMock, "MarketplaceService.PromptGamePassPurchase", GAME_PASS_ID, true)
|
|
292
|
+
|
|
293
|
+
local serverFired = {}
|
|
294
|
+
local clientFired = {}
|
|
295
|
+
controller.gameProductService.GamePassPurchased:Connect(function(player, gamePassId)
|
|
296
|
+
table.insert(serverFired, { player = player, gamePassId = gamePassId })
|
|
297
|
+
end)
|
|
298
|
+
controller.gameProductServiceClient.GamePassPurchased:Connect(function(gamePassId)
|
|
299
|
+
table.insert(clientFired, gamePassId)
|
|
300
|
+
end)
|
|
301
|
+
|
|
302
|
+
expect(
|
|
303
|
+
controller.awaitBool(
|
|
304
|
+
controller.gameProductServiceClient:PromisePromptPurchase(
|
|
305
|
+
controller.playerMock,
|
|
306
|
+
GameConfigAssetTypes.PASS,
|
|
307
|
+
GAME_PASS_ID
|
|
308
|
+
)
|
|
309
|
+
)
|
|
310
|
+
).toEqual(true)
|
|
311
|
+
|
|
312
|
+
PromiseTestUtils.awaitValue(function()
|
|
313
|
+
return #serverFired > 0
|
|
314
|
+
end, 10)
|
|
315
|
+
|
|
316
|
+
expect(#serverFired).toEqual(1)
|
|
317
|
+
expect(serverFired[1].player).toBe(controller.playerMock)
|
|
318
|
+
expect(serverFired[1].gamePassId).toEqual(GAME_PASS_ID)
|
|
319
|
+
expect(clientFired[1]).toEqual(GAME_PASS_ID)
|
|
320
|
+
expect(
|
|
321
|
+
controller.gameProductService:HasPlayerPurchasedThisSession(
|
|
322
|
+
controller.playerMock,
|
|
323
|
+
GameConfigAssetTypes.PASS,
|
|
324
|
+
GAME_PASS_ID
|
|
325
|
+
)
|
|
326
|
+
).toEqual(true)
|
|
327
|
+
expect(
|
|
328
|
+
controller.awaitBool(
|
|
329
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
330
|
+
controller.playerMock,
|
|
331
|
+
GameConfigAssetTypes.PASS,
|
|
332
|
+
GAME_PASS_ID
|
|
333
|
+
)
|
|
334
|
+
)
|
|
335
|
+
).toEqual(true)
|
|
336
|
+
|
|
337
|
+
controller:destroy()
|
|
338
|
+
end)
|
|
339
|
+
|
|
340
|
+
it("resolves false on reject and marks nothing purchased on either realm", function()
|
|
341
|
+
local controller = setup()
|
|
342
|
+
|
|
343
|
+
local serverFired = {}
|
|
344
|
+
controller.gameProductService.GamePassPurchased:Connect(function()
|
|
345
|
+
table.insert(serverFired, true)
|
|
346
|
+
end)
|
|
347
|
+
|
|
348
|
+
expect(
|
|
349
|
+
controller.awaitBool(
|
|
350
|
+
controller.gameProductServiceClient:PromisePromptPurchase(
|
|
351
|
+
controller.playerMock,
|
|
352
|
+
GameConfigAssetTypes.PASS,
|
|
353
|
+
GAME_PASS_ID
|
|
354
|
+
)
|
|
355
|
+
)
|
|
356
|
+
).toEqual(false)
|
|
357
|
+
|
|
358
|
+
-- Resolving the prompt promise resumed this thread mid-handler; let the handler's
|
|
359
|
+
-- remaining work (the decline forward to the server) run before tearing down.
|
|
360
|
+
StepUtils.deferWait()
|
|
361
|
+
|
|
362
|
+
expect(#serverFired).toEqual(0)
|
|
363
|
+
expect(
|
|
364
|
+
controller.gameProductService:HasPlayerPurchasedThisSession(
|
|
365
|
+
controller.playerMock,
|
|
366
|
+
GameConfigAssetTypes.PASS,
|
|
367
|
+
GAME_PASS_ID
|
|
368
|
+
)
|
|
369
|
+
).toEqual(false)
|
|
370
|
+
expect(
|
|
371
|
+
controller.gameProductServiceClient:HasPlayerPurchasedThisSession(
|
|
372
|
+
controller.playerMock,
|
|
373
|
+
GameConfigAssetTypes.PASS,
|
|
374
|
+
GAME_PASS_ID
|
|
375
|
+
)
|
|
376
|
+
).toEqual(false)
|
|
377
|
+
|
|
378
|
+
controller:destroy()
|
|
379
|
+
end)
|
|
380
|
+
end)
|
|
381
|
+
|
|
382
|
+
describe("server-initiated gamepass prompt", function()
|
|
383
|
+
it("resolves true on accept and marks the session purchase", function()
|
|
384
|
+
local controller = setup()
|
|
385
|
+
PlayerMock.writeLookup(controller.playerMock, "MarketplaceService.PromptGamePassPurchase", GAME_PASS_ID, true)
|
|
386
|
+
|
|
387
|
+
local serverFired = {}
|
|
388
|
+
controller.gameProductService.GamePassPurchased:Connect(function(player, gamePassId)
|
|
389
|
+
table.insert(serverFired, { player = player, gamePassId = gamePassId })
|
|
390
|
+
end)
|
|
391
|
+
|
|
392
|
+
expect(
|
|
393
|
+
controller.awaitBool(
|
|
394
|
+
controller.gameProductService:PromisePlayerPromptPurchase(
|
|
395
|
+
controller.playerMock,
|
|
396
|
+
GameConfigAssetTypes.PASS,
|
|
397
|
+
GAME_PASS_ID
|
|
398
|
+
)
|
|
399
|
+
)
|
|
400
|
+
).toEqual(true)
|
|
401
|
+
|
|
402
|
+
PromiseTestUtils.awaitValue(function()
|
|
403
|
+
return #serverFired > 0
|
|
404
|
+
end, 10)
|
|
405
|
+
|
|
406
|
+
expect(#serverFired).toEqual(1)
|
|
407
|
+
expect(serverFired[1].gamePassId).toEqual(GAME_PASS_ID)
|
|
408
|
+
expect(
|
|
409
|
+
controller.gameProductService:HasPlayerPurchasedThisSession(
|
|
410
|
+
controller.playerMock,
|
|
411
|
+
GameConfigAssetTypes.PASS,
|
|
412
|
+
GAME_PASS_ID
|
|
413
|
+
)
|
|
414
|
+
).toEqual(true)
|
|
415
|
+
expect(
|
|
416
|
+
controller.awaitBool(
|
|
417
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
418
|
+
controller.playerMock,
|
|
419
|
+
GameConfigAssetTypes.PASS,
|
|
420
|
+
GAME_PASS_ID
|
|
421
|
+
)
|
|
422
|
+
)
|
|
423
|
+
).toEqual(true)
|
|
424
|
+
|
|
425
|
+
controller:destroy()
|
|
426
|
+
end)
|
|
427
|
+
|
|
428
|
+
it("resolves false on reject and leaves ownership untouched", function()
|
|
429
|
+
local controller = setup()
|
|
430
|
+
|
|
431
|
+
expect(
|
|
432
|
+
controller.awaitBool(
|
|
433
|
+
controller.gameProductService:PromisePlayerPromptPurchase(
|
|
434
|
+
controller.playerMock,
|
|
435
|
+
GameConfigAssetTypes.PASS,
|
|
436
|
+
GAME_PASS_ID
|
|
437
|
+
)
|
|
438
|
+
)
|
|
439
|
+
).toEqual(false)
|
|
440
|
+
|
|
441
|
+
expect(
|
|
442
|
+
controller.gameProductService:HasPlayerPurchasedThisSession(
|
|
443
|
+
controller.playerMock,
|
|
444
|
+
GameConfigAssetTypes.PASS,
|
|
445
|
+
GAME_PASS_ID
|
|
446
|
+
)
|
|
447
|
+
).toEqual(false)
|
|
448
|
+
expect(
|
|
449
|
+
controller.awaitBool(
|
|
450
|
+
controller.gameProductService:PromisePlayerOwnership(
|
|
451
|
+
controller.playerMock,
|
|
452
|
+
GameConfigAssetTypes.PASS,
|
|
453
|
+
GAME_PASS_ID
|
|
454
|
+
)
|
|
455
|
+
)
|
|
456
|
+
).toEqual(false)
|
|
457
|
+
|
|
458
|
+
controller:destroy()
|
|
459
|
+
end)
|
|
460
|
+
end)
|
|
@@ -10,6 +10,7 @@ local GameConfigAssetTypeUtils = require("GameConfigAssetTypeUtils")
|
|
|
10
10
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
11
11
|
local Maid = require("Maid")
|
|
12
12
|
local Observable = require("Observable")
|
|
13
|
+
local PlayerMock = require("PlayerMock")
|
|
13
14
|
local PlayerProductManagerInterface = require("PlayerProductManagerInterface")
|
|
14
15
|
local Promise = require("Promise")
|
|
15
16
|
local Rx = require("Rx")
|
|
@@ -136,7 +137,7 @@ function GameProductDataService.ObserveServerOnlyPrompting(
|
|
|
136
137
|
_self: GameProductDataService,
|
|
137
138
|
player: Player
|
|
138
139
|
): Observable.Observable<boolean>
|
|
139
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
140
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
140
141
|
|
|
141
142
|
-- Always read the server-authoritative value (the server implementation), which
|
|
142
143
|
-- replicates down to clients as an attribute on the PlayerProductManager folder.
|
|
@@ -215,7 +216,7 @@ function GameProductDataService.HasPlayerPurchasedThisSession(
|
|
|
215
216
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
216
217
|
idOrKey: string | number
|
|
217
218
|
): boolean
|
|
218
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
219
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
219
220
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
220
221
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
221
222
|
|
|
@@ -243,7 +244,7 @@ function GameProductDataService.PromisePromptPurchase(
|
|
|
243
244
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
244
245
|
idOrKey
|
|
245
246
|
): Promise.Promise<boolean>
|
|
246
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
247
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
247
248
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
248
249
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
249
250
|
|
|
@@ -267,7 +268,7 @@ function GameProductDataService.PromisePlayerOwnership(
|
|
|
267
268
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
268
269
|
idOrKey: string | number
|
|
269
270
|
): Promise.Promise<boolean>
|
|
270
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
271
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
271
272
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
272
273
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
273
274
|
|
|
@@ -307,7 +308,7 @@ function GameProductDataService.SetPlayerOwnershipOverride(
|
|
|
307
308
|
self._tieRealmService:GetTieRealm() ~= TieRealms.CLIENT,
|
|
308
309
|
"[GameProductDataService] - Ownership overrides can only be set from the server"
|
|
309
310
|
)
|
|
310
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
311
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
311
312
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
312
313
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
313
314
|
assert(type(ownsAsset) == "boolean" or ownsAsset == nil, "Bad ownsAsset")
|
|
@@ -350,7 +351,7 @@ function GameProductDataService.PromiseIsOwnable(
|
|
|
350
351
|
player: Player,
|
|
351
352
|
assetType: GameConfigAssetTypes.GameConfigAssetType
|
|
352
353
|
): Promise.Promise<boolean>
|
|
353
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
354
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
354
355
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
355
356
|
|
|
356
357
|
return self:_promisePlayerProductManager(player):Then(function(playerProductManager)
|
|
@@ -368,7 +369,7 @@ function GameProductDataService.PromisePlayerIsPromptOpen(
|
|
|
368
369
|
self: GameProductDataService,
|
|
369
370
|
player: Player
|
|
370
371
|
): Promise.Promise<boolean>
|
|
371
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
372
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
372
373
|
|
|
373
374
|
return self:_promisePlayerProductManager(player):Then(function(playerProductManager)
|
|
374
375
|
return playerProductManager:IsPromptOpen()
|
|
@@ -385,7 +386,7 @@ function GameProductDataService.PromisePlayerPromptClosed(
|
|
|
385
386
|
self: GameProductDataService,
|
|
386
387
|
player: Player
|
|
387
388
|
): Promise.Promise<boolean>
|
|
388
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
389
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
389
390
|
|
|
390
391
|
return self:_promisePlayerProductManager(player):Then(function(playerProductManager)
|
|
391
392
|
return playerProductManager:PromisePlayerPromptClosed()
|
|
@@ -406,7 +407,7 @@ function GameProductDataService.ObservePlayerOwnership(
|
|
|
406
407
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
407
408
|
idOrKey: string | number
|
|
408
409
|
): Observable.Observable<boolean>
|
|
409
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
410
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
410
411
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
411
412
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
412
413
|
|
|
@@ -438,7 +439,7 @@ function GameProductDataService.ObservePlayerAssetPurchased(
|
|
|
438
439
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
439
440
|
idOrKey: string | number
|
|
440
441
|
): Observable.Observable<()>
|
|
441
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
442
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
442
443
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
443
444
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
444
445
|
|
|
@@ -514,7 +515,7 @@ function GameProductDataService.PromisePlayerOwnershipOrPrompt(
|
|
|
514
515
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
515
516
|
idOrKey: string | number
|
|
516
517
|
): Promise.Promise<boolean>
|
|
517
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
518
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
518
519
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
519
520
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
520
521
|
|
|
@@ -546,7 +547,7 @@ function GameProductDataService._observePlayerProductManagerBrio(
|
|
|
546
547
|
self: GameProductDataService,
|
|
547
548
|
player: Player
|
|
548
549
|
): Observable.Observable<Brio.Brio<any>>
|
|
549
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
550
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
550
551
|
|
|
551
552
|
return PlayerProductManagerInterface:ObserveBrio(player, self._tieRealmService:GetTieRealm())
|
|
552
553
|
end
|
|
@@ -555,13 +556,13 @@ function GameProductDataService._promisePlayerProductManager(
|
|
|
555
556
|
self: GameProductDataService,
|
|
556
557
|
player: Player
|
|
557
558
|
): Promise.Promise<any>
|
|
558
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
559
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
559
560
|
|
|
560
561
|
return PlayerProductManagerInterface:Promise(player, self._tieRealmService:GetTieRealm())
|
|
561
562
|
end
|
|
562
563
|
|
|
563
564
|
function GameProductDataService._getPlayerProductManager(self: GameProductDataService, player: Player): any
|
|
564
|
-
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
565
|
+
assert((typeof(player) == "Instance" and player:IsA("Player")) or PlayerMock.isMock(player), "Bad player")
|
|
565
566
|
|
|
566
567
|
return PlayerProductManagerInterface:Find(player, self._tieRealmService:GetTieRealm())
|
|
567
568
|
end
|
|
@@ -14,6 +14,7 @@ local require = require(script.Parent.loader).load(script)
|
|
|
14
14
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
15
15
|
local GameProductDataService = require("GameProductDataService")
|
|
16
16
|
local Jest = require("Jest")
|
|
17
|
+
local PlayerMock = require("PlayerMock")
|
|
17
18
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
18
19
|
local ServiceBag = require("ServiceBag")
|
|
19
20
|
local Signal = require("Signal")
|
|
@@ -26,10 +27,9 @@ local it = Jest.Globals.it
|
|
|
26
27
|
|
|
27
28
|
local function setup(tieRealm: TieRealms.TieRealm?)
|
|
28
29
|
local serviceBag = ServiceBag.new()
|
|
29
|
-
local tieRealmService =
|
|
30
|
-
local gameProductDataService =
|
|
30
|
+
local tieRealmService: TieRealmService.TieRealmService = serviceBag:GetService(TieRealmService) :: any
|
|
31
|
+
local gameProductDataService: GameProductDataService.GameProductDataService =
|
|
31
32
|
serviceBag:GetService(GameProductDataService) :: any
|
|
32
|
-
) :: GameProductDataService.GameProductDataService
|
|
33
33
|
serviceBag:Init()
|
|
34
34
|
tieRealmService:SetTieRealm(tieRealm or TieRealms.SERVER)
|
|
35
35
|
serviceBag:Start()
|
|
@@ -127,10 +127,8 @@ describe("GameProductDataService ownership overrides", function()
|
|
|
127
127
|
it("should refuse to set an ownership override from the client realm", function()
|
|
128
128
|
local context = setup(TieRealms.CLIENT)
|
|
129
129
|
local service = context.gameProductDataService
|
|
130
|
-
local fakePlayer =
|
|
130
|
+
local fakePlayer = PlayerMock.new()
|
|
131
131
|
|
|
132
|
-
-- The realm guard is checked before anything else, so a player can never grant themselves
|
|
133
|
-
-- ownership from the client.
|
|
134
132
|
expect(function()
|
|
135
133
|
service:SetPlayerOwnershipOverride(fakePlayer :: any, GameConfigAssetTypes.GAME, 123, true)
|
|
136
134
|
end).toThrow()
|
|
@@ -142,7 +140,7 @@ describe("GameProductDataService ownership overrides", function()
|
|
|
142
140
|
it("should refuse to clear an ownership override from the client realm", function()
|
|
143
141
|
local context = setup(TieRealms.CLIENT)
|
|
144
142
|
local service = context.gameProductDataService
|
|
145
|
-
local fakePlayer =
|
|
143
|
+
local fakePlayer = PlayerMock.new()
|
|
146
144
|
|
|
147
145
|
expect(function()
|
|
148
146
|
service:ClearPlayerOwnershipOverride(fakePlayer :: any, GameConfigAssetTypes.GAME, 123)
|
|
@@ -158,7 +156,7 @@ describe("GameProductDataService prompt guard", function()
|
|
|
158
156
|
local context = setup(TieRealms.SERVER)
|
|
159
157
|
local service = context.gameProductDataService
|
|
160
158
|
|
|
161
|
-
local fakePlayer =
|
|
159
|
+
local fakePlayer = PlayerMock.new()
|
|
162
160
|
local outcome = PromiseTestUtils.awaitOutcome(service:_promiseServerOnlyPromptingGuard(fakePlayer :: any), 5)
|
|
163
161
|
expect(outcome).toEqual("resolved")
|
|
164
162
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
--[[
|
|
3
3
|
Unit coverage for PlayerAssetOwnershipTracker. The tracker is constructed directly with a fake
|
|
4
4
|
config picker (key -> id lookup) and a fake market tracker exposing only a Purchased signal, so
|
|
5
|
-
no ServiceBag, GameConfig, or real MarketplaceService is involved. A
|
|
5
|
+
no ServiceBag, GameConfig, or real MarketplaceService is involved. A PlayerMock stands in for
|
|
6
6
|
the player because the tracker only stores the player, never reads properties off it in the code
|
|
7
7
|
paths under test. Each test destroys everything it creates so nothing leaks into the shared test
|
|
8
8
|
place.
|
|
@@ -17,6 +17,7 @@ local GameConfigPicker = require("GameConfigPicker")
|
|
|
17
17
|
local Jest = require("Jest")
|
|
18
18
|
local Observable = require("Observable")
|
|
19
19
|
local PlayerAssetOwnershipTracker = require("PlayerAssetOwnershipTracker")
|
|
20
|
+
local PlayerMock = require("PlayerMock")
|
|
20
21
|
local PlayerProductOwnershipOverrideUtils = require("PlayerProductOwnershipOverrideUtils")
|
|
21
22
|
local Promise = require("Promise")
|
|
22
23
|
local PromiseTestUtils = require("PromiseTestUtils")
|
|
@@ -38,7 +39,6 @@ local function toId(idOrKey)
|
|
|
38
39
|
return KEY_TO_ID[idOrKey]
|
|
39
40
|
end
|
|
40
41
|
|
|
41
|
-
-- Minimal GameConfigPicker stand-in covering the two methods the tracker calls.
|
|
42
42
|
local function makeConfigPicker()
|
|
43
43
|
return {
|
|
44
44
|
ToAssetId = function(_self, _assetType, idOrKey)
|
|
@@ -66,7 +66,7 @@ end
|
|
|
66
66
|
local function setup()
|
|
67
67
|
local purchased = Signal.new()
|
|
68
68
|
local marketTracker = { Purchased = purchased }
|
|
69
|
-
local player =
|
|
69
|
+
local player = PlayerMock.new()
|
|
70
70
|
player.Name = "FakePlayer"
|
|
71
71
|
|
|
72
72
|
local tracker = PlayerAssetOwnershipTracker.new(
|
|
@@ -168,7 +168,6 @@ describe("PlayerAssetOwnershipTracker:SetOwnership()", function()
|
|
|
168
168
|
|
|
169
169
|
it("should ignore an unknown key without erroring", function()
|
|
170
170
|
local context = setup()
|
|
171
|
-
-- Should warn and no-op rather than throw.
|
|
172
171
|
context.tracker:SetOwnership("doesNotExist", true)
|
|
173
172
|
context.destroy()
|
|
174
173
|
end)
|
|
@@ -429,7 +428,6 @@ describe("PlayerAssetOwnershipTracker:SetOwnershipOverride() combined keys", fun
|
|
|
429
428
|
|
|
430
429
|
it("should ignore an override for an unknown key without erroring", function()
|
|
431
430
|
local context = setup()
|
|
432
|
-
-- Should warn and no-op rather than throw.
|
|
433
431
|
context.tracker:SetOwnershipOverride("doesNotExist", true)
|
|
434
432
|
|
|
435
433
|
local outcome = PromiseTestUtils.awaitOutcome(context.tracker:PromiseOwnsAsset("doesNotExist"), 5)
|
|
@@ -511,13 +509,11 @@ describe("PlayerAssetOwnershipTracker override replication", function()
|
|
|
511
509
|
end
|
|
512
510
|
|
|
513
511
|
it("should apply an override already present when a new tracker binds to the same player", function()
|
|
514
|
-
local player =
|
|
512
|
+
local player = PlayerMock.new()
|
|
515
513
|
|
|
516
|
-
-- The "server" tracker authors the override, writing the replicated attribute.
|
|
517
514
|
local serverTracker, destroyServer = makeTracker(player)
|
|
518
515
|
serverTracker:SetOwnershipOverride("swordKey", true)
|
|
519
516
|
|
|
520
|
-
-- The "client" tracker binds later over the same (replicated) player attribute.
|
|
521
517
|
local clientTracker, destroyClient = makeTracker(player)
|
|
522
518
|
local promise = clientTracker:PromiseOwnsAsset("swordKey")
|
|
523
519
|
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
@@ -530,7 +526,7 @@ describe("PlayerAssetOwnershipTracker override replication", function()
|
|
|
530
526
|
end)
|
|
531
527
|
|
|
532
528
|
it("should apply a false override present at bind time even when the cloud query owns", function()
|
|
533
|
-
local player =
|
|
529
|
+
local player = PlayerMock.new()
|
|
534
530
|
|
|
535
531
|
local serverTracker, destroyServer = makeTracker(player)
|
|
536
532
|
serverTracker:SetOwnershipOverride("swordKey", false)
|
|
@@ -550,7 +546,7 @@ describe("PlayerAssetOwnershipTracker override replication", function()
|
|
|
550
546
|
end)
|
|
551
547
|
|
|
552
548
|
it("should not write the attribute for an unknown key", function()
|
|
553
|
-
local player =
|
|
549
|
+
local player = PlayerMock.new()
|
|
554
550
|
local tracker, destroy = makeTracker(player)
|
|
555
551
|
|
|
556
552
|
tracker:SetOwnershipOverride("doesNotExist", true)
|
|
@@ -561,7 +557,7 @@ describe("PlayerAssetOwnershipTracker override replication", function()
|
|
|
561
557
|
end)
|
|
562
558
|
|
|
563
559
|
it("should remove the attribute once the only override is cleared", function()
|
|
564
|
-
local player =
|
|
560
|
+
local player = PlayerMock.new()
|
|
565
561
|
local tracker, destroy = makeTracker(player)
|
|
566
562
|
|
|
567
563
|
tracker:SetOwnershipOverride("swordKey", true)
|
|
@@ -20,8 +20,6 @@ local describe = Jest.Globals.describe
|
|
|
20
20
|
local expect = Jest.Globals.expect
|
|
21
21
|
local it = Jest.Globals.it
|
|
22
22
|
|
|
23
|
-
-- Maps asset keys to numeric ids. Any key not present converts to nil, which exercises the
|
|
24
|
-
-- "no asset with key" reject paths.
|
|
25
23
|
local KEY_TO_ID = {
|
|
26
24
|
swordKey = 111,
|
|
27
25
|
shieldKey = 222,
|
|
@@ -65,8 +63,6 @@ local function setup()
|
|
|
65
63
|
}
|
|
66
64
|
end
|
|
67
65
|
|
|
68
|
-
-- Builds a non-promptable tracker (as used for the game asset type), which should reject
|
|
69
|
-
-- prompts instead of surfacing them.
|
|
70
66
|
local function setupNonPromptable()
|
|
71
67
|
local tracker = PlayerAssetMarketTracker.new(GameConfigAssetTypes.GAME, convertIds, observeIdsBrio, false)
|
|
72
68
|
|
|
@@ -78,8 +74,6 @@ local function setupNonPromptable()
|
|
|
78
74
|
}
|
|
79
75
|
end
|
|
80
76
|
|
|
81
|
-
-- Drives a full prompt: fires PromisePromptPurchase, waits for ShowPromptRequested to surface the
|
|
82
|
-
-- resolved id, then feeds the purchase result back in. Returns the tracking promise and the id.
|
|
83
77
|
local function promptAndCapture(tracker, idOrKey)
|
|
84
78
|
local capturedId
|
|
85
79
|
local conn = tracker.ShowPromptRequested:Connect(function(id)
|
|
@@ -278,7 +272,6 @@ describe("PlayerAssetMarketTracker:PromisePromptPurchase()", function()
|
|
|
278
272
|
local secondOutcome = PromiseTestUtils.awaitOutcome(context.tracker:PromisePromptPurchase("shieldKey"), 5)
|
|
279
273
|
expect(secondOutcome).toEqual("rejected")
|
|
280
274
|
|
|
281
|
-
-- Close out the first prompt so nothing leaks.
|
|
282
275
|
context.tracker:HandlePurchaseEvent(firstId, true)
|
|
283
276
|
context.tracker:HandlePromptClosedEvent(firstId)
|
|
284
277
|
PromiseTestUtils.awaitSettled(firstPromise, 5)
|
|
@@ -317,7 +310,6 @@ describe("PlayerAssetMarketTracker prompt open counting", function()
|
|
|
317
310
|
PromiseTestUtils.awaitSettled(promise, 5)
|
|
318
311
|
sub:Destroy()
|
|
319
312
|
|
|
320
|
-
-- Should have observed the initial 0 and at least one increment to 1.
|
|
321
313
|
expect(counts[1]).toEqual(0)
|
|
322
314
|
local sawOpen = false
|
|
323
315
|
for _, value in counts do
|
|
@@ -18,6 +18,7 @@ local Observable = require("Observable")
|
|
|
18
18
|
local PlayerAssetMarketTracker = require("PlayerAssetMarketTracker")
|
|
19
19
|
local PlayerAssetMarketTrackerInterface = require("PlayerAssetMarketTrackerInterface")
|
|
20
20
|
local PlayerAssetOwnershipTracker = require("PlayerAssetOwnershipTracker")
|
|
21
|
+
local PlayerMock = require("PlayerMock")
|
|
21
22
|
local Promise = require("Promise")
|
|
22
23
|
local Rx = require("Rx")
|
|
23
24
|
local ServiceBag = require("ServiceBag")
|
|
@@ -98,6 +99,18 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
98
99
|
MarketplaceService:PromptBundlePurchase(self._player, bundleId)
|
|
99
100
|
end))
|
|
100
101
|
self._maid:GiveTask(pass.ShowPromptRequested:Connect(function(gamePassId)
|
|
102
|
+
if PlayerMock.isMock(self._player) then
|
|
103
|
+
-- The engine cannot prompt a mock; answer a frame later with the decision injected
|
|
104
|
+
-- through [PlayerMock.writeLookup] (default: declined), routed through the same
|
|
105
|
+
-- handler the engine's PromptGamePassPurchaseFinished would reach.
|
|
106
|
+
local isPurchased =
|
|
107
|
+
PlayerMock.readLookup(self._player, "MarketplaceService.PromptGamePassPurchase", gamePassId)
|
|
108
|
+
self._maid:GiveTask(task.defer(function()
|
|
109
|
+
(self :: any):_handleGamePassPromptFinished(gamePassId, isPurchased)
|
|
110
|
+
end))
|
|
111
|
+
return
|
|
112
|
+
end
|
|
113
|
+
|
|
101
114
|
MarketplaceService:PromptGamePassPurchase(self._player, gamePassId)
|
|
102
115
|
end))
|
|
103
116
|
self._maid:GiveTask(product.ShowPromptRequested:Connect(function(productId)
|
|
@@ -124,7 +137,11 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
124
137
|
|
|
125
138
|
-- Configure gamepass to be a bit special
|
|
126
139
|
passOwnership:SetQueryOwnershipCallback(function(gamePassId)
|
|
127
|
-
|
|
140
|
+
local userId = if PlayerMock.isMock(self._player)
|
|
141
|
+
then PlayerMock.read(self._player, "UserId")
|
|
142
|
+
else self._player.UserId
|
|
143
|
+
|
|
144
|
+
return MarketplaceUtils.promiseUserOwnsGamePass(userId, gamePassId)
|
|
128
145
|
end)
|
|
129
146
|
|
|
130
147
|
-- Configure assets too
|
|
@@ -145,7 +162,10 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
145
162
|
end)
|
|
146
163
|
|
|
147
164
|
membershipOwnership:SetQueryOwnershipCallback(function(membershipType)
|
|
148
|
-
|
|
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)
|
|
149
169
|
end)
|
|
150
170
|
|
|
151
171
|
-- Paid-access game ownership is queried through PlayerOwnsAssetAsync
|
|
@@ -156,6 +176,25 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
156
176
|
return self
|
|
157
177
|
end
|
|
158
178
|
|
|
179
|
+
--[=[
|
|
180
|
+
Applies a gamepass prompt result to this realm's tracker, exactly as the engine's
|
|
181
|
+
PromptGamePassPurchaseFinished handler would. Only invoked for a [PlayerMock] (see the
|
|
182
|
+
ShowPromptRequested mock branch); [PlayerProductManagerClient] overrides this to also
|
|
183
|
+
forward the result to the server over remoting, matching its engine handler.
|
|
184
|
+
|
|
185
|
+
@param gamePassId number
|
|
186
|
+
@param isPurchased boolean
|
|
187
|
+
]=]
|
|
188
|
+
function PlayerProductManagerBase._handleGamePassPromptFinished(
|
|
189
|
+
self: PlayerProductManagerBase,
|
|
190
|
+
gamePassId: number,
|
|
191
|
+
isPurchased: boolean
|
|
192
|
+
)
|
|
193
|
+
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.PASS) :: any
|
|
194
|
+
tracker:HandlePromptClosedEvent(gamePassId)
|
|
195
|
+
tracker:HandlePurchaseEvent(gamePassId, isPurchased)
|
|
196
|
+
end
|
|
197
|
+
|
|
159
198
|
function PlayerProductManagerBase.ExportMarketTrackers(self: PlayerProductManagerBase, parent)
|
|
160
199
|
for assetType: GameConfigAssetTypes.GameConfigAssetType, assetMarketTracker in self._assetMarketTrackers do
|
|
161
200
|
local folder = self._maid:Add(Instance.new("Folder"))
|