@quenty/saveslot 2.14.2 → 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 +10 -0
- package/package.json +28 -27
- 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
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
]]
|
|
13
13
|
local require = require(script.Parent.loader).load(script)
|
|
14
14
|
|
|
15
|
+
local BindToCloseService = require("BindToCloseService")
|
|
15
16
|
local CmdrReplyUtils = require("CmdrReplyUtils")
|
|
16
17
|
local DataStoreMock = require("DataStoreMock")
|
|
17
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
18
18
|
local Jest = require("Jest")
|
|
19
19
|
local JestUtils = require("JestUtils")
|
|
20
20
|
local Maid = require("Maid")
|
|
@@ -38,6 +38,7 @@ local SLOW_REPLY_SECONDS = 0.05
|
|
|
38
38
|
local function setup()
|
|
39
39
|
local maid = Maid.new()
|
|
40
40
|
local serviceBag = maid:Add(ServiceBag.new())
|
|
41
|
+
local bindToCloseService: BindToCloseService.BindToCloseService = serviceBag:GetService(BindToCloseService) :: any
|
|
41
42
|
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
42
43
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
43
44
|
local saveSlotService: SaveSlotService.SaveSlotService = serviceBag:GetService(SaveSlotService) :: any
|
|
@@ -117,7 +118,7 @@ local function setup()
|
|
|
117
118
|
return mock:GetRaw(tostring(userId or ABSENT_USER_ID))
|
|
118
119
|
end,
|
|
119
120
|
Destroy = function(_self)
|
|
120
|
-
|
|
121
|
+
PromiseTestUtils.awaitFulfilled(bindToCloseService:PromiseClose())
|
|
121
122
|
maid:DoCleaning()
|
|
122
123
|
end,
|
|
123
124
|
}
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
]]
|
|
9
9
|
local require = require(script.Parent.loader).load(script)
|
|
10
10
|
|
|
11
|
+
local BindToCloseService = require("BindToCloseService")
|
|
11
12
|
local DataStoreMock = require("DataStoreMock")
|
|
12
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
13
13
|
local Jest = require("Jest")
|
|
14
14
|
local JestUtils = require("JestUtils")
|
|
15
15
|
local Maid = require("Maid")
|
|
@@ -27,6 +27,7 @@ local ABSENT_USER_ID = 90210
|
|
|
27
27
|
local function setup()
|
|
28
28
|
local maid = Maid.new()
|
|
29
29
|
local serviceBag = maid:Add(ServiceBag.new())
|
|
30
|
+
local bindToCloseService: BindToCloseService.BindToCloseService = serviceBag:GetService(BindToCloseService) :: any
|
|
30
31
|
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
31
32
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
32
33
|
local saveSlotService: SaveSlotService.SaveSlotService = serviceBag:GetService(SaveSlotService) :: any
|
|
@@ -37,37 +38,22 @@ local function setup()
|
|
|
37
38
|
saveSlotService:SetMaxSlotCount(5)
|
|
38
39
|
serviceBag:Start()
|
|
39
40
|
|
|
40
|
-
local function await(promise, label: string): any
|
|
41
|
-
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
42
|
-
expect(`{label} hung`).toEqual(`{label} settled`)
|
|
43
|
-
return nil
|
|
44
|
-
end
|
|
45
|
-
local ok, value = promise:Yield()
|
|
46
|
-
if not ok then
|
|
47
|
-
expect(`{label} rejected: {tostring(value)}`).toEqual(`{label} fulfilled`)
|
|
48
|
-
return nil
|
|
49
|
-
end
|
|
50
|
-
return value
|
|
51
|
-
end
|
|
52
|
-
|
|
53
41
|
local controller = {
|
|
54
42
|
serviceBag = serviceBag,
|
|
55
43
|
saveSlotService = saveSlotService,
|
|
56
44
|
mock = mock,
|
|
57
|
-
await = await,
|
|
58
45
|
-- Opens the offline slots and waits for the roster to load, which is what every caller wants;
|
|
59
46
|
-- the sync read accessors see an empty roster until it has.
|
|
60
47
|
openSlots = function(userId: number?): any
|
|
61
|
-
local offline =
|
|
48
|
+
local offline =
|
|
49
|
+
PromiseTestUtils.awaitFulfilled(saveSlotService:PromiseOfflineSaveSlots(userId or ABSENT_USER_ID))
|
|
62
50
|
if offline then
|
|
63
|
-
|
|
51
|
+
PromiseTestUtils.awaitFulfilled(offline:PromiseSlotsLoaded())
|
|
64
52
|
end
|
|
65
53
|
return offline
|
|
66
54
|
end,
|
|
67
55
|
Destroy = function(_self)
|
|
68
|
-
|
|
69
|
-
-- released by its handle, so shut down the way Roblox does before tearing the bag down.
|
|
70
|
-
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
56
|
+
PromiseTestUtils.awaitFulfilled(bindToCloseService:PromiseClose())
|
|
71
57
|
maid:DoCleaning()
|
|
72
58
|
end,
|
|
73
59
|
}
|
|
@@ -113,7 +99,7 @@ describe("SaveSlotService.PromiseOfflineSaveSlots", function()
|
|
|
113
99
|
local controller = setup()
|
|
114
100
|
|
|
115
101
|
local offline = controller.openSlots()
|
|
116
|
-
local slotId =
|
|
102
|
+
local slotId = PromiseTestUtils.awaitFulfilled(offline:GetSlotsDataStore():PromiseCreateSlot(1))
|
|
117
103
|
expect(type(slotId)).toEqual("string")
|
|
118
104
|
|
|
119
105
|
-- Releasing the session is what flushes it, so read the store only after the destroy settles.
|
|
@@ -153,8 +139,8 @@ describe("SaveSlotService.PromiseOfflineSaveSlots", function()
|
|
|
153
139
|
local offline = controller.openSlots()
|
|
154
140
|
local slots = offline:GetSlotsDataStore()
|
|
155
141
|
|
|
156
|
-
local slotId =
|
|
157
|
-
|
|
142
|
+
local slotId = PromiseTestUtils.awaitFulfilled(slots:PromiseCreateSlot(1))
|
|
143
|
+
PromiseTestUtils.awaitFulfilled(slots:PromiseSelectSlot(slotId))
|
|
158
144
|
|
|
159
145
|
local metadata = slots:GetSlotMetadata(slotId)
|
|
160
146
|
expect(metadata.PlayCount).toBeNil()
|
|
@@ -13,8 +13,8 @@ local require = require(script.Parent.loader).load(script)
|
|
|
13
13
|
|
|
14
14
|
local Workspace = game:GetService("Workspace")
|
|
15
15
|
|
|
16
|
+
local BindToCloseService = require("BindToCloseService")
|
|
16
17
|
local DataStoreMock = require("DataStoreMock")
|
|
17
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
18
18
|
local Jest = require("Jest")
|
|
19
19
|
local JestUtils = require("JestUtils")
|
|
20
20
|
local Maid = require("Maid")
|
|
@@ -45,6 +45,7 @@ local function setup()
|
|
|
45
45
|
mock:SetYieldTime(READ_YIELD_SECONDS)
|
|
46
46
|
|
|
47
47
|
local serviceBag = maid:Add(ServiceBag.new())
|
|
48
|
+
local bindToCloseService: BindToCloseService.BindToCloseService = serviceBag:GetService(BindToCloseService) :: any
|
|
48
49
|
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
49
50
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
50
51
|
local hasSaveSlotsBinder = serviceBag:GetService(require("HasSaveSlots"))
|
|
@@ -57,10 +58,7 @@ local function setup()
|
|
|
57
58
|
fakePlayer.Parent = Workspace
|
|
58
59
|
|
|
59
60
|
local function Destroy(_self)
|
|
60
|
-
|
|
61
|
-
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
62
|
-
-- this spec and fires inside a later package's window.
|
|
63
|
-
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
61
|
+
PromiseTestUtils.awaitFulfilled(bindToCloseService:PromiseClose())
|
|
64
62
|
serviceBag:Destroy()
|
|
65
63
|
maid:DoCleaning()
|
|
66
64
|
-- Any straggler continuation blows up here, inside the test that owns it, rather
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
]]
|
|
10
10
|
local require = require(script.Parent.loader).load(script)
|
|
11
11
|
|
|
12
|
+
local BindToCloseService = require("BindToCloseService")
|
|
12
13
|
local DataStore = require("DataStore")
|
|
13
14
|
local DataStoreMock = require("DataStoreMock")
|
|
14
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
15
15
|
local Jest = require("Jest")
|
|
16
16
|
local JestUtils = require("JestUtils")
|
|
17
17
|
local Maid = require("Maid")
|
|
@@ -31,6 +31,7 @@ local function setup(mock: DataStoreMock.DataStoreMock?)
|
|
|
31
31
|
local dataStoreMock = mock or DataStoreMock.new()
|
|
32
32
|
|
|
33
33
|
local serviceBag = maid:Add(ServiceBag.new())
|
|
34
|
+
local bindToCloseService: BindToCloseService.BindToCloseService = serviceBag:GetService(BindToCloseService) :: any
|
|
34
35
|
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
35
36
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
36
37
|
serviceBag:Init()
|
|
@@ -46,10 +47,7 @@ local function setup(mock: DataStoreMock.DataStoreMock?)
|
|
|
46
47
|
local systemStore = dataStore:GetSubStore(SaveSlotConstants.SYSTEM_STORE_KEY)
|
|
47
48
|
|
|
48
49
|
local function Destroy(_self)
|
|
49
|
-
|
|
50
|
-
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
51
|
-
-- this spec and fires inside a later package's window.
|
|
52
|
-
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
50
|
+
PromiseTestUtils.awaitFulfilled(bindToCloseService:PromiseClose())
|
|
53
51
|
maid:DoCleaning()
|
|
54
52
|
end
|
|
55
53
|
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
]]
|
|
12
12
|
local require = require(script.Parent.loader).load(script)
|
|
13
13
|
|
|
14
|
+
local BindToCloseService = require("BindToCloseService")
|
|
14
15
|
local DataStore = require("DataStore")
|
|
15
16
|
local DataStoreMock = require("DataStoreMock")
|
|
16
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
17
17
|
local Jest = require("Jest")
|
|
18
18
|
local JestUtils = require("JestUtils")
|
|
19
19
|
local Maid = require("Maid")
|
|
@@ -35,6 +35,7 @@ local function setup()
|
|
|
35
35
|
local mock = DataStoreMock.new()
|
|
36
36
|
|
|
37
37
|
local serviceBag = maid:Add(ServiceBag.new())
|
|
38
|
+
local bindToCloseService: BindToCloseService.BindToCloseService = serviceBag:GetService(BindToCloseService) :: any
|
|
38
39
|
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
39
40
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
40
41
|
serviceBag:Init()
|
|
@@ -55,10 +56,7 @@ local function setup()
|
|
|
55
56
|
-- cleanly, rather than throwing during cleanup and leaking a retry into a later spec (these all
|
|
56
57
|
-- share one test place).
|
|
57
58
|
mock:SetMaxValueLength(nil)
|
|
58
|
-
|
|
59
|
-
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
60
|
-
-- this spec and fires inside a later package's window.
|
|
61
|
-
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
59
|
+
PromiseTestUtils.awaitFulfilled(bindToCloseService:PromiseClose())
|
|
62
60
|
maid:DoCleaning()
|
|
63
61
|
end
|
|
64
62
|
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
]]
|
|
9
9
|
local require = require(script.Parent.loader).load(script)
|
|
10
10
|
|
|
11
|
+
local BindToCloseService = require("BindToCloseService")
|
|
11
12
|
local DataStoreMock = require("DataStoreMock")
|
|
12
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
13
13
|
local HasSaveSlotsDataStore = require("HasSaveSlotsDataStore")
|
|
14
14
|
local Jest = require("Jest")
|
|
15
15
|
local JestUtils = require("JestUtils")
|
|
@@ -32,6 +32,7 @@ local SESSION_SECONDS = 120
|
|
|
32
32
|
local function setup()
|
|
33
33
|
local maid = Maid.new()
|
|
34
34
|
local serviceBag = maid:Add(ServiceBag.new())
|
|
35
|
+
local bindToCloseService: BindToCloseService.BindToCloseService = serviceBag:GetService(BindToCloseService) :: any
|
|
35
36
|
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
36
37
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
37
38
|
local sharedDataStoreService: SaveSlotSharedDataStoreService.SaveSlotSharedDataStoreService =
|
|
@@ -42,20 +43,7 @@ local function setup()
|
|
|
42
43
|
playerDataStoreService:SetRobloxDataStore(mock)
|
|
43
44
|
serviceBag:Start()
|
|
44
45
|
|
|
45
|
-
local
|
|
46
|
-
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
47
|
-
expect(`{label} hung`).toEqual(`{label} settled`)
|
|
48
|
-
return nil
|
|
49
|
-
end
|
|
50
|
-
local ok, value = promise:Yield()
|
|
51
|
-
if not ok then
|
|
52
|
-
expect(`{label} rejected: {tostring(value)}`).toEqual(`{label} fulfilled`)
|
|
53
|
-
return nil
|
|
54
|
-
end
|
|
55
|
-
return value
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
local dataStore = await(playerDataStoreService:PromiseDataStore(USER_ID), "data store")
|
|
46
|
+
local dataStore = PromiseTestUtils.awaitFulfilled(playerDataStoreService:PromiseDataStore(USER_ID))
|
|
59
47
|
|
|
60
48
|
local slotsDataStore = maid:Add(HasSaveSlotsDataStore.new(Promise.resolved(dataStore), {
|
|
61
49
|
ActiveSlotId = maid:Add(ValueObject.new(nil)),
|
|
@@ -65,18 +53,17 @@ local function setup()
|
|
|
65
53
|
SharedDataStoreService = sharedDataStoreService,
|
|
66
54
|
UserId = USER_ID,
|
|
67
55
|
}))
|
|
68
|
-
|
|
56
|
+
PromiseTestUtils.awaitFulfilled(slotsDataStore:PromiseSlotsLoaded())
|
|
69
57
|
|
|
70
58
|
local controller = {
|
|
71
|
-
await = await,
|
|
72
59
|
mock = mock,
|
|
73
60
|
dataStore = dataStore,
|
|
74
61
|
slotsDataStore = slotsDataStore,
|
|
75
62
|
-- Selects a fresh slot and backdates the session so the next flush accrues real time without
|
|
76
63
|
-- the spec waiting it out.
|
|
77
64
|
beginBackdatedSession = function(): string
|
|
78
|
-
local slotId =
|
|
79
|
-
|
|
65
|
+
local slotId = PromiseTestUtils.awaitFulfilled(slotsDataStore:PromiseCreateSlot(1))
|
|
66
|
+
PromiseTestUtils.awaitFulfilled(slotsDataStore:PromiseSelectSlot(slotId))
|
|
80
67
|
slotsDataStore._playSessionStart = assert(slotsDataStore._playSessionStart, "No _playSessionStart")
|
|
81
68
|
- SESSION_SECONDS
|
|
82
69
|
slotsDataStore._playSessionLastFlush = assert(
|
|
@@ -92,7 +79,7 @@ local function setup()
|
|
|
92
79
|
return metadata and metadata[slotId]
|
|
93
80
|
end,
|
|
94
81
|
Destroy = function(_self)
|
|
95
|
-
|
|
82
|
+
PromiseTestUtils.awaitFulfilled(bindToCloseService:PromiseClose())
|
|
96
83
|
maid:DoCleaning()
|
|
97
84
|
end,
|
|
98
85
|
}
|
|
@@ -107,7 +94,7 @@ describe("save slot playtime", function()
|
|
|
107
94
|
local controller = setup()
|
|
108
95
|
local slotId = controller.beginBackdatedSession()
|
|
109
96
|
|
|
110
|
-
|
|
97
|
+
PromiseTestUtils.awaitFulfilled(controller.dataStore:Save())
|
|
111
98
|
|
|
112
99
|
local stored = controller.storedMetadata(slotId)
|
|
113
100
|
expect(stored).never.toBeNil()
|
|
@@ -122,7 +109,7 @@ describe("save slot playtime", function()
|
|
|
122
109
|
local controller = setup()
|
|
123
110
|
local slotId = controller.beginBackdatedSession()
|
|
124
111
|
|
|
125
|
-
|
|
112
|
+
PromiseTestUtils.awaitFulfilled(controller.dataStore:Save())
|
|
126
113
|
|
|
127
114
|
local metadata = assert(controller.slotsDataStore:GetSlotMetadata(slotId), "No slot metadata")
|
|
128
115
|
expect(metadata.TimePlayed).toEqual(controller.storedMetadata(slotId).TimePlayed)
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
]]
|
|
10
10
|
local require = require(script.Parent.loader).load(script)
|
|
11
11
|
|
|
12
|
+
local BindToCloseService = require("BindToCloseService")
|
|
12
13
|
local DataStoreMock = require("DataStoreMock")
|
|
13
|
-
local DataStoreTestUtils = require("DataStoreTestUtils")
|
|
14
14
|
local Jest = require("Jest")
|
|
15
15
|
local JestUtils = require("JestUtils")
|
|
16
16
|
local Maid = require("Maid")
|
|
@@ -31,6 +31,7 @@ local it = Jest.Globals.it
|
|
|
31
31
|
local function setup()
|
|
32
32
|
local maid = Maid.new()
|
|
33
33
|
local serviceBag = maid:Add(ServiceBag.new())
|
|
34
|
+
local bindToCloseService: BindToCloseService.BindToCloseService = serviceBag:GetService(BindToCloseService) :: any
|
|
34
35
|
local playerDataStoreService: PlayerDataStoreService.PlayerDataStoreService =
|
|
35
36
|
serviceBag:GetService(PlayerDataStoreService) :: any
|
|
36
37
|
local saveSlotService: SaveSlotService.SaveSlotService = serviceBag:GetService(SaveSlotService) :: any
|
|
@@ -46,17 +47,8 @@ local function setup()
|
|
|
46
47
|
fakePlayer = function(userId: number?): Player
|
|
47
48
|
return maid:Add(PlayerMock.new(if userId ~= nil then { UserId = userId } else nil))
|
|
48
49
|
end,
|
|
49
|
-
awaitBool = function(promise: any): boolean
|
|
50
|
-
expect(PromiseTestUtils.awaitSettled(promise, 5)).toEqual(true)
|
|
51
|
-
local ok, value = promise:Yield()
|
|
52
|
-
expect(ok).toEqual(true)
|
|
53
|
-
return value
|
|
54
|
-
end,
|
|
55
50
|
Destroy = function(_self)
|
|
56
|
-
|
|
57
|
-
-- real Players.PlayerRemoving, so shut down the way Roblox does or its auto-save loop outlives
|
|
58
|
-
-- this spec and fires inside a later package's window.
|
|
59
|
-
DataStoreTestUtils.awaitServiceShutdown(playerDataStoreService)
|
|
51
|
+
PromiseTestUtils.awaitFulfilled(bindToCloseService:PromiseClose())
|
|
60
52
|
maid:DoCleaning()
|
|
61
53
|
end,
|
|
62
54
|
}
|
|
@@ -120,7 +112,7 @@ describe("SaveSlotService:RegisterPreSelectCallback", function()
|
|
|
120
112
|
return nil
|
|
121
113
|
end)
|
|
122
114
|
|
|
123
|
-
|
|
115
|
+
PromiseTestUtils.awaitFulfilled(controller.saveSlotService:PromisePreSelect(player, "slot-1"))
|
|
124
116
|
expect(ran).toEqual(1)
|
|
125
117
|
|
|
126
118
|
controller:Destroy()
|
|
@@ -136,12 +128,12 @@ describe("SaveSlotService:RegisterPreSelectCallback", function()
|
|
|
136
128
|
return nil
|
|
137
129
|
end)
|
|
138
130
|
|
|
139
|
-
|
|
131
|
+
PromiseTestUtils.awaitFulfilled(controller.saveSlotService:PromisePreSelect(player, "slot-1"))
|
|
140
132
|
expect(ran).toEqual(1)
|
|
141
133
|
|
|
142
134
|
remove()
|
|
143
135
|
|
|
144
|
-
|
|
136
|
+
PromiseTestUtils.awaitFulfilled(controller.saveSlotService:PromisePreSelect(player, "slot-1"))
|
|
145
137
|
expect(ran).toEqual(1)
|
|
146
138
|
|
|
147
139
|
controller:Destroy()
|
|
@@ -152,9 +144,11 @@ describe("SaveSlotService:PromisePreSelect", function()
|
|
|
152
144
|
it("allows the selection when nothing is registered", function()
|
|
153
145
|
local controller = setup()
|
|
154
146
|
|
|
155
|
-
expect(
|
|
156
|
-
|
|
157
|
-
|
|
147
|
+
expect(
|
|
148
|
+
PromiseTestUtils.awaitFulfilled(
|
|
149
|
+
controller.saveSlotService:PromisePreSelect(controller.fakePlayer(), "slot-1")
|
|
150
|
+
)
|
|
151
|
+
).toEqual(true)
|
|
158
152
|
|
|
159
153
|
controller:Destroy()
|
|
160
154
|
end)
|
|
@@ -169,7 +163,7 @@ describe("SaveSlotService:PromisePreSelect", function()
|
|
|
169
163
|
return nil
|
|
170
164
|
end)
|
|
171
165
|
|
|
172
|
-
|
|
166
|
+
PromiseTestUtils.awaitFulfilled(controller.saveSlotService:PromisePreSelect(player, "slot-2", "slot-1"))
|
|
173
167
|
|
|
174
168
|
expect(#calls).toEqual(1)
|
|
175
169
|
expect(calls[1].player).toEqual(player)
|
|
@@ -186,9 +180,11 @@ describe("SaveSlotService:PromisePreSelect", function()
|
|
|
186
180
|
return false
|
|
187
181
|
end)
|
|
188
182
|
|
|
189
|
-
expect(
|
|
190
|
-
|
|
191
|
-
|
|
183
|
+
expect(
|
|
184
|
+
PromiseTestUtils.awaitFulfilled(
|
|
185
|
+
controller.saveSlotService:PromisePreSelect(controller.fakePlayer(), "slot-1")
|
|
186
|
+
)
|
|
187
|
+
).toEqual(false)
|
|
192
188
|
|
|
193
189
|
controller:Destroy()
|
|
194
190
|
end)
|
|
@@ -200,9 +196,11 @@ describe("SaveSlotService:PromisePreSelect", function()
|
|
|
200
196
|
return Promise.resolved(false)
|
|
201
197
|
end)
|
|
202
198
|
|
|
203
|
-
expect(
|
|
204
|
-
|
|
205
|
-
|
|
199
|
+
expect(
|
|
200
|
+
PromiseTestUtils.awaitFulfilled(
|
|
201
|
+
controller.saveSlotService:PromisePreSelect(controller.fakePlayer(), "slot-1")
|
|
202
|
+
)
|
|
203
|
+
).toEqual(false)
|
|
206
204
|
|
|
207
205
|
controller:Destroy()
|
|
208
206
|
end)
|
|
@@ -225,7 +223,7 @@ describe("SaveSlotService:PromisePreSelect", function()
|
|
|
225
223
|
expect(PromiseTestUtils.awaitSettled(verdict, 0.5)).toEqual(false)
|
|
226
224
|
|
|
227
225
|
second:Resolve()
|
|
228
|
-
expect(
|
|
226
|
+
expect(PromiseTestUtils.awaitFulfilled(verdict)).toEqual(true)
|
|
229
227
|
|
|
230
228
|
controller:Destroy()
|
|
231
229
|
end)
|
|
@@ -242,7 +240,7 @@ describe("SaveSlotService:PromisePreSelect", function()
|
|
|
242
240
|
return nil
|
|
243
241
|
end)
|
|
244
242
|
|
|
245
|
-
|
|
243
|
+
PromiseTestUtils.awaitFulfilled(controller.saveSlotService:PromisePreSelect(controller.fakePlayer(), "slot-1"))
|
|
246
244
|
|
|
247
245
|
expect(ranAfter).toEqual(1)
|
|
248
246
|
|
|
@@ -261,9 +259,11 @@ describe("SaveSlotService:PromisePreSelect", function()
|
|
|
261
259
|
return nil
|
|
262
260
|
end)
|
|
263
261
|
|
|
264
|
-
expect(
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
expect(
|
|
263
|
+
PromiseTestUtils.awaitFulfilled(
|
|
264
|
+
controller.saveSlotService:PromisePreSelect(controller.fakePlayer(), "slot-1")
|
|
265
|
+
)
|
|
266
|
+
).toEqual(true)
|
|
267
267
|
expect(ranAfter).toEqual(1)
|
|
268
268
|
|
|
269
269
|
controller:Destroy()
|
|
@@ -276,9 +276,11 @@ describe("SaveSlotService:PromisePreSelect", function()
|
|
|
276
276
|
return Promise.rejected("work blew up")
|
|
277
277
|
end)
|
|
278
278
|
|
|
279
|
-
expect(
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
expect(
|
|
280
|
+
PromiseTestUtils.awaitFulfilled(
|
|
281
|
+
controller.saveSlotService:PromisePreSelect(controller.fakePlayer(), "slot-1")
|
|
282
|
+
)
|
|
283
|
+
).toEqual(true)
|
|
282
284
|
|
|
283
285
|
controller:Destroy()
|
|
284
286
|
end)
|
|
@@ -444,7 +446,9 @@ describe("SaveSlotService internal teleport", function()
|
|
|
444
446
|
[SaveSlotConstants.TELEPORT_DATA_SLOT_KEY] = "slot-1",
|
|
445
447
|
})
|
|
446
448
|
|
|
447
|
-
expect(
|
|
449
|
+
expect(PromiseTestUtils.awaitFulfilled(controller.saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(
|
|
450
|
+
true
|
|
451
|
+
)
|
|
448
452
|
|
|
449
453
|
controller:Destroy()
|
|
450
454
|
end)
|
|
@@ -459,7 +463,9 @@ describe("SaveSlotService internal teleport", function()
|
|
|
459
463
|
})
|
|
460
464
|
controller.teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(arrived, nil) -- no client band; seals
|
|
461
465
|
|
|
462
|
-
expect(
|
|
466
|
+
expect(PromiseTestUtils.awaitFulfilled(controller.saveSlotService:PromiseIsInternalTeleport(arrived))).toEqual(
|
|
467
|
+
true
|
|
468
|
+
)
|
|
463
469
|
|
|
464
470
|
controller:Destroy()
|
|
465
471
|
end)
|
|
@@ -471,7 +477,9 @@ describe("SaveSlotService internal teleport", function()
|
|
|
471
477
|
local fresh = controller.fakePlayer(111)
|
|
472
478
|
controller.teleportDataService:SetNonTrustedArrivedTeleportDataForTesting(fresh, nil) -- fresh-join sentinel; seals
|
|
473
479
|
|
|
474
|
-
expect(
|
|
480
|
+
expect(PromiseTestUtils.awaitFulfilled(controller.saveSlotService:PromiseIsInternalTeleport(fresh))).toEqual(
|
|
481
|
+
false
|
|
482
|
+
)
|
|
475
483
|
|
|
476
484
|
controller:Destroy()
|
|
477
485
|
end)
|
|
@@ -45,62 +45,39 @@ local function setup()
|
|
|
45
45
|
return controller
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
local function runWithContext(body)
|
|
49
|
-
local context = setup()
|
|
50
|
-
local ok, err = pcall(body, context)
|
|
51
|
-
context:Destroy()
|
|
52
|
-
if not ok then
|
|
53
|
-
error(err, 0)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
local function awaitValueOf(promise)
|
|
58
|
-
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
59
|
-
error("promise hung", 0)
|
|
60
|
-
end
|
|
61
|
-
local ok, value = promise:Yield()
|
|
62
|
-
if not ok then
|
|
63
|
-
error(`promise rejected: {tostring(value)}`, 0)
|
|
64
|
-
end
|
|
65
|
-
return value
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
local function awaitResolved(promise): boolean
|
|
69
|
-
if not PromiseTestUtils.awaitSettled(promise, 10) then
|
|
70
|
-
error("promise hung", 0)
|
|
71
|
-
end
|
|
72
|
-
return (promise:Yield())
|
|
73
|
-
end
|
|
74
|
-
|
|
75
48
|
describe("SaveSlotSharedDataStoreService", function()
|
|
76
49
|
it("round-trips a value by key", function()
|
|
77
|
-
|
|
78
|
-
|
|
50
|
+
local context = setup()
|
|
51
|
+
PromiseTestUtils.awaitFulfilled(context.service:PromiseWrite("code-1", { Coins = 9, World = { Eggs = 2 } }))
|
|
52
|
+
|
|
53
|
+
local value = PromiseTestUtils.awaitFulfilled(context.service:PromiseRead("code-1"))
|
|
54
|
+
expect(value.Coins).toEqual(9)
|
|
55
|
+
expect(value.World.Eggs).toEqual(2)
|
|
79
56
|
|
|
80
|
-
|
|
81
|
-
expect(value.Coins).toEqual(9)
|
|
82
|
-
expect(value.World.Eggs).toEqual(2)
|
|
83
|
-
end)
|
|
57
|
+
context:Destroy()
|
|
84
58
|
end)
|
|
85
59
|
|
|
86
60
|
it("reads nil for an absent key", function()
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
61
|
+
local context = setup()
|
|
62
|
+
expect(PromiseTestUtils.awaitFulfilled(context.service:PromiseRead("missing"))).toBeNil()
|
|
63
|
+
|
|
64
|
+
context:Destroy()
|
|
90
65
|
end)
|
|
91
66
|
|
|
92
67
|
it("removes a value", function()
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
68
|
+
local context = setup()
|
|
69
|
+
PromiseTestUtils.awaitFulfilled(context.service:PromiseWrite("code-2", { A = 1 }))
|
|
70
|
+
PromiseTestUtils.awaitFulfilled(context.service:PromiseRemove("code-2"))
|
|
71
|
+
expect(PromiseTestUtils.awaitFulfilled(context.service:PromiseRead("code-2"))).toBeNil()
|
|
72
|
+
|
|
73
|
+
context:Destroy()
|
|
98
74
|
end)
|
|
99
75
|
|
|
100
76
|
it("surfaces datastore failures as rejections", function()
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
77
|
+
local context = setup()
|
|
78
|
+
context.mock:FailNextRequests(1)
|
|
79
|
+
PromiseTestUtils.awaitRejected(context.service:PromiseWrite("code-3", { A = 1 }))
|
|
80
|
+
|
|
81
|
+
context:Destroy()
|
|
105
82
|
end)
|
|
106
83
|
end)
|