local j=script.Parent.Parent.Parent local m=j.Parent local V=require(m.Dev.JestGlobals)local f=V.describe local y=V.expect local Y=V.it local c=(require(j.errors)).ApolloError local s=(require(m.GraphQL)).GraphQLError local b=(require(m.LuauPolyfill)).String local w=require(m.LuauPolyfill)local p=w.Error f("\065\112\111\108\108\111\069\114\114\111\114",function()Y("\115\104\111\117\108\100 \099\111\110\115\116\114\117\099\116 \105\116\115\101\108\102 \099\111\114\114\101\099\116\108\121",function()local j={s.new("\083\111\109\101\116\104\105\110\103 \119\101\110\116 \119\114\111\110\103 \119\105\116\104 \071\114\097\112\104\081\076");s.new("\083\111\109\101\116\104\105\110\103 \101\108\115\101 \119\101\110\116 \119\114\111\110\103 \119\105\116\104 \071\114\097\112\104\081\076")}local m=p.new("\078\101\116\119\111\114\107 \101\114\114\111\114")local V="\116\104\105\115 \105\115 \097\110 \101\114\114\111\114 \109\101\115\115\097\103\101"local f=c.new({graphQLErrors=j,networkError=m;errorMessage=V});(y(f.graphQLErrors)).toEqual(j);(y(f.networkError)).toEqual(m);(y(f.message)).toBe(V)end)Y("\115\104\111\117\108\100 \097\100\100 \097 \110\101\116\119\111\114\107 \101\114\114\111\114 \116\111 \116\104\101 \109\101\115\115\097\103\101",function()local j=p.new("\116\104\105\115 \105\115 \097\110 \101\114\114\111\114 \109\101\115\115\097\103\101")local m=c.new({networkError=j});(y(m.message)).toMatch("\116\104\105\115 \105\115 \097\110 \101\114\114\111\114 \109\101\115\115\097\103\101");(y(#b.split(m.message,"\n"))).toBe(1)end)Y("\115\104\111\117\108\100 \097\100\100 \097 \103\114\097\112\104\113\108 \101\114\114\111\114 \116\111 \116\104\101 \109\101\115\115\097\103\101",function()local j={s.new("\116\104\105\115 \105\115 \097\110 \101\114\114\111\114 \109\101\115\115\097\103\101")}local m=c.new({graphQLErrors=j});(y(m.message)).toMatch("\116\104\105\115 \105\115 \097\110 \101\114\114\111\114 \109\101\115\115\097\103\101");(y(#b.split(m.message,"\n"))).toBe(1)end)Y("\115\104\111\117\108\100 \097\100\100 \109\117\108\116\105\112\108\101 \103\114\097\112\104\113\108 \101\114\114\111\114\115 \116\111 \116\104\101 \109\101\115\115\097\103\101",function()local j={s.new("\116\104\105\115 \105\115 \110\101\119");s.new("\116\104\105\115 \105\115 \111\108\100")}local m=c.new({graphQLErrors=j})local V=b.split(m.message,"\n");(y(#V)).toBe(2);(y(V[1])).toMatch("\116\104\105\115 \105\115 \110\101\119");(y(V[2])).toMatch("\116\104\105\115 \105\115 \111\108\100")end)Y("\115\104\111\117\108\100 \097\100\100 \098\111\116\104 \110\101\116\119\111\114\107 \097\110\100 \103\114\097\112\104\113\108 \101\114\114\111\114\115 \116\111 \116\104\101 \109\101\115\115\097\103\101",function()local j={s.new("\103\114\097\112\104\113\108 \101\114\114\111\114 \109\101\115\115\097\103\101")}local m=p.new("\110\101\116\119\111\114\107 \101\114\114\111\114 \109\101\115\115\097\103\101")local V=c.new({graphQLErrors=j;networkError=m})local f=b.split(V.message,"\n");(y(#f)).toBe(2);(y(f[1])).toMatch("\103\114\097\112\104\113\108 \101\114\114\111\114 \109\101\115\115\097\103\101");(y(f[2])).toMatch("\110\101\116\119\111\114\107 \101\114\114\111\114 \109\101\115\115\097\103\101")end)Y("\115\104\111\117\108\100 \099\111\110\116\097\105\110 \097 \115\116\097\099\107 \116\114\097\099\101",function()local j={s.new("\103\114\097\112\104\113\108 \101\114\114\111\114 \109\101\115\115\097\103\101")}local m=p.new("\110\101\116\119\111\114\107 \101\114\114\111\114 \109\101\115\115\097\103\101")local V=c.new({graphQLErrors=j;networkError=m});(y(V.stack)).toBeDefined()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/errors/__tests__/ApolloError.ts

local srcWorkspace = script.Parent.Parent.Parent
local Packages = srcWorkspace.Parent

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

local ApolloError = require(srcWorkspace.errors).ApolloError

local GraphQLError = require(Packages.GraphQL).GraphQLError

local String = require(Packages.LuauPolyfill).String

-- ROBLOX deviation: add polyfills for JS Primitives
local LuauPolyfill = require(Packages.LuauPolyfill)
local Error = LuauPolyfill.Error

describe("ApolloError", function()
	it("should construct itself correctly", function()
		local graphQLErrors = {
			GraphQLError.new("Something went wrong with GraphQL"),
			GraphQLError.new("Something else went wrong with GraphQL"),
		}
		local networkError = Error.new("Network error")
		local errorMessage = "this is an error message"
		local apolloError = ApolloError.new({
			graphQLErrors = graphQLErrors,
			networkError = networkError,
			errorMessage = errorMessage,
		})
		expect(apolloError.graphQLErrors).toEqual(graphQLErrors)
		expect(apolloError.networkError).toEqual(networkError)
		expect(apolloError.message).toBe(errorMessage)
	end)
	it("should add a network error to the message", function()
		local networkError = Error.new("this is an error message")
		local apolloError = ApolloError.new({ networkError = networkError })
		expect(apolloError.message).toMatch("this is an error message")
		expect(#String.split(apolloError.message, "\n")).toBe(1)
	end)
	it("should add a graphql error to the message", function()
		local graphQLErrors = { GraphQLError.new("this is an error message") }
		local apolloError = ApolloError.new({ graphQLErrors = graphQLErrors })
		expect(apolloError.message).toMatch("this is an error message")
		expect(#String.split(apolloError.message, "\n")).toBe(1)
	end)
	it("should add multiple graphql errors to the message", function()
		local graphQLErrors = { GraphQLError.new("this is new"), GraphQLError.new("this is old") }
		local apolloError = ApolloError.new({ graphQLErrors = graphQLErrors })
		local messages = String.split(apolloError.message, "\n")
		expect(#messages).toBe(2)
		expect(messages[
			1 --[[ ROBLOX adaptation: added 1 to array index ]]
		]).toMatch("this is new")
		expect(messages[
			2 --[[ ROBLOX adaptation: added 1 to array index ]]
		]).toMatch("this is old")
	end)
	it("should add both network and graphql errors to the message", function()
		local graphQLErrors = { GraphQLError.new("graphql error message") }
		local networkError = Error.new("network error message")
		local apolloError = ApolloError.new({
			graphQLErrors = graphQLErrors,
			networkError = networkError,
		})
		local messages = String.split(apolloError.message, "\n")
		expect(#messages).toBe(2)
		expect(messages[
			1 --[[ ROBLOX adaptation: added 1 to array index ]]
		]).toMatch("graphql error message")
		expect(messages[
			2 --[[ ROBLOX adaptation: added 1 to array index ]]
		]).toMatch("network error message")
	end)
	it("should contain a stack trace", function()
		local graphQLErrors = { GraphQLError.new("graphql error message") }
		local networkError = Error.new("network error message")
		local apolloError = ApolloError.new({
			graphQLErrors = graphQLErrors,
			networkError = networkError,
		})
		expect(apolloError.stack).toBeDefined()
	end)
end)

return {}
