@quenty/gameproductservice 14.55.0 → 14.57.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 +26 -25
- package/src/Shared/GameProductDataService.spec.lua +137 -0
- package/src/Shared/Ownership/PlayerAssetOwnershipTracker.spec.lua +242 -0
- package/src/Shared/Trackers/PlayerAssetMarketTracker.lua +25 -1
- package/src/Shared/Trackers/PlayerAssetMarketTracker.spec.lua +366 -0
- package/src/Shared/Trackers/PlayerProductManagerBase.lua +13 -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.57.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.56.0...@quenty/gameproductservice@14.57.0) (2026-07-20)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- Strict typing on tests ([efbc458](https://github.com/Quenty/NevermoreEngine/commit/efbc45882fac95755ea4ff4e007c5f71bedebf6f))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **gameproductservice:** add paid-access game ownership tracking ([581a595](https://github.com/Quenty/NevermoreEngine/commit/581a5950d433ea4d6dfbcc33e88f254f9f13e14c))
|
|
15
|
+
|
|
16
|
+
# [14.56.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.55.0...@quenty/gameproductservice@14.56.0) (2026-07-18)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @quenty/gameproductservice
|
|
19
|
+
|
|
6
20
|
# [14.55.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.54.1...@quenty/gameproductservice@14.55.0) (2026-07-18)
|
|
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.57.0",
|
|
4
4
|
"description": "Generalized monetization system for handling products and purchases correctly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -30,35 +30,36 @@
|
|
|
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.32.0",
|
|
34
|
+
"@quenty/avatareditorutils": "7.42.0",
|
|
35
|
+
"@quenty/baseobject": "10.14.0",
|
|
36
|
+
"@quenty/binder": "14.39.0",
|
|
37
|
+
"@quenty/brio": "14.32.0",
|
|
38
|
+
"@quenty/cmdrservice": "13.49.0",
|
|
39
39
|
"@quenty/enumutils": "3.4.6",
|
|
40
|
-
"@quenty/gameconfig": "12.
|
|
41
|
-
"@quenty/instanceutils": "13.
|
|
40
|
+
"@quenty/gameconfig": "12.54.0",
|
|
41
|
+
"@quenty/instanceutils": "13.32.0",
|
|
42
42
|
"@quenty/loader": "10.11.0",
|
|
43
|
-
"@quenty/maid": "3.
|
|
44
|
-
"@quenty/marketplaceutils": "11.
|
|
43
|
+
"@quenty/maid": "3.10.0",
|
|
44
|
+
"@quenty/marketplaceutils": "11.24.0",
|
|
45
45
|
"@quenty/nevermore-test-runner": "1.4.0",
|
|
46
|
-
"@quenty/observablecollection": "12.
|
|
47
|
-
"@quenty/playerbinder": "14.
|
|
48
|
-
"@quenty/playerutils": "8.
|
|
49
|
-
"@quenty/promise": "10.
|
|
50
|
-
"@quenty/promisemaid": "5.
|
|
51
|
-
"@quenty/receiptprocessing": "7.
|
|
52
|
-
"@quenty/remoting": "12.
|
|
53
|
-
"@quenty/rx": "13.
|
|
54
|
-
"@quenty/rxbinderutils": "14.
|
|
55
|
-
"@quenty/servicebag": "11.
|
|
46
|
+
"@quenty/observablecollection": "12.41.0",
|
|
47
|
+
"@quenty/playerbinder": "14.39.0",
|
|
48
|
+
"@quenty/playerutils": "8.35.0",
|
|
49
|
+
"@quenty/promise": "10.20.0",
|
|
50
|
+
"@quenty/promisemaid": "5.20.0",
|
|
51
|
+
"@quenty/receiptprocessing": "7.36.0",
|
|
52
|
+
"@quenty/remoting": "12.34.0",
|
|
53
|
+
"@quenty/rx": "13.30.0",
|
|
54
|
+
"@quenty/rxbinderutils": "14.39.0",
|
|
55
|
+
"@quenty/servicebag": "11.19.0",
|
|
56
56
|
"@quenty/signal": "7.13.1",
|
|
57
|
-
"@quenty/statestack": "14.
|
|
57
|
+
"@quenty/statestack": "14.34.0",
|
|
58
58
|
"@quenty/string": "3.3.7",
|
|
59
59
|
"@quenty/table": "3.9.2",
|
|
60
|
-
"@quenty/tie": "10.
|
|
61
|
-
"@quenty/valueobject": "13.
|
|
60
|
+
"@quenty/tie": "10.43.0",
|
|
61
|
+
"@quenty/valueobject": "13.33.0",
|
|
62
|
+
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
62
63
|
},
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "2c903e91ae2ea1702ae1ce94af20af83af81e4fe"
|
|
64
65
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
Integration coverage for GameProductDataService driven through a real ServiceBag. Only
|
|
4
|
+
GameProductDataService (and its dependency TieRealmService) is registered, so the heavy
|
|
5
|
+
binder/MarketplaceService graph is never started. This focuses on the pieces that do not
|
|
6
|
+
require a live Player: the exported purchase signals, the server-only prompting ValueObject,
|
|
7
|
+
and the prompt guard's realm behavior. The realm is forced explicitly so the test is not
|
|
8
|
+
sensitive to where the runner executes.
|
|
9
|
+
|
|
10
|
+
@class GameProductDataService.spec.lua
|
|
11
|
+
]]
|
|
12
|
+
local require = require(script.Parent.loader).load(script)
|
|
13
|
+
|
|
14
|
+
local GameProductDataService = require("GameProductDataService")
|
|
15
|
+
local Jest = require("Jest")
|
|
16
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
17
|
+
local ServiceBag = require("ServiceBag")
|
|
18
|
+
local Signal = require("Signal")
|
|
19
|
+
local TieRealmService = require("TieRealmService")
|
|
20
|
+
local TieRealms = require("TieRealms")
|
|
21
|
+
|
|
22
|
+
local describe = Jest.Globals.describe
|
|
23
|
+
local expect = Jest.Globals.expect
|
|
24
|
+
local it = Jest.Globals.it
|
|
25
|
+
|
|
26
|
+
local function setup(tieRealm: TieRealms.TieRealm?)
|
|
27
|
+
local serviceBag = ServiceBag.new()
|
|
28
|
+
local tieRealmService = (serviceBag:GetService(TieRealmService) :: any) :: TieRealmService.TieRealmService
|
|
29
|
+
local gameProductDataService = (
|
|
30
|
+
serviceBag:GetService(GameProductDataService) :: any
|
|
31
|
+
) :: GameProductDataService.GameProductDataService
|
|
32
|
+
serviceBag:Init()
|
|
33
|
+
tieRealmService:SetTieRealm(tieRealm or TieRealms.SERVER)
|
|
34
|
+
serviceBag:Start()
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
serviceBag = serviceBag,
|
|
38
|
+
tieRealmService = tieRealmService,
|
|
39
|
+
gameProductDataService = gameProductDataService,
|
|
40
|
+
destroy = function()
|
|
41
|
+
serviceBag:Destroy()
|
|
42
|
+
end,
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe("GameProductDataService purchase signals", function()
|
|
47
|
+
it("should expose the six purchase signals after init", function()
|
|
48
|
+
local context = setup()
|
|
49
|
+
local service = context.gameProductDataService
|
|
50
|
+
|
|
51
|
+
for _, signalName in
|
|
52
|
+
{
|
|
53
|
+
"GamePassPurchased",
|
|
54
|
+
"ProductPurchased",
|
|
55
|
+
"AssetPurchased",
|
|
56
|
+
"BundlePurchased",
|
|
57
|
+
"SubscriptionPurchased",
|
|
58
|
+
"MembershipPurchased",
|
|
59
|
+
}
|
|
60
|
+
do
|
|
61
|
+
expect(Signal.isSignal((service :: any)[signalName])).toEqual(true)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context.destroy()
|
|
65
|
+
end)
|
|
66
|
+
end)
|
|
67
|
+
|
|
68
|
+
describe("GameProductDataService server-only prompting", function()
|
|
69
|
+
it("should default to disabled", function()
|
|
70
|
+
local context = setup()
|
|
71
|
+
expect(context.gameProductDataService:GetServerOnlyPromptingValue().Value).toEqual(false)
|
|
72
|
+
context.destroy()
|
|
73
|
+
end)
|
|
74
|
+
|
|
75
|
+
it("should enable and disable via SetServerOnlyPrompting on the server", function()
|
|
76
|
+
local context = setup()
|
|
77
|
+
local service = context.gameProductDataService
|
|
78
|
+
|
|
79
|
+
service:SetServerOnlyPrompting(true)
|
|
80
|
+
expect(service:GetServerOnlyPromptingValue().Value).toEqual(true)
|
|
81
|
+
|
|
82
|
+
service:SetServerOnlyPrompting(false)
|
|
83
|
+
expect(service:GetServerOnlyPromptingValue().Value).toEqual(false)
|
|
84
|
+
context.destroy()
|
|
85
|
+
end)
|
|
86
|
+
|
|
87
|
+
it("should replicate the change through the ValueObject observable", function()
|
|
88
|
+
local context = setup()
|
|
89
|
+
local service = context.gameProductDataService
|
|
90
|
+
|
|
91
|
+
local values = {}
|
|
92
|
+
local sub = service:GetServerOnlyPromptingValue():Observe():Subscribe(function(value)
|
|
93
|
+
table.insert(values, value)
|
|
94
|
+
end)
|
|
95
|
+
|
|
96
|
+
service:SetServerOnlyPrompting(true)
|
|
97
|
+
sub:Destroy()
|
|
98
|
+
|
|
99
|
+
expect(values[1]).toEqual(false)
|
|
100
|
+
expect(values[#values]).toEqual(true)
|
|
101
|
+
context.destroy()
|
|
102
|
+
end)
|
|
103
|
+
|
|
104
|
+
it("should reject a non-boolean argument", function()
|
|
105
|
+
local context = setup()
|
|
106
|
+
local service = context.gameProductDataService
|
|
107
|
+
|
|
108
|
+
expect(function()
|
|
109
|
+
service:SetServerOnlyPrompting("nope" :: any)
|
|
110
|
+
end).toThrow()
|
|
111
|
+
context.destroy()
|
|
112
|
+
end)
|
|
113
|
+
|
|
114
|
+
it("should refuse to configure server-only prompting from the client realm", function()
|
|
115
|
+
local context = setup(TieRealms.CLIENT)
|
|
116
|
+
local service = context.gameProductDataService
|
|
117
|
+
|
|
118
|
+
expect(function()
|
|
119
|
+
service:SetServerOnlyPrompting(true)
|
|
120
|
+
end).toThrow()
|
|
121
|
+
context.destroy()
|
|
122
|
+
end)
|
|
123
|
+
end)
|
|
124
|
+
|
|
125
|
+
describe("GameProductDataService prompt guard", function()
|
|
126
|
+
it("should resolve immediately on the server realm", function()
|
|
127
|
+
local context = setup(TieRealms.SERVER)
|
|
128
|
+
local service = context.gameProductDataService
|
|
129
|
+
|
|
130
|
+
local fakePlayer = Instance.new("Folder")
|
|
131
|
+
local outcome = PromiseTestUtils.awaitOutcome(service:_promiseServerOnlyPromptingGuard(fakePlayer :: any), 5)
|
|
132
|
+
expect(outcome).toEqual("resolved")
|
|
133
|
+
|
|
134
|
+
fakePlayer:Destroy()
|
|
135
|
+
context.destroy()
|
|
136
|
+
end)
|
|
137
|
+
end)
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
Unit coverage for PlayerAssetOwnershipTracker. The tracker is constructed directly with a fake
|
|
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 plain Folder stands in for
|
|
6
|
+
the player because the tracker only stores the player, never reads properties off it in the code
|
|
7
|
+
paths under test. Each test destroys everything it creates so nothing leaks into the shared test
|
|
8
|
+
place.
|
|
9
|
+
|
|
10
|
+
@class PlayerAssetOwnershipTracker.spec.lua
|
|
11
|
+
]]
|
|
12
|
+
local require = require(script.Parent.loader).load(script)
|
|
13
|
+
|
|
14
|
+
local Brio = require("Brio")
|
|
15
|
+
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
16
|
+
local GameConfigPicker = require("GameConfigPicker")
|
|
17
|
+
local Jest = require("Jest")
|
|
18
|
+
local Observable = require("Observable")
|
|
19
|
+
local PlayerAssetOwnershipTracker = require("PlayerAssetOwnershipTracker")
|
|
20
|
+
local Promise = require("Promise")
|
|
21
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
22
|
+
local Signal = require("Signal")
|
|
23
|
+
|
|
24
|
+
local describe = Jest.Globals.describe
|
|
25
|
+
local expect = Jest.Globals.expect
|
|
26
|
+
local it = Jest.Globals.it
|
|
27
|
+
|
|
28
|
+
local KEY_TO_ID = {
|
|
29
|
+
swordKey = 111,
|
|
30
|
+
shieldKey = 222,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
local function toId(idOrKey)
|
|
34
|
+
if type(idOrKey) == "number" then
|
|
35
|
+
return idOrKey
|
|
36
|
+
end
|
|
37
|
+
return KEY_TO_ID[idOrKey]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
-- Minimal GameConfigPicker stand-in covering the two methods the tracker calls.
|
|
41
|
+
local function makeConfigPicker()
|
|
42
|
+
return {
|
|
43
|
+
ToAssetId = function(_self, _assetType, idOrKey)
|
|
44
|
+
return toId(idOrKey)
|
|
45
|
+
end,
|
|
46
|
+
ObserveToAssetIdBrio = function(_self, _assetType, idOrKey)
|
|
47
|
+
return Observable.new(function(sub)
|
|
48
|
+
local id = toId(idOrKey)
|
|
49
|
+
if not id then
|
|
50
|
+
sub:Complete()
|
|
51
|
+
return nil
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
local brio = Brio.new(id)
|
|
55
|
+
sub:Fire(brio)
|
|
56
|
+
|
|
57
|
+
return function()
|
|
58
|
+
brio:Destroy()
|
|
59
|
+
end
|
|
60
|
+
end)
|
|
61
|
+
end,
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
local function setup()
|
|
66
|
+
local purchased = Signal.new()
|
|
67
|
+
local marketTracker = { Purchased = purchased }
|
|
68
|
+
local player = Instance.new("Folder")
|
|
69
|
+
player.Name = "FakePlayer"
|
|
70
|
+
|
|
71
|
+
local tracker = PlayerAssetOwnershipTracker.new(
|
|
72
|
+
(player :: any) :: Player,
|
|
73
|
+
(makeConfigPicker() :: any) :: GameConfigPicker.GameConfigPicker,
|
|
74
|
+
GameConfigAssetTypes.PASS,
|
|
75
|
+
marketTracker
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
tracker = tracker,
|
|
80
|
+
marketTracker = marketTracker,
|
|
81
|
+
destroy = function()
|
|
82
|
+
tracker:Destroy()
|
|
83
|
+
purchased:Destroy()
|
|
84
|
+
player:Destroy()
|
|
85
|
+
end,
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe("PlayerAssetOwnershipTracker:PromiseOwnsAsset()", function()
|
|
90
|
+
it("should reject for an unknown key", function()
|
|
91
|
+
local context = setup()
|
|
92
|
+
|
|
93
|
+
local outcome = PromiseTestUtils.awaitOutcome(context.tracker:PromiseOwnsAsset("doesNotExist"), 5)
|
|
94
|
+
expect(outcome).toEqual("rejected")
|
|
95
|
+
context.destroy()
|
|
96
|
+
end)
|
|
97
|
+
|
|
98
|
+
it("should reject when no ownership callback is set and the asset is not already owned", function()
|
|
99
|
+
local context = setup()
|
|
100
|
+
|
|
101
|
+
local outcome = PromiseTestUtils.awaitOutcome(context.tracker:PromiseOwnsAsset("swordKey"), 5)
|
|
102
|
+
expect(outcome).toEqual("rejected")
|
|
103
|
+
context.destroy()
|
|
104
|
+
end)
|
|
105
|
+
|
|
106
|
+
it("should resolve true when the callback reports ownership", function()
|
|
107
|
+
local context = setup()
|
|
108
|
+
context.tracker:SetQueryOwnershipCallback(function()
|
|
109
|
+
return Promise.resolved(true)
|
|
110
|
+
end)
|
|
111
|
+
|
|
112
|
+
local promise = context.tracker:PromiseOwnsAsset("swordKey")
|
|
113
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
114
|
+
local ok, owns = promise:Yield()
|
|
115
|
+
expect(ok).toEqual(true)
|
|
116
|
+
expect(owns).toEqual(true)
|
|
117
|
+
context.destroy()
|
|
118
|
+
end)
|
|
119
|
+
|
|
120
|
+
it("should resolve false when the callback reports no ownership", function()
|
|
121
|
+
local context = setup()
|
|
122
|
+
context.tracker:SetQueryOwnershipCallback(function()
|
|
123
|
+
return Promise.resolved(false)
|
|
124
|
+
end)
|
|
125
|
+
|
|
126
|
+
local promise = context.tracker:PromiseOwnsAsset("swordKey")
|
|
127
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
128
|
+
local ok, owns = promise:Yield()
|
|
129
|
+
expect(ok).toEqual(true)
|
|
130
|
+
expect(owns).toEqual(false)
|
|
131
|
+
context.destroy()
|
|
132
|
+
end)
|
|
133
|
+
|
|
134
|
+
it("should cache the callback result and not query twice", function()
|
|
135
|
+
local context = setup()
|
|
136
|
+
|
|
137
|
+
local callCount = 0
|
|
138
|
+
context.tracker:SetQueryOwnershipCallback(function()
|
|
139
|
+
callCount += 1
|
|
140
|
+
return Promise.resolved(true)
|
|
141
|
+
end)
|
|
142
|
+
|
|
143
|
+
local first = context.tracker:PromiseOwnsAsset("swordKey")
|
|
144
|
+
PromiseTestUtils.awaitSettled(first, 5)
|
|
145
|
+
local second = context.tracker:PromiseOwnsAsset("swordKey")
|
|
146
|
+
PromiseTestUtils.awaitSettled(second, 5)
|
|
147
|
+
|
|
148
|
+
expect(callCount).toEqual(1)
|
|
149
|
+
local _, owns = second:Yield()
|
|
150
|
+
expect(owns).toEqual(true)
|
|
151
|
+
context.destroy()
|
|
152
|
+
end)
|
|
153
|
+
end)
|
|
154
|
+
|
|
155
|
+
describe("PlayerAssetOwnershipTracker:SetOwnership()", function()
|
|
156
|
+
it("should mark an asset owned so PromiseOwnsAsset resolves true without a callback", function()
|
|
157
|
+
local context = setup()
|
|
158
|
+
|
|
159
|
+
context.tracker:SetOwnership(KEY_TO_ID.swordKey, true)
|
|
160
|
+
|
|
161
|
+
local promise = context.tracker:PromiseOwnsAsset("swordKey")
|
|
162
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
163
|
+
local _, owns = promise:Yield()
|
|
164
|
+
expect(owns).toEqual(true)
|
|
165
|
+
context.destroy()
|
|
166
|
+
end)
|
|
167
|
+
|
|
168
|
+
it("should ignore an unknown key without erroring", function()
|
|
169
|
+
local context = setup()
|
|
170
|
+
-- Should warn and no-op rather than throw.
|
|
171
|
+
context.tracker:SetOwnership("doesNotExist", true)
|
|
172
|
+
context.destroy()
|
|
173
|
+
end)
|
|
174
|
+
end)
|
|
175
|
+
|
|
176
|
+
describe("PlayerAssetOwnershipTracker market tracker integration", function()
|
|
177
|
+
it("should mark ownership when the market tracker fires Purchased", function()
|
|
178
|
+
local context = setup()
|
|
179
|
+
|
|
180
|
+
context.marketTracker.Purchased:Fire(KEY_TO_ID.swordKey)
|
|
181
|
+
|
|
182
|
+
local promise = context.tracker:PromiseOwnsAsset("swordKey")
|
|
183
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
184
|
+
local _, owns = promise:Yield()
|
|
185
|
+
expect(owns).toEqual(true)
|
|
186
|
+
context.destroy()
|
|
187
|
+
end)
|
|
188
|
+
end)
|
|
189
|
+
|
|
190
|
+
describe("PlayerAssetOwnershipTracker:SetQueryOwnershipCallback()", function()
|
|
191
|
+
it("should clear the cache so a new callback is consulted", function()
|
|
192
|
+
local context = setup()
|
|
193
|
+
|
|
194
|
+
context.tracker:SetQueryOwnershipCallback(function()
|
|
195
|
+
return Promise.resolved(false)
|
|
196
|
+
end)
|
|
197
|
+
local first = context.tracker:PromiseOwnsAsset("swordKey")
|
|
198
|
+
PromiseTestUtils.awaitSettled(first, 5)
|
|
199
|
+
local _, firstOwns = first:Yield()
|
|
200
|
+
expect(firstOwns).toEqual(false)
|
|
201
|
+
|
|
202
|
+
local secondCallbackCalls = 0
|
|
203
|
+
context.tracker:SetQueryOwnershipCallback(function()
|
|
204
|
+
secondCallbackCalls += 1
|
|
205
|
+
return Promise.resolved(true)
|
|
206
|
+
end)
|
|
207
|
+
|
|
208
|
+
local second = context.tracker:PromiseOwnsAsset("swordKey")
|
|
209
|
+
PromiseTestUtils.awaitSettled(second, 5)
|
|
210
|
+
expect(secondCallbackCalls).toEqual(1)
|
|
211
|
+
local _, secondOwns = second:Yield()
|
|
212
|
+
expect(secondOwns).toEqual(true)
|
|
213
|
+
context.destroy()
|
|
214
|
+
end)
|
|
215
|
+
end)
|
|
216
|
+
|
|
217
|
+
describe("PlayerAssetOwnershipTracker:ObserveOwnsAsset()", function()
|
|
218
|
+
it("should emit false, then true once ownership is set", function()
|
|
219
|
+
local context = setup()
|
|
220
|
+
context.tracker:SetQueryOwnershipCallback(function()
|
|
221
|
+
return Promise.resolved(false)
|
|
222
|
+
end)
|
|
223
|
+
|
|
224
|
+
local values = {}
|
|
225
|
+
local sub = context.tracker:ObserveOwnsAsset(KEY_TO_ID.swordKey):Subscribe(function(value)
|
|
226
|
+
table.insert(values, value)
|
|
227
|
+
end)
|
|
228
|
+
|
|
229
|
+
expect(PromiseTestUtils.awaitValue(function()
|
|
230
|
+
return #values >= 1
|
|
231
|
+
end, 5)).toEqual(true)
|
|
232
|
+
expect(values[1]).toEqual(false)
|
|
233
|
+
|
|
234
|
+
context.tracker:SetOwnership(KEY_TO_ID.swordKey, true)
|
|
235
|
+
|
|
236
|
+
expect(PromiseTestUtils.awaitValue(function()
|
|
237
|
+
return values[#values] == true
|
|
238
|
+
end, 5)).toEqual(true)
|
|
239
|
+
sub:Destroy()
|
|
240
|
+
context.destroy()
|
|
241
|
+
end)
|
|
242
|
+
end)
|
|
@@ -26,6 +26,7 @@ export type PlayerAssetMarketTracker =
|
|
|
26
26
|
typeof(setmetatable(
|
|
27
27
|
{} :: {
|
|
28
28
|
_assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
29
|
+
_promptable: boolean,
|
|
29
30
|
_convertIds: (string | number) -> number?,
|
|
30
31
|
_observeIdsBrio: (string | number) -> Observable.Observable<Brio.Brio<number>>,
|
|
31
32
|
_pendingPurchasePromises: { Promise.Promise<boolean> },
|
|
@@ -51,18 +52,22 @@ export type PlayerAssetMarketTracker =
|
|
|
51
52
|
@param assetType GameConfigAssetTypes
|
|
52
53
|
@param convertIds function
|
|
53
54
|
@param observeIdsBrio function
|
|
55
|
+
@param promptable boolean? -- Defaults to true. When false, [PlayerAssetMarketTracker.PromisePromptPurchase] rejects instead of prompting. Used for asset types like games that cannot be prompted in-experience.
|
|
54
56
|
@return PlayerAssetMarketTracker
|
|
55
57
|
]=]
|
|
56
58
|
function PlayerAssetMarketTracker.new(
|
|
57
59
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
58
60
|
convertIds,
|
|
59
|
-
observeIdsBrio
|
|
61
|
+
observeIdsBrio,
|
|
62
|
+
promptable: boolean?
|
|
60
63
|
): PlayerAssetMarketTracker
|
|
61
64
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
65
|
+
assert(type(promptable) == "boolean" or promptable == nil, "Bad promptable")
|
|
62
66
|
|
|
63
67
|
local self: PlayerAssetMarketTracker = setmetatable(BaseObject.new() :: any, PlayerAssetMarketTracker)
|
|
64
68
|
|
|
65
69
|
self._assetType = assert(assetType, "No assetType")
|
|
70
|
+
self._promptable = promptable ~= false
|
|
66
71
|
self._convertIds = assert(convertIds, "No convertIds")
|
|
67
72
|
self._observeIdsBrio = assert(observeIdsBrio, "No observeIdsBrio")
|
|
68
73
|
|
|
@@ -187,6 +192,15 @@ function PlayerAssetMarketTracker.PromisePromptPurchase(
|
|
|
187
192
|
): Promise.Promise<boolean>
|
|
188
193
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
189
194
|
|
|
195
|
+
if not self._promptable then
|
|
196
|
+
return Promise.rejected(
|
|
197
|
+
string.format(
|
|
198
|
+
"[PlayerAssetMarketTracker.PromisePromptPurchase] - The %s asset type cannot be prompted for purchase in-experience. Use ownership checks instead.",
|
|
199
|
+
tostring(self._assetType)
|
|
200
|
+
)
|
|
201
|
+
)
|
|
202
|
+
end
|
|
203
|
+
|
|
190
204
|
local id = self._convertIds(idOrKey)
|
|
191
205
|
if not id then
|
|
192
206
|
return Promise.rejected(
|
|
@@ -294,6 +308,16 @@ function PlayerAssetMarketTracker.GetAssetType(self: PlayerAssetMarketTracker):
|
|
|
294
308
|
return self._assetType
|
|
295
309
|
end
|
|
296
310
|
|
|
311
|
+
--[=[
|
|
312
|
+
Returns whether this asset type can be prompted for purchase in-experience. When
|
|
313
|
+
false, [PlayerAssetMarketTracker.PromisePromptPurchase] rejects.
|
|
314
|
+
|
|
315
|
+
@return boolean
|
|
316
|
+
]=]
|
|
317
|
+
function PlayerAssetMarketTracker.IsPromptable(self: PlayerAssetMarketTracker): boolean
|
|
318
|
+
return self._promptable
|
|
319
|
+
end
|
|
320
|
+
|
|
297
321
|
--[=[
|
|
298
322
|
Returns true if item has been purchased this session
|
|
299
323
|
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
Unit coverage for PlayerAssetMarketTracker. The tracker is constructed directly with a fake
|
|
4
|
+
id-conversion table and a synchronous brio observable, so no ServiceBag, GameConfig, or real
|
|
5
|
+
MarketplaceService is involved. Each test builds a fresh tracker and destroys it so nothing
|
|
6
|
+
leaks into the shared test place.
|
|
7
|
+
|
|
8
|
+
@class PlayerAssetMarketTracker.spec.lua
|
|
9
|
+
]]
|
|
10
|
+
local require = require(script.Parent.loader).load(script)
|
|
11
|
+
|
|
12
|
+
local Brio = require("Brio")
|
|
13
|
+
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
14
|
+
local Jest = require("Jest")
|
|
15
|
+
local Observable = require("Observable")
|
|
16
|
+
local PlayerAssetMarketTracker = require("PlayerAssetMarketTracker")
|
|
17
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
18
|
+
|
|
19
|
+
local describe = Jest.Globals.describe
|
|
20
|
+
local expect = Jest.Globals.expect
|
|
21
|
+
local it = Jest.Globals.it
|
|
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
|
+
local KEY_TO_ID = {
|
|
26
|
+
swordKey = 111,
|
|
27
|
+
shieldKey = 222,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
local function convertIds(idOrKey)
|
|
31
|
+
if type(idOrKey) == "number" then
|
|
32
|
+
return idOrKey
|
|
33
|
+
end
|
|
34
|
+
return KEY_TO_ID[idOrKey]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
-- Emits a single live brio wrapping the resolved id, synchronously on subscribe, then completes
|
|
38
|
+
-- for unknown keys. Synchronous emission lets ObserveAssetPurchased register the known id before
|
|
39
|
+
-- the test fires Purchased.
|
|
40
|
+
local function observeIdsBrio(idOrKey)
|
|
41
|
+
return Observable.new(function(sub)
|
|
42
|
+
local id = convertIds(idOrKey)
|
|
43
|
+
if not id then
|
|
44
|
+
sub:Complete()
|
|
45
|
+
return nil
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
local brio = Brio.new(id)
|
|
49
|
+
sub:Fire(brio)
|
|
50
|
+
|
|
51
|
+
return function()
|
|
52
|
+
brio:Destroy()
|
|
53
|
+
end
|
|
54
|
+
end)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
local function setup()
|
|
58
|
+
local tracker = PlayerAssetMarketTracker.new(GameConfigAssetTypes.PRODUCT, convertIds, observeIdsBrio)
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
tracker = tracker,
|
|
62
|
+
destroy = function()
|
|
63
|
+
tracker:Destroy()
|
|
64
|
+
end,
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
-- Builds a non-promptable tracker (as used for the game asset type), which should reject
|
|
69
|
+
-- prompts instead of surfacing them.
|
|
70
|
+
local function setupNonPromptable()
|
|
71
|
+
local tracker = PlayerAssetMarketTracker.new(GameConfigAssetTypes.GAME, convertIds, observeIdsBrio, false)
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
tracker = tracker,
|
|
75
|
+
destroy = function()
|
|
76
|
+
tracker:Destroy()
|
|
77
|
+
end,
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
|
|
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
|
+
local function promptAndCapture(tracker, idOrKey)
|
|
84
|
+
local capturedId
|
|
85
|
+
local conn = tracker.ShowPromptRequested:Connect(function(id)
|
|
86
|
+
capturedId = id
|
|
87
|
+
end)
|
|
88
|
+
|
|
89
|
+
local promise = tracker:PromisePromptPurchase(idOrKey)
|
|
90
|
+
PromiseTestUtils.awaitValue(function()
|
|
91
|
+
return capturedId ~= nil
|
|
92
|
+
end, 5)
|
|
93
|
+
conn:Disconnect()
|
|
94
|
+
|
|
95
|
+
return promise, capturedId
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe("PlayerAssetMarketTracker basics", function()
|
|
99
|
+
it("should report its asset type", function()
|
|
100
|
+
local context = setup()
|
|
101
|
+
expect(context.tracker:GetAssetType()).toEqual(GameConfigAssetTypes.PRODUCT)
|
|
102
|
+
context.destroy()
|
|
103
|
+
end)
|
|
104
|
+
|
|
105
|
+
it("should start with no prompt open", function()
|
|
106
|
+
local context = setup()
|
|
107
|
+
expect(context.tracker:IsPromptOpen()).toEqual(false)
|
|
108
|
+
context.destroy()
|
|
109
|
+
end)
|
|
110
|
+
|
|
111
|
+
it("should hold and return an ownership tracker", function()
|
|
112
|
+
local context = setup()
|
|
113
|
+
expect(context.tracker:GetOwnershipTracker()).toBeNil()
|
|
114
|
+
|
|
115
|
+
local fakeOwnershipTracker = {}
|
|
116
|
+
context.tracker:SetOwnershipTracker(fakeOwnershipTracker :: any)
|
|
117
|
+
expect(context.tracker:GetOwnershipTracker()).toEqual(fakeOwnershipTracker)
|
|
118
|
+
|
|
119
|
+
context.tracker:SetOwnershipTracker(nil)
|
|
120
|
+
expect(context.tracker:GetOwnershipTracker()).toBeNil()
|
|
121
|
+
context.destroy()
|
|
122
|
+
end)
|
|
123
|
+
|
|
124
|
+
it("should be promptable by default", function()
|
|
125
|
+
local context = setup()
|
|
126
|
+
expect(context.tracker:IsPromptable()).toEqual(true)
|
|
127
|
+
context.destroy()
|
|
128
|
+
end)
|
|
129
|
+
end)
|
|
130
|
+
|
|
131
|
+
describe("PlayerAssetMarketTracker non-promptable asset types", function()
|
|
132
|
+
it("should report IsPromptable() as false", function()
|
|
133
|
+
local context = setupNonPromptable()
|
|
134
|
+
expect(context.tracker:IsPromptable()).toEqual(false)
|
|
135
|
+
context.destroy()
|
|
136
|
+
end)
|
|
137
|
+
|
|
138
|
+
it("should reject PromisePromptPurchase for a known id without opening a prompt", function()
|
|
139
|
+
local context = setupNonPromptable()
|
|
140
|
+
|
|
141
|
+
local promptRequested = false
|
|
142
|
+
local conn = context.tracker.ShowPromptRequested:Connect(function()
|
|
143
|
+
promptRequested = true
|
|
144
|
+
end)
|
|
145
|
+
|
|
146
|
+
local outcome = PromiseTestUtils.awaitOutcome(context.tracker:PromisePromptPurchase("swordKey"), 5)
|
|
147
|
+
conn:Disconnect()
|
|
148
|
+
|
|
149
|
+
expect(outcome).toEqual("rejected")
|
|
150
|
+
expect(promptRequested).toEqual(false)
|
|
151
|
+
expect(context.tracker:IsPromptOpen()).toEqual(false)
|
|
152
|
+
context.destroy()
|
|
153
|
+
end)
|
|
154
|
+
|
|
155
|
+
it("should reject PromisePromptPurchase for an unknown key too", function()
|
|
156
|
+
local context = setupNonPromptable()
|
|
157
|
+
|
|
158
|
+
local outcome = PromiseTestUtils.awaitOutcome(context.tracker:PromisePromptPurchase("doesNotExist"), 5)
|
|
159
|
+
expect(outcome).toEqual("rejected")
|
|
160
|
+
context.destroy()
|
|
161
|
+
end)
|
|
162
|
+
end)
|
|
163
|
+
|
|
164
|
+
describe("PlayerAssetMarketTracker:HasPurchasedThisSession()", function()
|
|
165
|
+
it("should return false before anything is purchased", function()
|
|
166
|
+
local context = setup()
|
|
167
|
+
expect(context.tracker:HasPurchasedThisSession("swordKey")).toEqual(false)
|
|
168
|
+
context.destroy()
|
|
169
|
+
end)
|
|
170
|
+
|
|
171
|
+
it("should return true after a purchase event for that id", function()
|
|
172
|
+
local context = setup()
|
|
173
|
+
context.tracker:HandlePurchaseEvent(KEY_TO_ID.swordKey, true)
|
|
174
|
+
expect(context.tracker:HasPurchasedThisSession("swordKey")).toEqual(true)
|
|
175
|
+
context.destroy()
|
|
176
|
+
end)
|
|
177
|
+
|
|
178
|
+
it("should stay false for a different id than the one purchased", function()
|
|
179
|
+
local context = setup()
|
|
180
|
+
context.tracker:HandlePurchaseEvent(KEY_TO_ID.swordKey, true)
|
|
181
|
+
expect(context.tracker:HasPurchasedThisSession("shieldKey")).toEqual(false)
|
|
182
|
+
context.destroy()
|
|
183
|
+
end)
|
|
184
|
+
|
|
185
|
+
it("should return false for an unknown key", function()
|
|
186
|
+
local context = setup()
|
|
187
|
+
expect(context.tracker:HasPurchasedThisSession("doesNotExist")).toEqual(false)
|
|
188
|
+
context.destroy()
|
|
189
|
+
end)
|
|
190
|
+
|
|
191
|
+
it("should not mark a failed purchase as purchased", function()
|
|
192
|
+
local context = setup()
|
|
193
|
+
context.tracker:HandlePurchaseEvent(KEY_TO_ID.swordKey, false)
|
|
194
|
+
expect(context.tracker:HasPurchasedThisSession("swordKey")).toEqual(false)
|
|
195
|
+
context.destroy()
|
|
196
|
+
end)
|
|
197
|
+
end)
|
|
198
|
+
|
|
199
|
+
describe("PlayerAssetMarketTracker:HandlePurchaseEvent()", function()
|
|
200
|
+
it("should fire the Purchased signal with the id on a successful purchase", function()
|
|
201
|
+
local context = setup()
|
|
202
|
+
|
|
203
|
+
local fired = {}
|
|
204
|
+
local conn = context.tracker.Purchased:Connect(function(id)
|
|
205
|
+
table.insert(fired, id)
|
|
206
|
+
end)
|
|
207
|
+
|
|
208
|
+
context.tracker:HandlePurchaseEvent(KEY_TO_ID.swordKey, true)
|
|
209
|
+
conn:Disconnect()
|
|
210
|
+
|
|
211
|
+
expect(#fired).toEqual(1)
|
|
212
|
+
expect(fired[1]).toEqual(KEY_TO_ID.swordKey)
|
|
213
|
+
context.destroy()
|
|
214
|
+
end)
|
|
215
|
+
|
|
216
|
+
it("should not fire Purchased on a failed purchase", function()
|
|
217
|
+
local context = setup()
|
|
218
|
+
|
|
219
|
+
local firedCount = 0
|
|
220
|
+
local conn = context.tracker.Purchased:Connect(function()
|
|
221
|
+
firedCount += 1
|
|
222
|
+
end)
|
|
223
|
+
|
|
224
|
+
context.tracker:HandlePurchaseEvent(KEY_TO_ID.swordKey, false)
|
|
225
|
+
conn:Disconnect()
|
|
226
|
+
|
|
227
|
+
expect(firedCount).toEqual(0)
|
|
228
|
+
context.destroy()
|
|
229
|
+
end)
|
|
230
|
+
end)
|
|
231
|
+
|
|
232
|
+
describe("PlayerAssetMarketTracker:PromisePromptPurchase()", function()
|
|
233
|
+
it("should reject for an unknown key", function()
|
|
234
|
+
local context = setup()
|
|
235
|
+
|
|
236
|
+
local outcome = PromiseTestUtils.awaitOutcome(context.tracker:PromisePromptPurchase("doesNotExist"), 5)
|
|
237
|
+
expect(outcome).toEqual("rejected")
|
|
238
|
+
context.destroy()
|
|
239
|
+
end)
|
|
240
|
+
|
|
241
|
+
it("should request a prompt and resolve true once the purchase succeeds", function()
|
|
242
|
+
local context = setup()
|
|
243
|
+
|
|
244
|
+
local promise, capturedId = promptAndCapture(context.tracker, "swordKey")
|
|
245
|
+
expect(capturedId).toEqual(KEY_TO_ID.swordKey)
|
|
246
|
+
expect(context.tracker:IsPromptOpen()).toEqual(true)
|
|
247
|
+
|
|
248
|
+
context.tracker:HandlePurchaseEvent(capturedId, true)
|
|
249
|
+
context.tracker:HandlePromptClosedEvent(capturedId)
|
|
250
|
+
|
|
251
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
252
|
+
local ok, purchased = promise:Yield()
|
|
253
|
+
expect(ok).toEqual(true)
|
|
254
|
+
expect(purchased).toEqual(true)
|
|
255
|
+
context.destroy()
|
|
256
|
+
end)
|
|
257
|
+
|
|
258
|
+
it("should resolve false when the purchase is declined", function()
|
|
259
|
+
local context = setup()
|
|
260
|
+
|
|
261
|
+
local promise, capturedId = promptAndCapture(context.tracker, "swordKey")
|
|
262
|
+
context.tracker:HandlePurchaseEvent(capturedId, false)
|
|
263
|
+
context.tracker:HandlePromptClosedEvent(capturedId)
|
|
264
|
+
|
|
265
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
266
|
+
local ok, purchased = promise:Yield()
|
|
267
|
+
expect(ok).toEqual(true)
|
|
268
|
+
expect(purchased).toEqual(false)
|
|
269
|
+
context.destroy()
|
|
270
|
+
end)
|
|
271
|
+
|
|
272
|
+
it("should reject a second prompt while one is already open", function()
|
|
273
|
+
local context = setup()
|
|
274
|
+
|
|
275
|
+
local firstPromise, firstId = promptAndCapture(context.tracker, "swordKey")
|
|
276
|
+
expect(context.tracker:IsPromptOpen()).toEqual(true)
|
|
277
|
+
|
|
278
|
+
local secondOutcome = PromiseTestUtils.awaitOutcome(context.tracker:PromisePromptPurchase("shieldKey"), 5)
|
|
279
|
+
expect(secondOutcome).toEqual("rejected")
|
|
280
|
+
|
|
281
|
+
-- Close out the first prompt so nothing leaks.
|
|
282
|
+
context.tracker:HandlePurchaseEvent(firstId, true)
|
|
283
|
+
context.tracker:HandlePromptClosedEvent(firstId)
|
|
284
|
+
PromiseTestUtils.awaitSettled(firstPromise, 5)
|
|
285
|
+
context.destroy()
|
|
286
|
+
end)
|
|
287
|
+
end)
|
|
288
|
+
|
|
289
|
+
describe("PlayerAssetMarketTracker prompt open counting", function()
|
|
290
|
+
it("should report the prompt closed after HandlePromptClosedEvent", function()
|
|
291
|
+
local context = setup()
|
|
292
|
+
|
|
293
|
+
local promise, capturedId = promptAndCapture(context.tracker, "swordKey")
|
|
294
|
+
expect(context.tracker:IsPromptOpen()).toEqual(true)
|
|
295
|
+
|
|
296
|
+
context.tracker:HandlePurchaseEvent(capturedId, true)
|
|
297
|
+
context.tracker:HandlePromptClosedEvent(capturedId)
|
|
298
|
+
PromiseTestUtils.awaitSettled(promise, 5)
|
|
299
|
+
|
|
300
|
+
expect(PromiseTestUtils.awaitValue(function()
|
|
301
|
+
return not context.tracker:IsPromptOpen()
|
|
302
|
+
end, 5)).toEqual(true)
|
|
303
|
+
context.destroy()
|
|
304
|
+
end)
|
|
305
|
+
|
|
306
|
+
it("should surface the open count through ObservePromptOpenCount", function()
|
|
307
|
+
local context = setup()
|
|
308
|
+
|
|
309
|
+
local counts = {}
|
|
310
|
+
local sub = context.tracker:ObservePromptOpenCount():Subscribe(function(value)
|
|
311
|
+
table.insert(counts, value)
|
|
312
|
+
end)
|
|
313
|
+
|
|
314
|
+
local promise, capturedId = promptAndCapture(context.tracker, "swordKey")
|
|
315
|
+
context.tracker:HandlePurchaseEvent(capturedId, true)
|
|
316
|
+
context.tracker:HandlePromptClosedEvent(capturedId)
|
|
317
|
+
PromiseTestUtils.awaitSettled(promise, 5)
|
|
318
|
+
sub:Destroy()
|
|
319
|
+
|
|
320
|
+
-- Should have observed the initial 0 and at least one increment to 1.
|
|
321
|
+
expect(counts[1]).toEqual(0)
|
|
322
|
+
local sawOpen = false
|
|
323
|
+
for _, value in counts do
|
|
324
|
+
if value >= 1 then
|
|
325
|
+
sawOpen = true
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
expect(sawOpen).toEqual(true)
|
|
329
|
+
context.destroy()
|
|
330
|
+
end)
|
|
331
|
+
end)
|
|
332
|
+
|
|
333
|
+
describe("PlayerAssetMarketTracker:ObserveAssetPurchased()", function()
|
|
334
|
+
it("should fire when the tracked id is purchased", function()
|
|
335
|
+
local context = setup()
|
|
336
|
+
|
|
337
|
+
local fireCount = 0
|
|
338
|
+
local sub = context.tracker:ObserveAssetPurchased("swordKey"):Subscribe(function()
|
|
339
|
+
fireCount += 1
|
|
340
|
+
end)
|
|
341
|
+
|
|
342
|
+
context.tracker:HandlePurchaseEvent(KEY_TO_ID.swordKey, true)
|
|
343
|
+
|
|
344
|
+
expect(PromiseTestUtils.awaitValue(function()
|
|
345
|
+
return fireCount > 0
|
|
346
|
+
end, 5)).toEqual(true)
|
|
347
|
+
sub:Destroy()
|
|
348
|
+
context.destroy()
|
|
349
|
+
end)
|
|
350
|
+
|
|
351
|
+
it("should not fire when a different id is purchased", function()
|
|
352
|
+
local context = setup()
|
|
353
|
+
|
|
354
|
+
local fireCount = 0
|
|
355
|
+
local sub = context.tracker:ObserveAssetPurchased("swordKey"):Subscribe(function()
|
|
356
|
+
fireCount += 1
|
|
357
|
+
end)
|
|
358
|
+
|
|
359
|
+
context.tracker:HandlePurchaseEvent(KEY_TO_ID.shieldKey, true)
|
|
360
|
+
task.wait()
|
|
361
|
+
sub:Destroy()
|
|
362
|
+
|
|
363
|
+
expect(fireCount).toEqual(0)
|
|
364
|
+
context.destroy()
|
|
365
|
+
end)
|
|
366
|
+
end)
|
|
@@ -78,12 +78,17 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
78
78
|
local subscription = self:_addAssetTracker(GameConfigAssetTypes.SUBSCRIPTION)
|
|
79
79
|
local membership = self:_addAssetTracker(GameConfigAssetTypes.MEMBERSHIP)
|
|
80
80
|
|
|
81
|
+
-- Paid-access games can be owned but cannot be prompted in-experience, so the market
|
|
82
|
+
-- tracker is created non-promptable. There's no purchase signal to listen for either.
|
|
83
|
+
self:_addAssetTracker(GameConfigAssetTypes.GAME, false)
|
|
84
|
+
|
|
81
85
|
-- Some assets can be owned and thus, are reflected here
|
|
82
86
|
local passOwnership = self:_addOwnershipTracker(GameConfigAssetTypes.PASS)
|
|
83
87
|
local assetOwnership = self:_addOwnershipTracker(GameConfigAssetTypes.ASSET)
|
|
84
88
|
local bundleOwnership = self:_addOwnershipTracker(GameConfigAssetTypes.BUNDLE)
|
|
85
89
|
local subscriptionOwnership = self:_addOwnershipTracker(GameConfigAssetTypes.SUBSCRIPTION)
|
|
86
90
|
local membershipOwnership = self:_addOwnershipTracker(GameConfigAssetTypes.MEMBERSHIP)
|
|
91
|
+
local gameOwnership = self:_addOwnershipTracker(GameConfigAssetTypes.GAME)
|
|
87
92
|
|
|
88
93
|
-- Prompt
|
|
89
94
|
self._maid:GiveTask(asset.ShowPromptRequested:Connect(function(assetId)
|
|
@@ -143,6 +148,11 @@ function PlayerProductManagerBase.new(player: Player, serviceBag: ServiceBag.Ser
|
|
|
143
148
|
return Promise.resolved(self._player.MembershipType == membershipType)
|
|
144
149
|
end)
|
|
145
150
|
|
|
151
|
+
-- Paid-access game ownership is queried through PlayerOwnsAssetAsync
|
|
152
|
+
gameOwnership:SetQueryOwnershipCallback(function(assetId)
|
|
153
|
+
return MarketplaceUtils.promisePlayerOwnsAssetAsync(self._player, assetId)
|
|
154
|
+
end)
|
|
155
|
+
|
|
146
156
|
return self
|
|
147
157
|
end
|
|
148
158
|
|
|
@@ -292,7 +302,8 @@ end
|
|
|
292
302
|
|
|
293
303
|
function PlayerProductManagerBase._addAssetTracker(
|
|
294
304
|
self: PlayerProductManagerBase,
|
|
295
|
-
assetType: GameConfigAssetTypes.GameConfigAssetType
|
|
305
|
+
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
306
|
+
promptable: boolean?
|
|
296
307
|
): PlayerAssetMarketTracker.PlayerAssetMarketTracker
|
|
297
308
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
298
309
|
assert(not self._assetMarketTrackers[assetType], "Already have tracker")
|
|
@@ -305,7 +316,7 @@ function PlayerProductManagerBase._addAssetTracker(
|
|
|
305
316
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
306
317
|
|
|
307
318
|
return self._configPicker:ObserveToAssetIdBrio(assetType, idOrKey)
|
|
308
|
-
end))
|
|
319
|
+
end, promptable))
|
|
309
320
|
|
|
310
321
|
self._assetMarketTrackers[assetType] = assetMarketTracker
|
|
311
322
|
|