@quenty/saveslot 2.14.3 → 2.15.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 +6 -0
- package/package.json +21 -20
- package/src/Server/Binders/HasSaveSlots.Code.spec.lua +101 -116
- package/src/Server/Binders/HasSaveSlots.ExportImport.spec.lua +124 -134
- package/src/Server/Binders/HasSaveSlots.PreSelect.spec.lua +21 -28
- package/src/Server/Binders/HasSaveSlots.SharedStore.spec.lua +70 -92
- package/src/Server/Binders/HasSaveSlots.TransferableEphemeral.spec.lua +166 -179
- package/src/Server/Binders/HasSaveSlots.spec.lua +159 -722
- package/src/Server/Cmdr/SaveSlotCmdrService.spec.lua +3 -2
- package/src/Server/OfflineSaveSlots.spec.lua +9 -23
- package/src/Server/SaveSlotService.LateSettle.spec.lua +3 -5
- package/src/Server/SaveSlotService.LoadFlow.spec.lua +3 -5
- package/src/Server/SaveSlotService.Overflow.spec.lua +3 -5
- package/src/Server/SaveSlotService.Playtime.spec.lua +9 -22
- package/src/Server/SaveSlotService.spec.lua +43 -35
- package/src/Server/SaveSlotSharedDataStoreService.spec.lua +22 -45
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
]]
|
|
8
8
|
local require = require(script.Parent.loader).load(script)
|
|
9
9
|
|
|
10
|
+
local BindToCloseService = require("BindToCloseService")
|
|
10
11
|
local DataStoreMock = require("DataStoreMock")
|
|
11
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
12
12
|
local Jest = require("Jest")
|
|
13
13
|
local JestUtils = require("JestUtils")
|
|
14
14
|
local Maid = require("Maid")
|
|
@@ -36,6 +36,7 @@ local function setup()
|
|
|
36
36
|
|
|
37
37
|
local serviceBag = ServiceBag.new()
|
|
38
38
|
serviceBag:GetService(require("TeleportDataService"))
|
|
39
|
+
local bindToCloseService: BindToCloseService.BindToCloseService = serviceBag:GetService(BindToCloseService) :: any
|
|
39
40
|
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
40
41
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
41
42
|
local sharedService: SaveSlotSharedDataStoreService.SaveSlotSharedDataStoreService =
|
|
@@ -52,10 +53,8 @@ local function setup()
|
|
|
52
53
|
local hasSaveSlots = assert(binder:Bind(fakePlayer), "Failed to bind HasSaveSlots")
|
|
53
54
|
hasSaveSlots.MaxSlotCount.Value = 5
|
|
54
55
|
|
|
55
|
-
-- A PlayerMock never fires the real Players.PlayerRemoving, and the store the spec loaded is only
|
|
56
|
-
-- destroyed by a removal, so shut it down the way Roblox does or its auto-save loop outlives this spec.
|
|
57
56
|
maid:GiveTask(function()
|
|
58
|
-
|
|
57
|
+
PromiseTestUtils.awaitFulfilled(bindToCloseService:PromiseClose())
|
|
59
58
|
fakePlayer:Destroy()
|
|
60
59
|
serviceBag:Destroy()
|
|
61
60
|
end)
|
|
@@ -77,37 +76,10 @@ local function setup()
|
|
|
77
76
|
return controller
|
|
78
77
|
end
|
|
79
78
|
|
|
80
|
-
local function runWithContext(body)
|
|
81
|
-
local context = setup()
|
|
82
|
-
local ok, err = pcall(body, context)
|
|
83
|
-
context:Destroy()
|
|
84
|
-
if not ok then
|
|
85
|
-
error(err, 0)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
local function awaitValueOf(promise)
|
|
90
|
-
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
91
|
-
error("promise hung", 0)
|
|
92
|
-
end
|
|
93
|
-
local ok, value = promise:Yield()
|
|
94
|
-
if not ok then
|
|
95
|
-
error(`promise rejected: {tostring(value)}`, 0)
|
|
96
|
-
end
|
|
97
|
-
return value
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
local function awaitResolved(promise): boolean
|
|
101
|
-
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
102
|
-
error("promise hung", 0)
|
|
103
|
-
end
|
|
104
|
-
return (promise:Yield())
|
|
105
|
-
end
|
|
106
|
-
|
|
107
79
|
local function createSelectAndWrite(hasSaveSlots, slotIndex: number): string
|
|
108
|
-
local slotId =
|
|
109
|
-
|
|
110
|
-
local store =
|
|
80
|
+
local slotId = PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseCreateSlot(slotIndex))
|
|
81
|
+
PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseSelectSlot(slotId))
|
|
82
|
+
local store = PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseActiveSlotStore())
|
|
111
83
|
store:Store("Coins", 7)
|
|
112
84
|
store:GetSubStore("World_2"):Store("Eggs", 3)
|
|
113
85
|
return slotId
|
|
@@ -115,92 +87,98 @@ end
|
|
|
115
87
|
|
|
116
88
|
describe("HasSaveSlots shared-store save/import", function()
|
|
117
89
|
it("saves a non-main slot to the shared store and imports it into a fresh non-main slot", function()
|
|
118
|
-
|
|
119
|
-
|
|
90
|
+
local context = setup()
|
|
91
|
+
local hasSaveSlots = context.hasSaveSlots
|
|
92
|
+
|
|
93
|
+
local sourceSlotId = createSelectAndWrite(hasSaveSlots, 2)
|
|
94
|
+
PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseSaveSlotToSharedDataStore(sourceSlotId, "code-abc"))
|
|
120
95
|
|
|
121
|
-
|
|
122
|
-
|
|
96
|
+
local newSlotId = PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseImportSlotFromSharedDataStore("code-abc"))
|
|
97
|
+
expect(newSlotId).never.toEqual(sourceSlotId)
|
|
123
98
|
|
|
124
|
-
|
|
125
|
-
|
|
99
|
+
local reexport = PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseExportSlot(newSlotId))
|
|
100
|
+
expect(reexport.data.Coins).toEqual(7)
|
|
101
|
+
expect(reexport.data.World_2.Eggs).toEqual(3)
|
|
126
102
|
|
|
127
|
-
|
|
128
|
-
expect(reexport.data.Coins).toEqual(7)
|
|
129
|
-
expect(reexport.data.World_2.Eggs).toEqual(3)
|
|
130
|
-
end)
|
|
103
|
+
context:Destroy()
|
|
131
104
|
end)
|
|
132
105
|
|
|
133
106
|
it("rejects import from a missing key", function()
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
107
|
+
local context = setup()
|
|
108
|
+
PromiseTestUtils.awaitRejected(context.hasSaveSlots:PromiseImportSlotFromSharedDataStore("nope"))
|
|
109
|
+
|
|
110
|
+
context:Destroy()
|
|
137
111
|
end)
|
|
138
112
|
|
|
139
113
|
it("tags what it writes as a share code, keeping it out of the teleport arrival path", function()
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
114
|
+
local context = setup()
|
|
115
|
+
local hasSaveSlots = context.hasSaveSlots
|
|
116
|
+
local sourceSlotId = createSelectAndWrite(hasSaveSlots, 2)
|
|
117
|
+
PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseSaveSlotToSharedDataStore(sourceSlotId, "code-kind"))
|
|
118
|
+
|
|
119
|
+
local stored = PromiseTestUtils.awaitFulfilled(context.sharedService:PromiseRead("code-kind"))
|
|
120
|
+
expect(stored.kind).toEqual(SaveSlotExportUtils.Kind.CODE)
|
|
121
|
+
|
|
122
|
+
context:Destroy()
|
|
148
123
|
end)
|
|
149
124
|
|
|
150
125
|
it("refuses to import a transfer snapshot, whose key every client can read", function()
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
)
|
|
126
|
+
local context = setup()
|
|
127
|
+
PromiseTestUtils.awaitFulfilled(
|
|
128
|
+
context.sharedService:PromiseWrite(
|
|
129
|
+
"transfer-key",
|
|
130
|
+
SaveSlotExportUtils.withKind({ data = { Coins = 5 } }, SaveSlotExportUtils.Kind.TRANSFER)
|
|
157
131
|
)
|
|
132
|
+
)
|
|
158
133
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
end)
|
|
134
|
+
PromiseTestUtils.awaitRejected(context.hasSaveSlots:PromiseImportSlotFromSharedDataStore("transfer-key"))
|
|
135
|
+
|
|
136
|
+
context:Destroy()
|
|
163
137
|
end)
|
|
164
138
|
|
|
165
139
|
it("still imports an entry written before kinds existed", function()
|
|
166
|
-
|
|
167
|
-
|
|
140
|
+
local context = setup()
|
|
141
|
+
PromiseTestUtils.awaitFulfilled(context.sharedService:PromiseWrite("legacy-code", { data = { Coins = 5 } }))
|
|
142
|
+
|
|
143
|
+
local newSlotId =
|
|
144
|
+
PromiseTestUtils.awaitFulfilled(context.hasSaveSlots:PromiseImportSlotFromSharedDataStore("legacy-code"))
|
|
145
|
+
local reexport = PromiseTestUtils.awaitFulfilled(context.hasSaveSlots:PromiseExportSlot(newSlotId))
|
|
146
|
+
expect(reexport.data.Coins).toEqual(5)
|
|
168
147
|
|
|
169
|
-
|
|
170
|
-
local reexport = awaitValueOf(context.hasSaveSlots:PromiseExportSlot(newSlotId))
|
|
171
|
-
expect(reexport.data.Coins).toEqual(5)
|
|
172
|
-
end)
|
|
148
|
+
context:Destroy()
|
|
173
149
|
end)
|
|
174
150
|
|
|
175
151
|
it("propagates the main-slot guard through a shared-store save", function()
|
|
176
|
-
|
|
177
|
-
|
|
152
|
+
local context = setup()
|
|
153
|
+
local hasSaveSlots = context.hasSaveSlots
|
|
178
154
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
155
|
+
local mainSlotId =
|
|
156
|
+
PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseCreateSlot(SaveSlotConstants.DEFAULT_SLOT_INDEX))
|
|
157
|
+
PromiseTestUtils.awaitRejected(hasSaveSlots:PromiseSaveSlotToSharedDataStore(mainSlotId, "k"))
|
|
158
|
+
|
|
159
|
+
context:Destroy()
|
|
182
160
|
end)
|
|
183
161
|
|
|
184
162
|
it("rejects a save when the shared store write fails", function()
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
163
|
+
local context = setup()
|
|
164
|
+
local hasSaveSlots = context.hasSaveSlots
|
|
165
|
+
local sourceSlotId = createSelectAndWrite(hasSaveSlots, 2)
|
|
188
166
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
end)
|
|
167
|
+
context.sharedMock:FailNextRequests(1)
|
|
168
|
+
PromiseTestUtils.awaitRejected(hasSaveSlots:PromiseSaveSlotToSharedDataStore(sourceSlotId, "code-fail"))
|
|
169
|
+
|
|
170
|
+
context:Destroy()
|
|
194
171
|
end)
|
|
195
172
|
|
|
196
173
|
it("rejects an import when the shared store read fails", function()
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
174
|
+
local context = setup()
|
|
175
|
+
local hasSaveSlots = context.hasSaveSlots
|
|
176
|
+
local sourceSlotId = createSelectAndWrite(hasSaveSlots, 2)
|
|
177
|
+
PromiseTestUtils.awaitFulfilled(hasSaveSlots:PromiseSaveSlotToSharedDataStore(sourceSlotId, "code-read"))
|
|
178
|
+
|
|
179
|
+
context.sharedMock:FailNextRequests(1)
|
|
180
|
+
PromiseTestUtils.awaitRejected(hasSaveSlots:PromiseImportSlotFromSharedDataStore("code-read"))
|
|
181
|
+
|
|
182
|
+
context:Destroy()
|
|
205
183
|
end)
|
|
206
184
|
end)
|