local b=script.Parent.Parent.Parent.Parent local e=b.Parent local p=require(e.LuauPolyfill)local k=p.Object local F=require(e.Dev.JestGlobals)local R=F.describe local K=F.expect local J=F.it local f=(require(script.Parent.Parent.compact)).compact local B=require(b.luaUtils.hasOwnProperty)R("\099\111\109\112\097\099\116",function()J("\115\104\111\117\108\100 \112\114\111\100\117\099\101 \097\110 \101\109\112\116\121 \111\098\106\101\099\116 \119\104\101\110 \099\097\108\108\101\100 \119\105\116\104\111\117\116 \097\114\103\115",function()(K(f())).toEqual({})end)J("\115\104\111\117\108\100 \109\101\114\103\101 \111\098\106\101\099\116\115 \119\105\116\104\111\117\116 \109\111\100\105\102\121\105\110\103 \116\104\101\109",function()local b={a=1,ay="\097"}local e={b=2,bee="\098"}local p=f(b,e);(K(p)).toEqual(k.assign({},b,e))local F=k.keys(b)table.sort(F)local R=k.keys(e)table.sort(R);(K(F)).toEqual({"\097","\097\121"});(K(R)).toEqual({"\098","\098\101\101"})end)J("\115\104\111\117\108\100 \099\108\101\097\110 \117\110\100\101\102\105\110\101\100 \118\097\108\117\101\115 \102\114\111\109 \115\105\110\103\108\101 \111\098\106\101\099\116\115",function()local b={zero=0;undef=nil;three=3}local e=f(b);(K(e)).toEqual({zero=0;three=3})local p=k.keys(e)table.sort(p);(K(p)).toEqual({"\116\104\114\101\101";"\122\101\114\111"})end)J("\115\104\111\117\108\100 \115\107\105\112 \111\118\101\114 \117\110\100\101\102\105\110\101\100 \118\097\108\117\101\115 \105\110 \108\097\116\101\114 \111\098\106\101\099\116\115",function()(K(f({a=1;b=2},{b=nil;c=3},{a=4;c=nil}))).toEqual({a=4;b=2,c=3})end)J("\115\104\111\117\108\100 \110\111\116 \108\101\097\118\101 \117\110\100\101\102\105\110\101\100 \112\114\111\112\101\114\116\105\101\115 \105\110 \114\101\115\117\108\116 \111\098\106\101\099\116",function()local b=f({a=1;b=nil},{a=2;c=nil});(K(B(b,"\097"))).toBe(true);(K(B(b,"\098"))).toBe(false);(K(B(b,"\099"))).toBe(false);(K(b)).toEqual({a=2})end)end)return{}
--[[
 * Copyright (c) 2021 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
]]
-- ROBLOX upstream: https://github.com/apollographql/apollo-client/blob/v3.4.2/src/utilities/common/__tests__/compact.ts

local srcWorkspace = script.Parent.Parent.Parent.Parent
local Packages = srcWorkspace.Parent
local LuauPolyfill = require(Packages.LuauPolyfill)
local Object = LuauPolyfill.Object

local JestGlobals = require(Packages.Dev.JestGlobals)
local describe = JestGlobals.describe
local expect = JestGlobals.expect
local it = JestGlobals.it

local compact = require(script.Parent.Parent.compact).compact
local hasOwn = require(srcWorkspace.luaUtils.hasOwnProperty)
describe("compact", function()
	it("should produce an empty object when called without args", function()
		expect(compact()).toEqual({})
	end)
	it("should merge objects without modifying them", function()
		local a = { a = 1, ay = "a" }
		local b = { b = 2, bee = "b" }
		local c = compact(a, b)
		expect(c).toEqual(Object.assign({}, a, b))
		-- ROBLOX deviation: can't rely on order of keys
		local aKeys = Object.keys(a)
		table.sort(aKeys)
		local bKeys = Object.keys(b)
		table.sort(bKeys)
		expect(aKeys).toEqual({ "a", "ay" })
		expect(bKeys).toEqual({ "b", "bee" })
	end)
	it("should clean undefined values from single objects", function()
		local source = { zero = 0, undef = nil, three = 3 }
		local result = compact(source)
		expect(result).toEqual({ zero = 0, three = 3 })
		-- ROBLOX deviation: can't rely on order of keys
		local resultKeys = Object.keys(result)
		table.sort(resultKeys)
		expect(resultKeys).toEqual({ "three", "zero" })
	end)
	it("should skip over undefined values in later objects", function()
		expect(compact({ a = 1, b = 2 }, { b = nil, c = 3 }, { a = 4, c = nil })).toEqual({
			a = 4,
			b = 2,
			c = 3,
		})
	end)
	it("should not leave undefined properties in result object", function()
		local result = compact({ a = 1, b = nil }, { a = 2, c = nil })
		expect(hasOwn(result, "a")).toBe(true)
		expect(hasOwn(result, "b")).toBe(false)
		expect(hasOwn(result, "c")).toBe(false)
		expect(result).toEqual({ a = 2 })
	end)
end)

return {}
