local e=require(script.Parent.serializeRepository)return function()it("\115\104\111\117\108\100 \110\111\116 \109\097\107\101 \097\110\121 \099\104\097\110\103\101\115 \116\111 \097\110 \101\109\112\116\121 \114\101\112\111\115\105\116\111\114\121 \119\104\101\110 \103\105\118\101\110 \110\111 \099\104\097\110\103\101\115",function()local Q={}local U=e(Q,{});(expect(next(U))).to.equal(nil)end)it("\115\104\111\117\108\100 \110\111\116 \109\097\107\101 \097\110\121 \099\104\097\110\103\101\115 \119\104\101\110 \103\105\118\101\110 \110\111 \099\104\097\110\103\101\115",function()local Q={flag1={config={active=true,retired=false,ruleSets={}},version=1};flag2={config={active=true;retired=false;ruleSets={}};version=1}}local U=e(Q,{});(expect(U.flag1)).to.be.ok();(expect(U.flag1.version)).to.equal(1);(expect(U.flag2)).to.be.ok();(expect(U.flag2.version)).to.equal(1)end)it("\115\104\111\117\108\100 \097\100\100 \097 \110\101\119 \102\108\097\103 \116\111 \097 \114\101\112\111\115\105\116\111\114\121",function()local Q={flag1={config={active=true;retired=false;ruleSets={}};version=1},flag2={config={active=true;retired=false,ruleSets={}},version=1}}local U=e(Q,{flag3={change={active=true,retired=false,ruleSets={}};version=1}});(expect(U.flag1)).to.be.ok();(expect(U.flag1.version)).to.equal(1);(expect(U.flag2)).to.be.ok();(expect(U.flag2.version)).to.equal(1);(expect(U.flag3)).to.be.ok();(expect(U.flag2.version)).to.equal(1)end)it("\115\104\111\117\108\100 \117\112\100\097\116\101 \097\110 \101\120\105\115\116\105\110\103 \102\108\097\103 \105\110 \097 \114\101\112\111\115\105\116\111\114\121",function()local Q={flag1={config={active=true;retired=false;ruleSets={}},version=1},flag2={config={active=true,retired=false,ruleSets={}};version=1}}local U=e(Q,{flag1={change={active=false,retired=true;ruleSets={}},version=2}});(expect(U.flag1)).to.be.ok();(expect(U.flag1.version)).to.equal(2);(expect(U.flag1.config.active)).to.equal(false);(expect(U.flag1.config.retired)).to.equal(true);(expect(U.flag2)).to.be.ok();(expect(U.flag2.version)).to.equal(1)end)it("\115\104\111\117\108\100 \114\101\109\111\118\101 \097\110 \101\120\105\115\116\105\110\103 \102\108\097\103 \102\114\111\109 \097 \114\101\112\111\115\105\116\111\114\121",function()local Q={flag1={config={active=true,retired=false;ruleSets={}};version=1};flag2={config={active=true,retired=false;ruleSets={}},version=1}}local U=e(Q,{flag1={version=2}});(expect(U.flag1)).to.be.ok();(expect(U.flag1.config)).never.to.be.ok();(expect(U.flag1.version)).to.equal(2);(expect(U.flag2)).to.be.ok();(expect(U.flag2.version)).to.equal(1)end)end
local serializeRepository = require(script.Parent.serializeRepository)

return function()
	it("should not make any changes to an empty repository when given no changes", function()
		local repository = {}

		local updatedRepository = serializeRepository(repository, {})

		expect((next(updatedRepository))).to.equal(nil)
	end)

	it("should not make any changes when given no changes", function()
		local repository = {
			flag1 = {
				config = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
			flag2 = {
				config = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
		}

		local updatedRepository = serializeRepository(repository, {})

		expect(updatedRepository.flag1).to.be.ok()
		expect(updatedRepository.flag1.version).to.equal(1)

		expect(updatedRepository.flag2).to.be.ok()
		expect(updatedRepository.flag2.version).to.equal(1)
	end)

	it("should add a new flag to a repository", function()
		local repository = {
			flag1 = {
				config = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
			flag2 = {
				config = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
		}

		local updatedRepository = serializeRepository(repository, {
			flag3 = {
				change = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
		})

		expect(updatedRepository.flag1).to.be.ok()
		expect(updatedRepository.flag1.version).to.equal(1)

		expect(updatedRepository.flag2).to.be.ok()
		expect(updatedRepository.flag2.version).to.equal(1)

		expect(updatedRepository.flag3).to.be.ok()
		expect(updatedRepository.flag2.version).to.equal(1)
	end)

	it("should update an existing flag in a repository", function()
		local repository = {
			flag1 = {
				config = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
			flag2 = {
				config = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
		}

		local updatedRepository = serializeRepository(repository, {
			flag1 = {
				change = {
					active = false,
					retired = true,
					ruleSets = {},
				},
				version = 2,
			},
		})

		expect(updatedRepository.flag1).to.be.ok()
		expect(updatedRepository.flag1.version).to.equal(2)
		expect(updatedRepository.flag1.config.active).to.equal(false)
		expect(updatedRepository.flag1.config.retired).to.equal(true)

		expect(updatedRepository.flag2).to.be.ok()
		expect(updatedRepository.flag2.version).to.equal(1)
	end)

	it("should remove an existing flag from a repository", function()
		local repository = {
			flag1 = {
				config = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
			flag2 = {
				config = {
					active = true,
					retired = false,
					ruleSets = {},
				},
				version = 1,
			},
		}

		local updatedRepository = serializeRepository(repository, {
			flag1 = {
				version = 2,
			},
		})

		expect(updatedRepository.flag1).to.be.ok()
		expect(updatedRepository.flag1.config).never.to.be.ok()
		expect(updatedRepository.flag1.version).to.equal(2)

		expect(updatedRepository.flag2).to.be.ok()
		expect(updatedRepository.flag2.version).to.equal(1)
	end)
end
