--[[----------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2023 Adobe
All Rights Reserved.

NOTICE: All information contained herein is, and remains
the property of Adobe and its suppliers, if any. The intellectual
and technical concepts contained herein are proprietary to Adobe
and its suppliers and are protected by all applicable intellectual
property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from Adobe.

------------------------------------------------------------------------------]]

	-- WF.web.http_client
local WFRxHttpClientUtils = require 'WFRxHttpClientUtils'

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

--============================================================================--

local WFRxHttpClientUtilsTest = {}

--------------------------------------------------------------------------------

function WFRxHttpClientUtilsTest.rxTestAppNumber( rxTest )

	rxTest:expectEqual( "0.0.", WFRxHttpClientUtils.normalizeAppNumber( "" ) )

	rxTest:expectEqual( "0.0.Dev", WFRxHttpClientUtils.normalizeAppNumber( "Dev" ) )

	rxTest:expectEqual( "1.0.0", WFRxHttpClientUtils.normalizeAppNumber( "1" ) )

	rxTest:expectEqual( "1.0.0.Dev", WFRxHttpClientUtils.normalizeAppNumber( "1.Dev" ) )

end

--------------------------------------------------------------------------------

function WFRxHttpClientUtilsTest.rxTestGetUserAgent( rxTest )

	local userAgent = WFRxHttpClientUtils.getUserAgent()

	-- It's almost impossible to verify this thoroughly as the reslut is
	-- different on every machine.

	rxTest:expectEqual( true, string.len( userAgent ) > 0 )

end

--------------------------------------------------------------------------------

function WFRxHttpClientUtilsTest.rxTestSplitMultipartResponseAtBoundary( rxTest )

	local function createPseudoMultipartResponse( boundary )

		local multiPartTemplate =[[one%stwo%sthree]]
		return string.format( multiPartTemplate, boundary, boundary )

	end

	local function verifyForBoundary( boundary )

		local multipartResponse = createPseudoMultipartResponse( boundary )

		local parts = WFRxHttpClientUtils.splitMultipartResponseAtBoundary( multipartResponse, boundary )

		local expected = {
			"one",
			"two",
			"three"
		}

		rxTest:expectEqual( expected, parts )

	end

	verifyForBoundary( "--onlyalphanumericchars" )
	verifyForBoundary( "--throw-in-some-magic-chars" )
	verifyForBoundary( "--throw in some spaces" )
	verifyForBoundary( "--all(of)the.magic+chars-is-fun?" )

end

--------------------------------------------------------------------------------

return WFRxTestCase.wrapSuite( 'WFRxHttpClientUtilsTest', WFRxHttpClientUtilsTest )
