@quenty/saveslot 1.4.1 → 1.5.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 +4 -0
- package/deploy.nevermore.json +10 -0
- package/package.json +17 -15
- package/src/Server/Binders/HasSaveSlots.spec.lua +282 -0
- package/src/Server/SaveSlotLoadFlow.spec.lua +152 -0
- package/src/Server/SaveSlotService.spec.lua +127 -0
- package/src/jest.config.lua +5 -0
- package/test/default.project.json +3 -0
- package/test/scripts/Server/ServerMain.server.lua +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
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
|
+
# [1.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.4.1...@quenty/saveslot@1.5.0) (2026-07-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/saveslot
|
|
9
|
+
|
|
6
10
|
## [1.4.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/saveslot@1.4.0...@quenty/saveslot@1.4.1) (2026-07-15)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @quenty/saveslot
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/saveslot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "PlayerDataStoreService wrapper for save slots",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,28 +28,30 @@
|
|
|
28
28
|
"Quenty"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@quenty/adorneedata": "7.
|
|
31
|
+
"@quenty/adorneedata": "7.35.0",
|
|
32
32
|
"@quenty/baseobject": "10.13.0",
|
|
33
|
-
"@quenty/binder": "14.
|
|
34
|
-
"@quenty/brio": "14.
|
|
35
|
-
"@quenty/cmdrservice": "13.
|
|
36
|
-
"@quenty/datastore": "13.
|
|
37
|
-
"@quenty/instanceutils": "13.
|
|
33
|
+
"@quenty/binder": "14.38.0",
|
|
34
|
+
"@quenty/brio": "14.31.0",
|
|
35
|
+
"@quenty/cmdrservice": "13.48.0",
|
|
36
|
+
"@quenty/datastore": "13.41.0",
|
|
37
|
+
"@quenty/instanceutils": "13.31.0",
|
|
38
38
|
"@quenty/loader": "10.11.0",
|
|
39
39
|
"@quenty/maid": "3.9.0",
|
|
40
|
-
"@quenty/
|
|
41
|
-
"@quenty/
|
|
42
|
-
"@quenty/
|
|
43
|
-
"@quenty/
|
|
44
|
-
"@quenty/
|
|
40
|
+
"@quenty/nevermore-test-runner": "1.4.0",
|
|
41
|
+
"@quenty/playerbinder": "14.38.0",
|
|
42
|
+
"@quenty/promise": "10.19.0",
|
|
43
|
+
"@quenty/propertyvalue": "7.31.0",
|
|
44
|
+
"@quenty/remoting": "12.33.0",
|
|
45
|
+
"@quenty/rx": "13.29.0",
|
|
45
46
|
"@quenty/servicebag": "11.18.1",
|
|
46
47
|
"@quenty/signal": "7.13.1",
|
|
47
48
|
"@quenty/table": "3.9.2",
|
|
48
|
-
"@quenty/tie": "10.
|
|
49
|
-
"@quenty/valueobject": "13.
|
|
49
|
+
"@quenty/tie": "10.42.0",
|
|
50
|
+
"@quenty/valueobject": "13.32.0",
|
|
51
|
+
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
50
52
|
},
|
|
51
53
|
"publishConfig": {
|
|
52
54
|
"access": "public"
|
|
53
55
|
},
|
|
54
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "cbbb89635bfdcbf32f26a40422ac736292917cca"
|
|
55
57
|
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
--!nonstrict
|
|
2
|
+
--[[
|
|
3
|
+
Integration coverage for the real HasSaveSlots binder, driven against a mocked datastore. Because
|
|
4
|
+
the load path only reads the player's UserId, a plain Folder stands in for a Player with
|
|
5
|
+
PlayerDataStoreManager._toPlayerUserIdOrError intercepted to map it to a fixed userId; everything
|
|
6
|
+
else exercises the real code.
|
|
7
|
+
|
|
8
|
+
@class HasSaveSlots.spec.lua
|
|
9
|
+
]]
|
|
10
|
+
local require = require(script.Parent.loader).load(script)
|
|
11
|
+
|
|
12
|
+
local DataStoreMock = require("DataStoreMock")
|
|
13
|
+
local Jest = require("Jest")
|
|
14
|
+
local PlayerDataStoreManager = require("PlayerDataStoreManager")
|
|
15
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
16
|
+
local ServiceBag = require("ServiceBag")
|
|
17
|
+
|
|
18
|
+
local Workspace = game:GetService("Workspace")
|
|
19
|
+
|
|
20
|
+
local describe = Jest.Globals.describe
|
|
21
|
+
local expect = Jest.Globals.expect
|
|
22
|
+
local it = Jest.Globals.it
|
|
23
|
+
local afterEach = Jest.Globals.afterEach
|
|
24
|
+
|
|
25
|
+
local FAKE_USER_ID = 424242
|
|
26
|
+
|
|
27
|
+
-- Real implementation, captured at load so the patch can fall through for anything but the fake player.
|
|
28
|
+
local originalToUserId = PlayerDataStoreManager._toPlayerUserIdOrError
|
|
29
|
+
|
|
30
|
+
-- We monkeypatch _toPlayerUserIdOrError directly rather than jest.spyOn: after jest.restoreAllMocks(),
|
|
31
|
+
-- re-spying the same method on the next test is a no-op (spyOn hands back the stale, already-restored
|
|
32
|
+
-- spy without re-patching the object), so only the first test's spy took effect and every later Bind
|
|
33
|
+
-- threw "Bad playerOrUserId". A direct swap re-patches deterministically each setup.
|
|
34
|
+
afterEach(function()
|
|
35
|
+
PlayerDataStoreManager._toPlayerUserIdOrError = originalToUserId
|
|
36
|
+
end)
|
|
37
|
+
|
|
38
|
+
local function setup(mock)
|
|
39
|
+
mock = mock or DataStoreMock.new()
|
|
40
|
+
|
|
41
|
+
local serviceBag = ServiceBag.new()
|
|
42
|
+
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
43
|
+
local binder = serviceBag:GetService(require("HasSaveSlots"))
|
|
44
|
+
serviceBag:Init()
|
|
45
|
+
playerDataStoreService:SetRobloxDataStore(mock)
|
|
46
|
+
serviceBag:Start()
|
|
47
|
+
|
|
48
|
+
local fakePlayer = Instance.new("Folder")
|
|
49
|
+
fakePlayer.Name = "FakePlayer"
|
|
50
|
+
fakePlayer.Parent = Workspace
|
|
51
|
+
|
|
52
|
+
-- Intercept only the UserId read so a Folder can stand in for a Player. Restored after each test.
|
|
53
|
+
PlayerDataStoreManager._toPlayerUserIdOrError = function(self, playerOrUserId)
|
|
54
|
+
if playerOrUserId == fakePlayer then
|
|
55
|
+
return FAKE_USER_ID
|
|
56
|
+
end
|
|
57
|
+
return originalToUserId(self, playerOrUserId)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
local hasSaveSlots = binder:Bind(fakePlayer)
|
|
61
|
+
if hasSaveSlots then
|
|
62
|
+
hasSaveSlots.MaxSlotCount.Value = 5
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
local function destroy()
|
|
66
|
+
fakePlayer:Destroy()
|
|
67
|
+
serviceBag:Destroy()
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
serviceBag = serviceBag,
|
|
72
|
+
binder = binder,
|
|
73
|
+
fakePlayer = fakePlayer,
|
|
74
|
+
hasSaveSlots = hasSaveSlots,
|
|
75
|
+
mock = mock,
|
|
76
|
+
destroy = destroy,
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe("HasSaveSlots against a fake player (healthy datastore)", function()
|
|
81
|
+
it("should construct via the binder and load slots for a fresh player", function()
|
|
82
|
+
local context = setup()
|
|
83
|
+
expect(context.hasSaveSlots).never.toBeNil()
|
|
84
|
+
|
|
85
|
+
local promise = context.hasSaveSlots:PromiseSlotsLoaded()
|
|
86
|
+
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
87
|
+
expect("slots load hung").toEqual("slots load settled")
|
|
88
|
+
context.destroy()
|
|
89
|
+
return
|
|
90
|
+
end
|
|
91
|
+
expect((promise:Yield())).toEqual(true)
|
|
92
|
+
|
|
93
|
+
context.destroy()
|
|
94
|
+
end)
|
|
95
|
+
|
|
96
|
+
it("should create a slot and find it", function()
|
|
97
|
+
local context = setup()
|
|
98
|
+
|
|
99
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
100
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
101
|
+
expect("create hung").toEqual("create settled")
|
|
102
|
+
context.destroy()
|
|
103
|
+
return
|
|
104
|
+
end
|
|
105
|
+
local ok, slotId = createPromise:Yield()
|
|
106
|
+
expect(ok).toEqual(true)
|
|
107
|
+
expect(type(slotId)).toEqual("string")
|
|
108
|
+
|
|
109
|
+
local hasPromise = context.hasSaveSlots:PromiseHasSlot(slotId)
|
|
110
|
+
if not PromiseTestUtils.awaitSettled(hasPromise, 10) then
|
|
111
|
+
expect("hasSlot hung").toEqual("hasSlot settled")
|
|
112
|
+
context.destroy()
|
|
113
|
+
return
|
|
114
|
+
end
|
|
115
|
+
expect((hasPromise:Wait())).toEqual(true)
|
|
116
|
+
|
|
117
|
+
local indexPromise = context.hasSaveSlots:PromiseSlotIdFromIndex(1)
|
|
118
|
+
if not PromiseTestUtils.awaitSettled(indexPromise, 10) then
|
|
119
|
+
expect("slotIdFromIndex hung").toEqual("slotIdFromIndex settled")
|
|
120
|
+
context.destroy()
|
|
121
|
+
return
|
|
122
|
+
end
|
|
123
|
+
expect((indexPromise:Wait())).toEqual(slotId)
|
|
124
|
+
|
|
125
|
+
context.destroy()
|
|
126
|
+
end)
|
|
127
|
+
|
|
128
|
+
it("should select a slot and report it active", function()
|
|
129
|
+
local context = setup()
|
|
130
|
+
|
|
131
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
132
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
133
|
+
expect("create hung").toEqual("create settled")
|
|
134
|
+
context.destroy()
|
|
135
|
+
return
|
|
136
|
+
end
|
|
137
|
+
local _, slotId = createPromise:Yield()
|
|
138
|
+
|
|
139
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
140
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
141
|
+
expect("select hung").toEqual("select settled")
|
|
142
|
+
context.destroy()
|
|
143
|
+
return
|
|
144
|
+
end
|
|
145
|
+
expect((selectPromise:Yield())).toEqual(true)
|
|
146
|
+
|
|
147
|
+
expect(context.hasSaveSlots.ActiveSlotId.Value).toEqual(slotId)
|
|
148
|
+
|
|
149
|
+
local lastPromise = context.hasSaveSlots:PromiseLastActiveSlotId()
|
|
150
|
+
if not PromiseTestUtils.awaitSettled(lastPromise, 10) then
|
|
151
|
+
expect("lastActive hung").toEqual("lastActive settled")
|
|
152
|
+
context.destroy()
|
|
153
|
+
return
|
|
154
|
+
end
|
|
155
|
+
expect((lastPromise:Wait())).toEqual(slotId)
|
|
156
|
+
|
|
157
|
+
context.destroy()
|
|
158
|
+
end)
|
|
159
|
+
|
|
160
|
+
it("should observe the active slot store after selection", function()
|
|
161
|
+
local context = setup()
|
|
162
|
+
|
|
163
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
164
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
165
|
+
expect("create hung").toEqual("create settled")
|
|
166
|
+
context.destroy()
|
|
167
|
+
return
|
|
168
|
+
end
|
|
169
|
+
local _, slotId = createPromise:Yield()
|
|
170
|
+
|
|
171
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
172
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
173
|
+
expect("select hung").toEqual("select settled")
|
|
174
|
+
context.destroy()
|
|
175
|
+
return
|
|
176
|
+
end
|
|
177
|
+
selectPromise:Yield()
|
|
178
|
+
|
|
179
|
+
local capturedStore
|
|
180
|
+
local subscription = context.hasSaveSlots:ObserveActiveSlotStoreBrio():Subscribe(function(brio)
|
|
181
|
+
if not brio:IsDead() then
|
|
182
|
+
capturedStore = brio:GetValue()
|
|
183
|
+
end
|
|
184
|
+
end)
|
|
185
|
+
|
|
186
|
+
local emitted = PromiseTestUtils.awaitValue(function()
|
|
187
|
+
return capturedStore ~= nil
|
|
188
|
+
end, 10)
|
|
189
|
+
subscription:Destroy()
|
|
190
|
+
|
|
191
|
+
expect(emitted).toEqual(true)
|
|
192
|
+
|
|
193
|
+
context.destroy()
|
|
194
|
+
end)
|
|
195
|
+
|
|
196
|
+
it("should reject creating a slot beyond the max slot count", function()
|
|
197
|
+
local context = setup()
|
|
198
|
+
context.hasSaveSlots.MaxSlotCount.Value = 1
|
|
199
|
+
|
|
200
|
+
local promise = context.hasSaveSlots:PromiseCreateSlot(2)
|
|
201
|
+
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
202
|
+
expect("create hung").toEqual("create settled")
|
|
203
|
+
context.destroy()
|
|
204
|
+
return
|
|
205
|
+
end
|
|
206
|
+
expect((promise:Yield())).toEqual(false)
|
|
207
|
+
|
|
208
|
+
context.destroy()
|
|
209
|
+
end)
|
|
210
|
+
|
|
211
|
+
it("should reject creating a duplicate slot index", function()
|
|
212
|
+
local context = setup()
|
|
213
|
+
|
|
214
|
+
local firstPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
215
|
+
if not PromiseTestUtils.awaitSettled(firstPromise, 10) then
|
|
216
|
+
expect("first create hung").toEqual("first create settled")
|
|
217
|
+
context.destroy()
|
|
218
|
+
return
|
|
219
|
+
end
|
|
220
|
+
firstPromise:Yield()
|
|
221
|
+
|
|
222
|
+
local secondPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
223
|
+
if not PromiseTestUtils.awaitSettled(secondPromise, 10) then
|
|
224
|
+
expect("second create hung").toEqual("second create settled")
|
|
225
|
+
context.destroy()
|
|
226
|
+
return
|
|
227
|
+
end
|
|
228
|
+
expect((secondPromise:Yield())).toEqual(false)
|
|
229
|
+
|
|
230
|
+
context.destroy()
|
|
231
|
+
end)
|
|
232
|
+
|
|
233
|
+
it("should reject deleting the active slot", function()
|
|
234
|
+
local context = setup()
|
|
235
|
+
|
|
236
|
+
local createPromise = context.hasSaveSlots:PromiseCreateSlot(1)
|
|
237
|
+
if not PromiseTestUtils.awaitSettled(createPromise, 10) then
|
|
238
|
+
expect("create hung").toEqual("create settled")
|
|
239
|
+
context.destroy()
|
|
240
|
+
return
|
|
241
|
+
end
|
|
242
|
+
local _, slotId = createPromise:Yield()
|
|
243
|
+
|
|
244
|
+
local selectPromise = context.hasSaveSlots:PromiseSelectSlot(slotId)
|
|
245
|
+
if not PromiseTestUtils.awaitSettled(selectPromise, 10) then
|
|
246
|
+
expect("select hung").toEqual("select settled")
|
|
247
|
+
context.destroy()
|
|
248
|
+
return
|
|
249
|
+
end
|
|
250
|
+
selectPromise:Yield()
|
|
251
|
+
|
|
252
|
+
local deletePromise = context.hasSaveSlots:PromiseDeleteSlot(slotId)
|
|
253
|
+
if not PromiseTestUtils.awaitSettled(deletePromise, 10) then
|
|
254
|
+
expect("delete hung").toEqual("delete settled")
|
|
255
|
+
context.destroy()
|
|
256
|
+
return
|
|
257
|
+
end
|
|
258
|
+
expect((deletePromise:Yield())).toEqual(false)
|
|
259
|
+
|
|
260
|
+
context.destroy()
|
|
261
|
+
end)
|
|
262
|
+
end)
|
|
263
|
+
|
|
264
|
+
describe("HasSaveSlots against a fake player (datastore down)", function()
|
|
265
|
+
it("PromiseSlotsLoaded rejects fast instead of hanging when datastores are down", function()
|
|
266
|
+
local mock = DataStoreMock.new()
|
|
267
|
+
mock:FailAllRequests()
|
|
268
|
+
|
|
269
|
+
local context = setup(mock)
|
|
270
|
+
expect(context.hasSaveSlots).never.toBeNil()
|
|
271
|
+
|
|
272
|
+
local promise = context.hasSaveSlots:PromiseSlotsLoaded()
|
|
273
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
274
|
+
|
|
275
|
+
if not promise:IsPending() then
|
|
276
|
+
local ok = promise:Yield()
|
|
277
|
+
expect(ok).toEqual(false)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
context.destroy()
|
|
281
|
+
end)
|
|
282
|
+
end)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
--!nonstrict
|
|
2
|
+
--[[
|
|
3
|
+
Characterizes the save-slot load flow -- the substore reads HasSaveSlots performs -- driven
|
|
4
|
+
through a mock-injected PlayerDataStoreService. A headless cloud test server has no real Players
|
|
5
|
+
to bind the PlayerBinder to, so these reproduce the load against the same datastore substore
|
|
6
|
+
layout (SaveSlotConstants) with a numeric userId.
|
|
7
|
+
|
|
8
|
+
@class SaveSlotLoadFlow.spec.lua
|
|
9
|
+
]]
|
|
10
|
+
local require = require(script.Parent.loader).load(script)
|
|
11
|
+
|
|
12
|
+
local DataStoreMock = require("DataStoreMock")
|
|
13
|
+
local Jest = require("Jest")
|
|
14
|
+
local Maid = require("Maid")
|
|
15
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
16
|
+
local SaveSlotConstants = require("SaveSlotConstants")
|
|
17
|
+
local ServiceBag = require("ServiceBag")
|
|
18
|
+
|
|
19
|
+
local describe = Jest.Globals.describe
|
|
20
|
+
local expect = Jest.Globals.expect
|
|
21
|
+
local it = Jest.Globals.it
|
|
22
|
+
|
|
23
|
+
-- Builds a ServiceBag with a mock-injected PlayerDataStoreService, owned by a Maid so destroy() tears
|
|
24
|
+
-- down the service (and the session-locked stores its manager owns), mirroring how the save-slot
|
|
25
|
+
-- system resolves a player's datastore. Read controller.mock to seed or fail the datastore.
|
|
26
|
+
local function setup(mock)
|
|
27
|
+
local maid = Maid.new()
|
|
28
|
+
mock = mock or DataStoreMock.new()
|
|
29
|
+
|
|
30
|
+
local serviceBag = maid:Add(ServiceBag.new())
|
|
31
|
+
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
32
|
+
serviceBag:Init()
|
|
33
|
+
playerDataStoreService:SetRobloxDataStore(mock)
|
|
34
|
+
serviceBag:Start()
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
playerDataStoreService = playerDataStoreService,
|
|
38
|
+
mock = mock,
|
|
39
|
+
destroy = function()
|
|
40
|
+
maid:DoCleaning()
|
|
41
|
+
end,
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
-- Resolves the session-locked datastore for a userId (bounded); returns nil on failure to settle.
|
|
46
|
+
local function resolveDataStore(playerDataStoreService, userId)
|
|
47
|
+
local promise = playerDataStoreService:PromiseDataStore(userId)
|
|
48
|
+
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
49
|
+
return nil
|
|
50
|
+
end
|
|
51
|
+
local ok, dataStore = promise:Yield()
|
|
52
|
+
if not ok then
|
|
53
|
+
return nil
|
|
54
|
+
end
|
|
55
|
+
return dataStore
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe("save slot load flow (healthy datastore)", function()
|
|
59
|
+
it("loads empty slot metadata and no active slot for a fresh user", function()
|
|
60
|
+
local controller = setup()
|
|
61
|
+
|
|
62
|
+
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
63
|
+
expect(dataStore).never.toBeNil()
|
|
64
|
+
|
|
65
|
+
local systemStore = dataStore:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
66
|
+
local metadataStore = systemStore:GetSubStore(SaveSlotConstants.METADATA_STORE_KEY)
|
|
67
|
+
|
|
68
|
+
local metaPromise = metadataStore:LoadAll({})
|
|
69
|
+
if not PromiseTestUtils.awaitSettled(metaPromise, 10) then
|
|
70
|
+
expect("metadata load hung").toEqual("metadata load settled")
|
|
71
|
+
controller:destroy()
|
|
72
|
+
return
|
|
73
|
+
end
|
|
74
|
+
local metaOk, metadata = metaPromise:Yield()
|
|
75
|
+
expect(metaOk).toEqual(true)
|
|
76
|
+
expect(metadata).toEqual({})
|
|
77
|
+
|
|
78
|
+
local activePromise = systemStore:Load("activeSlotId")
|
|
79
|
+
if not PromiseTestUtils.awaitSettled(activePromise, 10) then
|
|
80
|
+
expect("activeSlotId load hung").toEqual("activeSlotId load settled")
|
|
81
|
+
controller:destroy()
|
|
82
|
+
return
|
|
83
|
+
end
|
|
84
|
+
local activeOk, activeSlotId = activePromise:Yield()
|
|
85
|
+
expect(activeOk).toEqual(true)
|
|
86
|
+
expect(activeSlotId).toEqual(nil)
|
|
87
|
+
|
|
88
|
+
controller:destroy()
|
|
89
|
+
end)
|
|
90
|
+
|
|
91
|
+
it("round-trips a slot's data through the slot substore", function()
|
|
92
|
+
local controller = setup()
|
|
93
|
+
|
|
94
|
+
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
95
|
+
expect(dataStore).never.toBeNil()
|
|
96
|
+
|
|
97
|
+
-- Slot stores live at SaveSlots.slots.<slotId>, matching HasSaveSlots._getSlotStore.
|
|
98
|
+
local slotStore = dataStore
|
|
99
|
+
:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
100
|
+
:GetSubStore(SaveSlotConstants.SLOT_STORE_KEY)
|
|
101
|
+
:GetSubStore("slot-abc")
|
|
102
|
+
|
|
103
|
+
slotStore:Store("coins", 25)
|
|
104
|
+
|
|
105
|
+
local savePromise = dataStore:Save()
|
|
106
|
+
if not PromiseTestUtils.awaitSettled(savePromise, 10) then
|
|
107
|
+
expect("save hung").toEqual("save settled")
|
|
108
|
+
controller:destroy()
|
|
109
|
+
return
|
|
110
|
+
end
|
|
111
|
+
expect((savePromise:Yield())).toEqual(true)
|
|
112
|
+
|
|
113
|
+
local loadPromise = slotStore:Load("coins")
|
|
114
|
+
if not PromiseTestUtils.awaitSettled(loadPromise, 10) then
|
|
115
|
+
expect("load hung").toEqual("load settled")
|
|
116
|
+
controller:destroy()
|
|
117
|
+
return
|
|
118
|
+
end
|
|
119
|
+
local ok, value = loadPromise:Yield()
|
|
120
|
+
expect(ok).toEqual(true)
|
|
121
|
+
expect(value).toEqual(25)
|
|
122
|
+
|
|
123
|
+
controller:destroy()
|
|
124
|
+
end)
|
|
125
|
+
end)
|
|
126
|
+
|
|
127
|
+
describe("save slot load flow (datastore down)", function()
|
|
128
|
+
it("surfaces an error fast instead of hanging when datastores are down", function()
|
|
129
|
+
local mock = DataStoreMock.new()
|
|
130
|
+
mock:FailAllRequests()
|
|
131
|
+
|
|
132
|
+
local controller = setup(mock)
|
|
133
|
+
|
|
134
|
+
-- The manager hands back a datastore without loading, so this resolves.
|
|
135
|
+
local dataStore = resolveDataStore(controller.playerDataStoreService, 1)
|
|
136
|
+
expect(dataStore).never.toBeNil()
|
|
137
|
+
|
|
138
|
+
-- The first actual read (loading slot metadata) triggers the session-locked load.
|
|
139
|
+
local metadataStore =
|
|
140
|
+
dataStore:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY):GetSubStore(SaveSlotConstants.METADATA_STORE_KEY)
|
|
141
|
+
|
|
142
|
+
local promise = metadataStore:LoadAll({})
|
|
143
|
+
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
144
|
+
|
|
145
|
+
if not promise:IsPending() then
|
|
146
|
+
local ok = promise:Yield()
|
|
147
|
+
expect(ok).toEqual(false)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
controller:destroy()
|
|
151
|
+
end)
|
|
152
|
+
end)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
--!nonstrict
|
|
2
|
+
--[[
|
|
3
|
+
Coverage for SaveSlotService's ServiceBag-driven configuration surface — the parts reachable
|
|
4
|
+
without a bound Player (a headless cloud test server has none). The player-driven slot
|
|
5
|
+
selection flow (which needs a real Player on the HasSaveSlots binder) is characterized
|
|
6
|
+
separately at the datastore layer in SaveSlotLoadFlow.spec.
|
|
7
|
+
|
|
8
|
+
@class SaveSlotService.spec.lua
|
|
9
|
+
]]
|
|
10
|
+
local require = require(script.Parent.loader).load(script)
|
|
11
|
+
|
|
12
|
+
local DataStoreMock = require("DataStoreMock")
|
|
13
|
+
local Jest = require("Jest")
|
|
14
|
+
local ServiceBag = require("ServiceBag")
|
|
15
|
+
|
|
16
|
+
local describe = Jest.Globals.describe
|
|
17
|
+
local expect = Jest.Globals.expect
|
|
18
|
+
local it = Jest.Globals.it
|
|
19
|
+
|
|
20
|
+
-- Builds a ServiceBag with SaveSlotService, and a mock-injected PlayerDataStoreService so nothing
|
|
21
|
+
-- touches a real datastore. Returns the bag + service; the caller decides when to Start.
|
|
22
|
+
local function newServiceBag()
|
|
23
|
+
local serviceBag = ServiceBag.new()
|
|
24
|
+
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
|
|
25
|
+
local saveSlotService = serviceBag:GetService(require("SaveSlotService"))
|
|
26
|
+
serviceBag:Init()
|
|
27
|
+
playerDataStoreService:SetRobloxDataStore(DataStoreMock.new())
|
|
28
|
+
return serviceBag, saveSlotService
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe("SaveSlotService initialization", function()
|
|
32
|
+
it("should initialize and start without a bound player", function()
|
|
33
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
34
|
+
|
|
35
|
+
expect(function()
|
|
36
|
+
serviceBag:Start()
|
|
37
|
+
end).never.toThrow()
|
|
38
|
+
expect(saveSlotService).never.toBeNil()
|
|
39
|
+
|
|
40
|
+
serviceBag:Destroy()
|
|
41
|
+
end)
|
|
42
|
+
end)
|
|
43
|
+
|
|
44
|
+
describe("SaveSlotService.GetExplicitSelectionRequired", function()
|
|
45
|
+
it("should default to false", function()
|
|
46
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
47
|
+
|
|
48
|
+
expect(saveSlotService:GetExplicitSelectionRequired()).toEqual(false)
|
|
49
|
+
|
|
50
|
+
serviceBag:Destroy()
|
|
51
|
+
end)
|
|
52
|
+
|
|
53
|
+
it("should be true after RequireExplicitSelection", function()
|
|
54
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
55
|
+
|
|
56
|
+
saveSlotService:RequireExplicitSelection()
|
|
57
|
+
expect(saveSlotService:GetExplicitSelectionRequired()).toEqual(true)
|
|
58
|
+
|
|
59
|
+
serviceBag:Destroy()
|
|
60
|
+
end)
|
|
61
|
+
end)
|
|
62
|
+
|
|
63
|
+
describe("SaveSlotService configuration guards", function()
|
|
64
|
+
it("should reject RequireExplicitSelection after Start", function()
|
|
65
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
66
|
+
serviceBag:Start()
|
|
67
|
+
|
|
68
|
+
expect(function()
|
|
69
|
+
saveSlotService:RequireExplicitSelection()
|
|
70
|
+
end).toThrow("RequireExplicitSelection must be called before Start")
|
|
71
|
+
|
|
72
|
+
serviceBag:Destroy()
|
|
73
|
+
end)
|
|
74
|
+
|
|
75
|
+
it("should reject SetMaxSlotCount after Start", function()
|
|
76
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
77
|
+
serviceBag:Start()
|
|
78
|
+
|
|
79
|
+
expect(function()
|
|
80
|
+
saveSlotService:SetMaxSlotCount(3)
|
|
81
|
+
end).toThrow("SetMaxSlotCount must be called before Start")
|
|
82
|
+
|
|
83
|
+
serviceBag:Destroy()
|
|
84
|
+
end)
|
|
85
|
+
|
|
86
|
+
it("should accept a valid SetMaxSlotCount before Start", function()
|
|
87
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
88
|
+
|
|
89
|
+
expect(function()
|
|
90
|
+
saveSlotService:SetMaxSlotCount(3)
|
|
91
|
+
end).never.toThrow()
|
|
92
|
+
|
|
93
|
+
serviceBag:Destroy()
|
|
94
|
+
end)
|
|
95
|
+
|
|
96
|
+
it("should reject a SetMaxSlotCount below 1", function()
|
|
97
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
98
|
+
|
|
99
|
+
expect(function()
|
|
100
|
+
saveSlotService:SetMaxSlotCount(0)
|
|
101
|
+
end).toThrow("Bad maxSlotCount")
|
|
102
|
+
|
|
103
|
+
serviceBag:Destroy()
|
|
104
|
+
end)
|
|
105
|
+
|
|
106
|
+
it("should reject a non-function summary provider", function()
|
|
107
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
108
|
+
|
|
109
|
+
expect(function()
|
|
110
|
+
saveSlotService:SetDefaultSummaryProvider("not a function")
|
|
111
|
+
end).toThrow("Bad provider")
|
|
112
|
+
|
|
113
|
+
serviceBag:Destroy()
|
|
114
|
+
end)
|
|
115
|
+
|
|
116
|
+
it("should accept a function summary provider", function()
|
|
117
|
+
local serviceBag, saveSlotService = newServiceBag()
|
|
118
|
+
|
|
119
|
+
expect(function()
|
|
120
|
+
saveSlotService:SetDefaultSummaryProvider(function()
|
|
121
|
+
return nil
|
|
122
|
+
end)
|
|
123
|
+
end).never.toThrow()
|
|
124
|
+
|
|
125
|
+
serviceBag:Destroy()
|
|
126
|
+
end)
|
|
127
|
+
end)
|
|
@@ -5,8 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
local ServerScriptService = game:GetService("ServerScriptService")
|
|
7
7
|
|
|
8
|
-
local
|
|
9
|
-
local
|
|
8
|
+
local root = ServerScriptService.saveslot
|
|
9
|
+
local loader = root:FindFirstChild("LoaderUtils", true).Parent
|
|
10
|
+
local require = require(loader).bootstrapGame(root)
|
|
11
|
+
|
|
12
|
+
local NevermoreTestRunnerUtils = require("NevermoreTestRunnerUtils")
|
|
13
|
+
|
|
14
|
+
if NevermoreTestRunnerUtils.runTestsIfNeededAsync(root) then
|
|
15
|
+
return
|
|
16
|
+
end
|
|
10
17
|
|
|
11
18
|
local serviceBag = require("ServiceBag").new()
|
|
12
19
|
serviceBag:GetService(require("SaveSlotService"))
|