Files
XQuery-Allegro-API/XQuery Allegro API/API/test.xqm
2019-08-21 19:30:57 +02:00

164 lines
5.2 KiB
Plaintext

xquery version "3.1";
(:
: Module Name: XQuery Allegro API Test Library Module
:
: Module Version: 1.0
:
: Date: June 26, 2019
:
: Copyright: release11.com
:
: Properietary
: Extensions: none
:
: XQuery
: Specification: March 2019
:
: Module Overview: This contains tests for Allegro RESTApi.
:)
(:~
: This module provides unit tests.
:
: @author Tomasz Kaleta
: @since June 26, 2019
: @version 1.0
:)
module namespace test = "http://release11.com/allegro/test";
import module namespace allegro = "http://release11.com/xquery-allegro-api/api" at "api.xqm";
import module namespace auth = "http://release11.com/xquery-allegro-api/authorization" at "authorization.xqm";
(:~
: This variable contains valid parameters map for get-offers() function from Application Library Module.
:)
declare variable $test:validMap := map {'category.id' : '5','phrase' : 'iphone', 'sort' : '+price', 'seller.id' : '3252', 'searchMode' : 'REGULAR','offset' : '100', 'limit' : '20', 'include' : 'free', 'fallback' : 'true()' };
(:~
: This variable contains invalid parameters map for get-offers() function from Application Library Module.
:)
declare variable $test:invalidMap := map {'category.id' : '5','phrase' : 'iphone', 'notValidParam' : '+price'};
(:~
: This variable contains client id and client secret encoded in base64.
:)
declare variable $test:base64credentials as xs:string := "NGI3OWMyM2RhOTMxNGE2Y2E0MzhmYTg0YjhjYzA3MDg6UjB5SERBR292TVRDUFQ3aDMxbjltUHNxNWtNT1o1cktZS3k2aXN3dUFMNVppbzBqem9EYkFidU5WYjJsdkp3TQ==";
(:~
: This variable contains client id and client secret encoded in base64.
:)
declare variable $test:tokenType as xs:string := "Bearer";
(:~
: This variable contains access token granted by authorization server.
:)
declare variable $test:accessToken as xs:string := auth:get-access-token("https://allegro.pl/auth/oauth/token?grant_type=client_credentials", $test:base64credentials);
(:~
: This variable contains authorization header.
:)
(:~
: This variable contains authorization header.
:)
declare variable $test:authorizationUrl as xs:string := "https://allegro.pl/auth/oauth/token?grant_type=client_credentials";
(:~
: This variable contains base of url to search offers.
:)
declare variable $test:offersUrl as xs:string := "https://api.allegro.pl/offers/listing?";
(:~
: This variable contains base of url to search categories.
:)
declare variable $test:categoriesUrl as xs:string := "https://api.allegro.pl/sale/categories/";
(:~
: Test checks if response for token request contains access token .
declare %unit:test function test:should-contain-access-token()
{
unit:assert(not(empty(auth:get-access-token("https://allegro.pl/auth/oauth/token?grant_type=client_credentials", $test:base64credentials))))
};
:)
declare variable $test:authorizationHeader := auth:get-authorization-header($test:accessToken, $test:tokenType);
(:~ Test checks if response for token request contains access token :)
declare %unit:test function test:should-contain-access-token(
)
{
unit:assert(string-length(auth:get-access-token($test:authorizationUrl, $test:base64credentials)) > 0 )
};
(:~
: Test should return error as map contains invalid input parameter.
:)
declare %unit:test("expected", "err:FOER0000") function test:should-return-error-invalid-param()
{
allegro:get-offers($test:authorizationHeader, $test:offersUrl, $test:invalidMap)
};
(:~
: Test should pass and request should be send as map contains only valid input parameters.
:)
declare %unit:test function test:should-pass-get-offers()
{
unit:assert(allegro:get-offers($test:authorizationHeader, $test:offersUrl, $test:validMap))
};
(:~
: Test should pass and response status should be 200.
:)
declare %unit:test function test:should-be-200-status-offers()
{
unit:assert-equals(string(allegro:get-offers($test:authorizationHeader, $test:offersUrl, $test:validMap)//@status), '200')
};
(:~
: Test should pass and request should be sent as map contains only valid input parameters.
:)
declare %unit:test function test:should-pass-get-categories()
{
unit:assert(allegro:get-categories($test:authorizationHeader, $test:categoriesUrl))
};
(:~
: Test should pass and response status should be 200.
:)
declare %unit:test function test:should-be-200-status-categories()
{
unit:assert-equals(string(allegro:get-categories($test:authorizationHeader, $test:categoriesUrl)//@status), '200')
};
(:~
: Test should pass and response status should be 200.
:)
declare %unit:test function test:should-be-200-status-category-by-id()
{
unit:assert-equals(string(allegro:get-category-by-id($test:authorizationHeader, $test:categoriesUrl, 5)//@status), '200')
};
(:~
: Test should pass and response status should be 200.
:)
declare %unit:test function test:should-return-category-with-id-5()
{
unit:assert-equals(string(allegro:get-category-by-id($test:authorizationHeader, $test:categoriesUrl, 5)//id), '5')
};
(:~
: Test should pass and response status should be 200.
:)
declare %unit:test function test:should-be-200-status-category-params()
{
unit:assert-equals(string(allegro:get-category-params($test:authorizationHeader, $test:categoriesUrl, 5)//@status), '200')
};