rossoneri rossoneri - 1 month ago 8
AngularJS Question

how to properly write url in httpBackend service in unit tests

I want to mock

$httpBackend.whenGet
request.

I can write full url as string, but i can not uderstend with last part where i define queryExpression:
"('120' != 1 AND '106' != 5)"


Example of request from console that working:

http://localhost:9002/api/application/datapage?dataPageType=application.group.datapage.GroupDataPageQuery&pageSize=-1&propertySelection=groupName,groupId&queryExpression=(%27120%27+!%3D+1+AND+%27106%27+!%3D+5)&startIndex=0


if i past this as string in
$httpBackend.whenGET( '/api/application/datapage?dataPageType=application.group.datapage.GroupDataPageQuery&pageSize=-1&propertySelection=groupName,groupId&queryExpression=(%27120%27+!%3D+1+AND+%27106%27+!%3D+5)&startIndex=0' )
,

i have Unexpected Error in my unit tests

Error: Unexpected request: GET /api/application/datapage?dataPageType=application.group.datapage.GroupDataPageQuery&pageSize=-1&propertySelection=groupName,groupId&queryExpression=('120'+!%3D+1+AND+'106'+!%3D+5)&startIndex=0


I define that proplem with wrong format of
queryExpression
.

Answer

First case that it is not so urgent to mock full url for request, i can use RegExp in $httpBackend.whenGet service for match parameters without query.

Second is what i asked and resolution is simple, using \ escape character.

So, the result is:

/api/application/datapage?dataPageType=application.group.datapage.GroupDataPageQuery&pageSize=-1&propertySelection=groupName,groupId&queryExpression=(\'120\'+!%3D+1+AND+\'106\'+!%3D+5)&startIndex=0