local Z=script.Parent.Parent.Parent.Parent local O=Z.Parent local y=require(O.LuauPolyfill)local S=y.Error local G=require(O.Dev.JestGlobals)local g=G.describe local T=G.expect local K=G.it local c=require(O.Promise)local r=(require(script.Parent.Parent.fromPromise)).fromPromise local V=(require(script.Parent.Parent.toPromise)).toPromise local function W(...)(T(false)).toBe(true)end g("\102\114\111\109\080\114\111\109\105\115\101",function()local Z={data={hello="\119\111\114\108\100"}}local O=S.new("\073 \097\108\119\097\121\115 \101\114\114\111\114")K("\114\101\116\117\114\110 \110\101\120\116 \099\097\108\108 \097\115 \080\114\111\109\105\115\101 \114\101\115\111\108\117\116\105\111\110",function()local O=r(c.resolve(Z))return((V(O)):andThen(function(O)return(T(Z)).toEqual(O)end)):expect()end)K("\114\101\116\117\114\110 \080\114\111\109\105\115\101 \114\101\106\101\099\116\105\111\110 \097\115 \101\114\114\111\114 \099\097\108\108",function()local Z=r(c.reject(O))return(((V(Z)):andThen(W)):catch(function(Z)return(T(O)).toEqual(Z)end)):expect()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/link/utils/__tests__/fromPromise.ts

local srcWorkspace = script.Parent.Parent.Parent.Parent
local rootWorkspace = srcWorkspace.Parent
local LuauPolyfill = require(rootWorkspace.LuauPolyfill)
local Error = LuauPolyfill.Error

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

local Promise = require(rootWorkspace.Promise)

local fromPromise = require(script.Parent.Parent.fromPromise).fromPromise
local toPromise = require(script.Parent.Parent.toPromise).toPromise

-- ROBLOX deviation: method not available
local function fail(...)
	expect(false).toBe(true)
end

describe("fromPromise", function()
	local data = { data = { hello = "world" } }
	local error_ = Error.new("I always error")

	it("return next call as Promise resolution", function()
		local observable = fromPromise(Promise.resolve(data))
		return toPromise(observable)
			:andThen(function(result)
				return expect(data).toEqual(result)
			end)
			:expect()
	end)

	it("return Promise rejection as error call", function()
		local observable = fromPromise(Promise.reject(error_))
		return toPromise(observable)
			:andThen(fail)
			:catch(function(actualError)
				return expect(error_).toEqual(actualError)
			end)
			:expect()
	end)
end)

return {}
