add gs
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"language": {
|
||||
"mode": "nonstrict"
|
||||
},
|
||||
"lint": {
|
||||
"ImplicitReturn": "fatal"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local Rodux = require(CorePackages.Rodux)
|
||||
|
||||
local ReceivedUserCountryCode = require(CorePackages.AppTempCommon.LuaApp.Actions.ReceivedUserCountryCode)
|
||||
|
||||
local DEFAULT_STATE = ""
|
||||
return Rodux.createReducer(DEFAULT_STATE, {
|
||||
[ReceivedUserCountryCode.name] = function(state, action)
|
||||
return action.countryCode
|
||||
end,
|
||||
})
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
return function()
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local ReceivedUserCountryCode = require(CorePackages.AppTempCommon.LuaApp.Actions.ReceivedUserCountryCode)
|
||||
local CountryCodeReducer = require(CorePackages.AppTempCommon.LuaApp.Reducers.CountryCode)
|
||||
|
||||
describe("CountryCode", function()
|
||||
it("should be and empty string by default", function()
|
||||
local state = CountryCodeReducer(nil, {})
|
||||
|
||||
expect(state).to.equal("")
|
||||
end)
|
||||
|
||||
it("should not be modified by other actions", function()
|
||||
local oldState = CountryCodeReducer(nil, {})
|
||||
local newState = CountryCodeReducer(oldState, { type = "not a real action" })
|
||||
|
||||
expect(newState).to.equal(oldState)
|
||||
end)
|
||||
|
||||
it("should be changed using ReceivedUserCountryCode", function()
|
||||
local state = CountryCodeReducer(nil, {})
|
||||
|
||||
state = CountryCodeReducer(state, ReceivedUserCountryCode("US"))
|
||||
expect(state).to.equal("US")
|
||||
|
||||
state = CountryCodeReducer(state, ReceivedUserCountryCode(""))
|
||||
expect(state).to.equal("")
|
||||
end)
|
||||
end)
|
||||
end
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local UpdateFetchingStatus = require(CorePackages.AppTempCommon.LuaApp.Actions.UpdateFetchingStatus)
|
||||
local Cryo = require(CorePackages.Cryo)
|
||||
|
||||
return function(state, action)
|
||||
state = state or {}
|
||||
|
||||
if action.type == UpdateFetchingStatus.name then
|
||||
local key = action.key
|
||||
local status = action.status
|
||||
local value
|
||||
if status ~= nil then
|
||||
value = status
|
||||
else
|
||||
value = Cryo.None
|
||||
end
|
||||
|
||||
state = Cryo.Dictionary.join(
|
||||
state,
|
||||
{
|
||||
[key] = value,
|
||||
}
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
return state
|
||||
end
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
return function()
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local UpdateFetchingStatus = require(CorePackages.AppTempCommon.LuaApp.Actions.UpdateFetchingStatus)
|
||||
local FetchingStatusReducer = require(CorePackages.AppTempCommon.LuaApp.Reducers.FetchingStatus)
|
||||
local RetrievalStatus = require(CorePackages.AppTempCommon.LuaApp.Enum.RetrievalStatus)
|
||||
local TableUtilities = require(CorePackages.AppTempCommon.LuaApp.TableUtilities)
|
||||
|
||||
local KEY_1 = "key_1"
|
||||
local KEY_2 = "key_2"
|
||||
|
||||
describe("FetchingStatus", function()
|
||||
it("should be empty by default", function()
|
||||
local state = FetchingStatusReducer(nil, {})
|
||||
|
||||
expect(TableUtilities.FieldCount(state)).to.equal(0)
|
||||
end)
|
||||
|
||||
it("should not be modified by other actions", function()
|
||||
local oldState = FetchingStatusReducer(nil, {})
|
||||
local newState = FetchingStatusReducer(oldState, { type = "not a real action" })
|
||||
|
||||
expect(newState).to.equal(oldState)
|
||||
end)
|
||||
|
||||
it("should be changed using UpdateFetchingStatus", function()
|
||||
local state = FetchingStatusReducer(nil, {})
|
||||
|
||||
state = FetchingStatusReducer(state, UpdateFetchingStatus(KEY_1, RetrievalStatus.Fetching))
|
||||
expect(state[KEY_1]).to.equal(RetrievalStatus.Fetching)
|
||||
|
||||
state = FetchingStatusReducer(state, UpdateFetchingStatus(KEY_1, RetrievalStatus.Failed))
|
||||
expect(state[KEY_1]).to.equal(RetrievalStatus.Failed)
|
||||
end)
|
||||
|
||||
it("should store different values for different keys", function()
|
||||
local state = FetchingStatusReducer(nil, {})
|
||||
|
||||
state = FetchingStatusReducer(state, UpdateFetchingStatus(KEY_1, RetrievalStatus.Failed))
|
||||
state = FetchingStatusReducer(state, UpdateFetchingStatus(KEY_2, RetrievalStatus.Done))
|
||||
|
||||
expect(state[KEY_1]).to.equal(RetrievalStatus.Failed)
|
||||
expect(state[KEY_2]).to.equal(RetrievalStatus.Done)
|
||||
end)
|
||||
|
||||
it("should clear values for nil keys", function()
|
||||
local state = { [KEY_1] = RetrievalStatus.Fetching }
|
||||
|
||||
state = FetchingStatusReducer(state, UpdateFetchingStatus(KEY_1, nil))
|
||||
expect(state[KEY_1]).to.equal(nil)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Immutable = require(CorePackages.AppTempCommon.Common.Immutable)
|
||||
local RetrievalStatus = require(CorePackages.AppTempCommon.LuaApp.Enum.RetrievalStatus)
|
||||
|
||||
local FetchUserFriendsStarted = require(CorePackages.AppTempCommon.LuaApp.Actions.FetchUserFriendsStarted)
|
||||
local FetchUserFriendsFailed = require(CorePackages.AppTempCommon.LuaApp.Actions.FetchUserFriendsFailed)
|
||||
local FetchUserFriendsCompleted = require(CorePackages.AppTempCommon.LuaApp.Actions.FetchUserFriendsCompleted)
|
||||
|
||||
local function setFieldPerUser(state, fieldName, userId, value)
|
||||
local field = state[fieldName] or {}
|
||||
return Immutable.JoinDictionaries(state, {
|
||||
[fieldName] = Immutable.JoinDictionaries(field, {
|
||||
[userId] = value
|
||||
})
|
||||
})
|
||||
end
|
||||
|
||||
local function setRetrievalStatus(state, userId, status)
|
||||
return setFieldPerUser(state, "retrievalStatus", userId, status)
|
||||
end
|
||||
|
||||
local function setRetrievalFailureResponse(state, userId, response)
|
||||
return setFieldPerUser(state, "retrievalFailureResponse", userId, response)
|
||||
end
|
||||
|
||||
return function(state, action)
|
||||
state = state or {
|
||||
retrievalStatus = {},
|
||||
retrievalFailureResponse = {},
|
||||
}
|
||||
|
||||
if action.type == FetchUserFriendsStarted.name then
|
||||
state = setRetrievalStatus(state, action.userId, RetrievalStatus.Fetching)
|
||||
elseif action.type == FetchUserFriendsFailed.name then
|
||||
state = setRetrievalStatus(state, action.userId, RetrievalStatus.Failed)
|
||||
state = setRetrievalFailureResponse(state, action.userId, action.response)
|
||||
elseif action.type == FetchUserFriendsCompleted.name then
|
||||
state = setRetrievalStatus(state, action.userId, RetrievalStatus.Done)
|
||||
end
|
||||
|
||||
return state
|
||||
end
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Immutable = require(CorePackages.AppTempCommon.Common.Immutable)
|
||||
local ReceivedPlacesInfos = require(CorePackages.AppTempCommon.LuaApp.Actions.ReceivedPlacesInfos)
|
||||
|
||||
local LuaAppFlags = CorePackages.AppTempCommon.LuaApp.Flags
|
||||
local convertUniverseIdToString = require(LuaAppFlags.ConvertUniverseIdToString)
|
||||
|
||||
return function(state, action)
|
||||
state = state or {}
|
||||
|
||||
if action.type == ReceivedPlacesInfos.name then
|
||||
for _, placeInfo in pairs(action.placesInfos) do
|
||||
local universeId = convertUniverseIdToString(placeInfo.universeId)
|
||||
|
||||
state = Immutable.Set(state, universeId, placeInfo)
|
||||
end
|
||||
end
|
||||
|
||||
return state
|
||||
end
|
||||
@@ -0,0 +1,107 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Immutable = require(CorePackages.AppTempCommon.Common.Immutable)
|
||||
|
||||
local AddUser = require(CorePackages.AppTempCommon.LuaApp.Actions.AddUser)
|
||||
local AddUsers = require(CorePackages.AppTempCommon.LuaApp.Actions.AddUsers)
|
||||
local ReceivedUserPresence = require(CorePackages.AppTempCommon.LuaChat.Actions.ReceivedUserPresence)
|
||||
local RemoveUser = require(CorePackages.AppTempCommon.LuaApp.Actions.RemoveUser)
|
||||
local SetUserIsFriend = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserIsFriend)
|
||||
local SetUserMembershipType = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserMembershipType)
|
||||
local SetUserPresence = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserPresence)
|
||||
local SetUserThumbnail = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserThumbnail)
|
||||
local ReceivedDisplayName = require(CorePackages.AppTempCommon.LuaApp.Actions.ReceivedDisplayName)
|
||||
|
||||
return function(state, action)
|
||||
state = state or {}
|
||||
|
||||
if action.type == AddUser.name then
|
||||
local user = action.user
|
||||
state = Immutable.Set(state, user.id, user)
|
||||
elseif action.type == AddUsers.name then
|
||||
local addedUsers = action.users
|
||||
local usersUpdate = {}
|
||||
for userId, addedUser in pairs(addedUsers) do
|
||||
local existingUser = state[userId]
|
||||
if existingUser then
|
||||
usersUpdate[userId] = Immutable.JoinDictionaries(existingUser, addedUser)
|
||||
else
|
||||
usersUpdate[userId] = addedUser
|
||||
end
|
||||
end
|
||||
|
||||
state = Immutable.JoinDictionaries(state, usersUpdate)
|
||||
|
||||
elseif action.type == SetUserIsFriend.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
local newUser = Immutable.Set(user, "isFriend", action.isFriend)
|
||||
state = Immutable.Set(state, user.id, newUser)
|
||||
else
|
||||
warn("Setting isFriend on user", action.userId, "who doesn't exist yet")
|
||||
end
|
||||
elseif action.type == SetUserPresence.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
local newUser = Immutable.JoinDictionaries(user, {
|
||||
presence = action.presence,
|
||||
lastLocation = action.lastLocation,
|
||||
})
|
||||
state = Immutable.Set(state, user.id, newUser)
|
||||
else
|
||||
warn("Setting presence on user", action.userId, "who doesn't exist yet")
|
||||
end
|
||||
elseif action.type == ReceivedUserPresence.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
state = Immutable.JoinDictionaries(state, {
|
||||
[action.userId] = Immutable.JoinDictionaries(user, {
|
||||
presence = action.presence,
|
||||
lastLocation = action.lastLocation,
|
||||
placeId = action.placeId,
|
||||
rootPlaceId = action.rootPlaceId,
|
||||
gameInstanceId = action.gameInstanceId,
|
||||
lastOnline = action.lastOnline,
|
||||
universeId = action.universeId,
|
||||
}),
|
||||
})
|
||||
end
|
||||
elseif action.type == SetUserThumbnail.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
local thumbnails = user.thumbnails or {}
|
||||
state = Immutable.JoinDictionaries(state, {
|
||||
[action.userId] = Immutable.JoinDictionaries(user, {
|
||||
thumbnails = Immutable.JoinDictionaries(thumbnails, {
|
||||
[action.thumbnailType] = Immutable.JoinDictionaries(thumbnails[action.thumbnailType] or {}, {
|
||||
[action.thumbnailSize] = action.image,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
end
|
||||
elseif action.type == SetUserMembershipType.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
state = Immutable.JoinDictionaries(state, {
|
||||
[action.userId] = Immutable.JoinDictionaries(user, {
|
||||
membership = action.membershipType,
|
||||
}),
|
||||
})
|
||||
end
|
||||
elseif action.type == RemoveUser.name then
|
||||
if state[action.userId] then
|
||||
state = Immutable.RemoveFromDictionary(state, action.userId)
|
||||
end
|
||||
elseif action.type == ReceivedDisplayName.name then
|
||||
local user = state[action.userId]
|
||||
if user then
|
||||
state = Immutable.JoinDictionaries(state, {
|
||||
[action.userId] = Immutable.JoinDictionaries(user, {
|
||||
displayName = action.displayName,
|
||||
}),
|
||||
})
|
||||
end
|
||||
end
|
||||
return state
|
||||
end
|
||||
@@ -0,0 +1,106 @@
|
||||
return function()
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local MockId = require(CorePackages.AppTempCommon.LuaApp.MockId)
|
||||
local User = require(CorePackages.AppTempCommon.LuaApp.Models.User)
|
||||
local Users = require(CorePackages.AppTempCommon.LuaApp.Reducers.Users)
|
||||
|
||||
local AddUser = require(CorePackages.AppTempCommon.LuaApp.Actions.AddUser)
|
||||
local ReceivedUserPresence = require(CorePackages.AppTempCommon.LuaChat.Actions.ReceivedUserPresence)
|
||||
local SetUserIsFriend = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserIsFriend)
|
||||
local SetUserMembershipType = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserMembershipType)
|
||||
local SetUserPresence = require(CorePackages.AppTempCommon.LuaApp.Actions.SetUserPresence)
|
||||
|
||||
describe("initial state", function()
|
||||
it("should return an initial table when passed nil", function()
|
||||
local state = Users(nil, {})
|
||||
expect(state).to.be.a("table")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("AddUser", function()
|
||||
it("should add a user to the store", function()
|
||||
local user = User.mock()
|
||||
local state = {}
|
||||
|
||||
state = Users(state, AddUser(user))
|
||||
|
||||
expect(state[user.id]).to.equal(user)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("SetUserIsFriend", function()
|
||||
it("should set isFriend on an existing user", function()
|
||||
local user = User.mock()
|
||||
local state = {
|
||||
[user.id] = user
|
||||
}
|
||||
|
||||
expect(state[user.id].isFriend).to.equal(false)
|
||||
|
||||
state = Users(state, SetUserIsFriend(user.id, true))
|
||||
expect(state[user.id].isFriend).to.equal(true)
|
||||
|
||||
state = Users(state, SetUserIsFriend(user.id, false))
|
||||
expect(state[user.id].isFriend).to.equal(false)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("SetUserPresence", function()
|
||||
it("should set presence on an existing user", function()
|
||||
local user = User.mock()
|
||||
local state = {
|
||||
[user.id] = user
|
||||
}
|
||||
|
||||
expect(state[user.id].presence).to.equal(User.PresenceType.OFFLINE)
|
||||
|
||||
state = Users(state, SetUserPresence(user.id, User.PresenceType.ONLINE))
|
||||
expect(state[user.id].presence).to.equal(User.PresenceType.ONLINE)
|
||||
|
||||
state = Users(state, SetUserPresence(user.id, User.PresenceType.IN_GAME))
|
||||
expect(state[user.id].presence).to.equal(User.PresenceType.IN_GAME)
|
||||
|
||||
state = Users(state, SetUserPresence(user.id, User.PresenceType.IN_STUDIO))
|
||||
expect(state[user.id].presence).to.equal(User.PresenceType.IN_STUDIO)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ReceivedUserPresence", function()
|
||||
it("should set presence on an existing user", function()
|
||||
local user = User.mock()
|
||||
local state = {
|
||||
[user.id] = user
|
||||
}
|
||||
|
||||
local existingPresence = user.presence
|
||||
local newPresence = 'ONLINE'
|
||||
local lastLocation = MockId()
|
||||
local newPlaceId = MockId()
|
||||
|
||||
state = Users(state, ReceivedUserPresence(user.id, newPresence, lastLocation, newPlaceId))
|
||||
|
||||
expect(user.presence).to.equal(existingPresence)
|
||||
expect(state[user.id].presence).to.equal(newPresence)
|
||||
expect(state[user.id].lastLocation).to.equal(lastLocation)
|
||||
expect(state[user.id].placeId).to.equal(newPlaceId)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("SetUserMembershipType", function()
|
||||
it("should set membership on an existing user", function()
|
||||
local user = User.mock()
|
||||
local state = {
|
||||
[user.id] = user
|
||||
}
|
||||
|
||||
local existingMembership = user.membership
|
||||
local newMembership = Enum.MembershipType.BuildersClub
|
||||
|
||||
state = Users(state, SetUserMembershipType(user.id, newMembership))
|
||||
|
||||
expect(user.membership).to.equal(existingMembership)
|
||||
expect(state[user.id].membership).to.equal(newMembership)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
Reference in New Issue
Block a user