Skip to content

Commit

Permalink
fix: HttpResponse.rawData accepts only AssocArray (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
bchelkowski authored Nov 3, 2023
1 parent 9924bf8 commit 33b5caa
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end function
function parseResponse(response as Object) as Object
user = CreateObject("roSGNode", "User") ' example custom roSGNode extending Node
user.status = response.rawData.status
user.status = response.raw.data.status
return user
end function
Expand Down
4 changes: 3 additions & 1 deletion src/components/http/HttpResponse.brs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
' @param {String} responseData.failureReason
' @param {Object} responseData.headers
' @param {Integer} responseData.httpStatusCode
' @param {Object} responseData.rawData
' @param {Object} responseData.requestOptions
' @param {Integer} [responseData.time]
function HttpResponse(responseData as Object) as Object
Expand All @@ -25,7 +26,7 @@ function HttpResponse(responseData as Object) as Object
prototype._failureReason = getProperty(responseData, "failureReason", "OK")
prototype._headers = getProperty(responseData, "headers", {})
prototype._httpStatusCode = getProperty(responseData, "httpStatusCode", -1)
prototype._rawData = getProperty(responseData, "rawData", {})
prototype._rawData = getProperty(responseData, "rawData")
prototype._requestOptions = responseData.requestOptions
prototype._time = DateTime().asSeconds()

Expand All @@ -44,6 +45,7 @@ function HttpResponse(responseData as Object) as Object
isReusable: m.isReusable(),
isSuccess: m._isSuccess(),
maxAge: m.getMaxAge(),
raw: { data: m._rawData },
rawData: m._rawData,
requestOptions: m._requestOptions,
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/http/HttpResponse.model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<field id="isReusable" type="boolean" />
<field id="isSuccess" type="boolean" />
<field id="maxAge" type="integer" />
<field id="rawData" type="assocarray" />
<field id="raw" type="assocarray" />
<field id="rawData" type="assocarray" /> <!-- @deprecated - raw field contains data key with rawData value now - raw = { data: <rawData value>} -->
<field id="requestOptions" type="assocarray" />
</interface>
</component>
2 changes: 2 additions & 0 deletions src/components/http/_tests/HttpResponse_Main.test.brs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function TestSuite__HttpResponse_Main() as Object
headers: props.headers,
id: props.id,
isSuccess: true,
raw: { data: props.rawData },
rawData: props.rawData,
})

Expand All @@ -43,6 +44,7 @@ function TestSuite__HttpResponse_Main() as Object
httpStatusCode: props.httpStatusCode,
failureReason: props.failureReason,
headers: props.headers,
raw: { data: props.rawData },
rawData: props.rawData,
})

Expand Down
2 changes: 2 additions & 0 deletions src/components/http/request/_mocks/Request.mock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<field id="data" type="assocarray" />
<field id="options" type="assocarray" />
<field id="result" type="node" />
<!-- Task fields -->
<field id="control" type="string" />
</interface>

<script type="text/brightscript" uri="Request.mock.brs" />
Expand Down
1 change: 0 additions & 1 deletion src/components/router/_tests/Router.test.brs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ end function

sub RouterTestSuite__TearDown(ts as Object)
m.top.activatedRoute = CreateObject("roSGNode", "ActivatedRoute")
m.top.activatedPath = ""
m.top.url = "/"

m._history = []
Expand Down

0 comments on commit 33b5caa

Please # to comment.