Trade Me-9-Remove a purchase from your won items list API testing | Postman API automation testing

API Function

Hides a listing from the won items list.

API - Remove a purchase from your won items list script development steps

API Specification -> Business Presentation -> API Testing Script Debugging -> API Testing Script Enhancement -> API Testing Script Negative Cases Extension -> API Testing Script Publishment

API Specification

  • Key request fields

  • Key response fields - Details on whether the operation was successful.

Note that this operation will only report failure if the purchase still exists in the won items list after the operation completes. In all other cases, this API will report success (for example it will report success if the purchase ID is invalid or the purchase has already been removed).

Success Boolean Indicates whether the operation was successful.
Description String or null The description of the error, if the operation failed.
  • Example request

GET https://api.tmsandbox.co.nz/v1/MyTradeMe/Won/00000.JSON

  • Example response

{
    "Success": true,
    "Description": "Success"
}

Business Presentation

  • Front-end page - Won list page (pick a given item to delete)

Login > My Trade Me > Won > Delete > Confirm to delete

  • Front-end page - Confirm to remove a given item from won items list.

  • Business scope selection

Chained combination transactions

Retrieve your won items -> Remove a purchase from your won items list(I’m here) -> General search -> Retrieve the details of a single listing -> Buy an auction using Buy Now

Choose API - ‘Retrieve your won items’ as pre-request to get all won items that want to be removed

Remove all won items on the won items list

  • Business verification points

Checking a purchased item has been removed by visiting the won items list page.

API Testing Script Debugging

Fetch two environment variables: {{WonPurchaseId}} and {{WonPurchaseIdCount}} which means all won items PurchaseId and their counts on the watch list. These variables set origin from the response of the upstream API - ‘Retrieve your won items ’.

var WonPurchaseIdCount = pm.environment.get("WonPurchaseIdCount");

var WonPurchaseId = pm.environment.get("WonPurchaseId").split(",");
...

Where to set the two variables refer to: Retrieve your won items - API Testing Script Debugging -> API checkpoint.

Remove all won items from the won items list, but leave the last won item (for later request ‘Remove a purchase from your won items list ’ to use.

if (WonPurchaseIdCount <= 0){

    postman.setEnvironmentVariable('LastWonPurchaseId', "00000");

}

else if (WonPurchaseIdCount == 1){

    postman.setEnvironmentVariable('LastWonPurchaseId', WonPurchaseId[(Number(WonPurchaseIdCount) - 1)]);

}

else{

    //Remove all items but the last item on the won list. The later transaction will remove the last item from the won list.
    console.log("Pre-Transaction: RemoveAPurchaseFromYourWonItemsList Start");

    postman.setEnvironmentVariable('LastWonPurchaseId', WonPurchaseId[(Number(WonPurchaseIdCount) - 1)]);

    var LastWonPurchaseId = pm.environment.get("LastWonPurchaseId");

    console.log("LastWonPurchaseId: " + LastWonPurchaseId);

    //Exclude the last WonPurchaseId
    for (var i = 0; i < (WonPurchaseId.length - 1); i++) {

        const pre_request = {

            url: pm.environment.get("BaseUrl") + '/v1/MyTradeMe/Won/' + WonPurchaseId[i] + '.JSON',

            method: 'DELETE',

    		header:['Content-Type:application/json', 'Authorization:OAuth oauth_consumer_key="your Consumer Key",oauth_token="your OAuth Token",oauth_signature_method="PLAINTEXT",oauth_timestamp="1623834029",oauth_nonce="Zr5dzIAuVON",oauth_version="1.0",oauth_signature="your Consumer Secret%26your OAuth Token Secret"'],

            body: {
            }

        };

        pm.sendRequest(pre_request, function (err, response) {

            if (err) {

                console.log(err);

                console.log("Pre-Transaction: RemoveAPurchaseFromYourWonItemsList Failed");

            }

            else {

                // Output the ListingId that has been deleted
                pm.test("Delete PurchaseId from the Wonlist, but leave the LastPurchaseId: " + LastWonPurchaseId, function () {
                    // console.log(response.json());                  
                });

            }

        });

    }

    setTimeout(()=>{

        console.log("Pre-Transaction: RemoveAPurchaseFromYourWonItemsList Pass");
        
    }, 2000);
}

Note: how to get Consumer Key, Consumer Secret, OAuth Token, and OAuth Token Secret, please refer to Preparation before API testing demo

  • Choose the OAuth 1.0 in the Authorization label of Postman to authorize the request.

The OAuth 1.0 is for the transaction that needs to be authorized before sending. Template likes the below:

How to get Consumer Key, Consumer Secret, OAuth Token, and OAuth Token Secret, please refer to Preparation before API testing demo

Base on the API specification, parameter - purchaseId means the hided item from the won items list.

And the purchaseId origin from the response of pre_request ‘Remove a purchase from your won items list ’, and it has already been set to environment variables: {{LastWonPurchaseId}}.

So the request should be DELETE https://api.tmsandbox.co.nz/v1/MyTradeMe/Won/{{LastWonPurchaseId}}.JSON

  • API connectivity

The connectivity test passes and gets a response example.

{
    "Success": true,
    "Description": "Success"
}
  • API checkpoint

Check wheter have items on the won list.

Then we get the checking code snippet below base on the example feature.

//Check wheter have items on the won list
console.log("Post-Transaction: CheckingDeleteWonItems Start");

var LastWonPurchaseId = pm.environment.get("LastWonPurchaseId");

const post_request = {

    url: pm.environment.get("BaseUrl") + '/v1/MyTradeMe/Won/All.JSON',

    method: 'GET',

  	header:['Content-Type:application/json', 'Authorization:OAuth oauth_consumer_key="Your consumerKey",oauth_token="Your token",oauth_signature_method="PLAINTEXT",oauth_timestamp="1623834029",oauth_nonce="Zr5dzIAuVON",oauth_version="1.0",oauth_signature="Your consumerSecret%26Your tokenSecret"'],

    body: {
    }

};

pm.sendRequest(post_request, function (err, response) {

    if (err) {

        console.log(err);

        console.log("Post-Transaction: CheckingDeleteWonItems Failed");

    }

    else {

        // Output the PurchaseId that has been removed
        pm.test("Checking LastWonPurchaseId: " +LastWonPurchaseId +" has been removed", function () {

            var jsonData = response.json();

            var TotalCount = jsonData.TotalCount;

            if (TotalCount == 0){

                console.log("Current items count on the won list: "+TotalCount + ". All items have been removed from the won list.");

                console.log("Post-Transaction: CheckingDeleteWonItems Pass");

            }

            else{

                console.log("Current items count on the won list: "+TotalCount + ". Still have Items need to be removed from the won list.");
                
                console.log("Post-Transaction: CheckingDeleteWonItems Failed");
                
            }

        });

    }
       
});

Run script to verify the checkpoint works from console log.

One item is removed from the won list page.

Multiple items are removed from the won list page.

API Testing Script Enhancement

  • Enhance the script, such as to add the transactional function, exceptional verification, parameterization, etc.

  • Run the final script and to verify from front-end page or console log.

Display on the Won list page before removing operation.

Display on the Won list page after removing operation.

API Testing Script Negative Cases Extension

Using the ‘Equivalent Class Partitioning’ and ‘Boundary Value Analysis’ as we did in manual testing cases.

These API test scripts are doing the negative direction of the business, to be an extension to the above API positive case.

API Testing Script Publishment

Move script from debug folder to public folder when we finished API positive and negative cases.

Then wait to be published to the GitHub specific repo combining with other scripts using the CICD tool.

Copyright

This work is licensed under CC BY-NC-ND 4.0 .