How to handle endpoint that does not return immediate results

Viewed 46

I have an endpoint that I bid/request some amount for a vehicle and then in the response body, I do not see that particular amount, I can only see the previous amounts that bidded. But I can get the list of bidded amounts in the different endpoint. So basically I request from 1 endpoint and verify the response of different Read auctions endpoints. I do not how to maintain logic for API testing. Can you please advise? Thank you.

1st Request

it('bidding in external API', () => {
        cy.request({
            'method': 'POST',
            'url': `${Cypress.env('ampApiPrefixForExternalEndpoints')}/bid`,

            'headers': {
                'Authorization': Cypress.env('externalToken'),
                'content-type': Cypress.env('contentType'),
            },

            'body': {
                'id': 'bbbbbb',
                'bid': 42550,
                'auctionPlatformId': 'xxxx',
                'auctionPlatformUserId': 'aaaaa',
            },

            'failOnStatusCode': false,

        }).then((res) => {

            cy.log(JSON.stringify(res));
            expect(res.status).to.eq(200);


            })

        });

Response of Read auctions endpoints.

Received response (200):
{
    "data": {
        "auctions": [
            {
                "additionalCosts": xxx,
                "auctionCountryIso": "zxxc",
                "ahId": "12324",
                "auctionEndDatetime": "2022-03-20T06:03:47.394Z",
                "auctionStartDatetime": "2022-03-14T06:03:47.394Z",
                "auctionStatus": "ongoing",
                "auctionType": "type",
                "damageStatus": "normal",
                "bidStep": asddf,
                "bids": [
                    {
                        "amount": 29650,
                        "createdDatetime": "2022-03-15T05:56:47.394Z",
                        "externalData": [],
                        "isMaxBid": false,
                        "status": "accepted"
                    },
                    {
                        "amount": 29750,
                        "createdDatetime": "2022-03-15T05:57:47.394Z",
                        "externalData": [],
                        "isMaxBid": false,
                        "status": "accepted"
                    },
                    {
                        "amount": 29850,
                        "createdDatetime": "2022-03-15T05:58:47.394Z",
                        "externalData": [],
                        "isMaxBid": false,
                        "status": "accepted"
                    },
                    {
                        "amount": 29950,
                        "createdDatetime": "2022-03-15T05:59:47.394Z",
                        "externalData": [],
                        "isMaxBid": false,
                        "status": "accepted"
                    },
                    {
                        "amount": 30050,
                        "createdDatetime": "2022-03-15T06:00:47.395Z",
                        "externalData": [],
                        "isMaxBid": false,
                        "status": "accepted"
                    },
                    {
                        "amount": 30150,
                        "createdDatetime": "2022-03-15T06:01:47.395Z",
                        "externalData": [],
                        "isMaxBid": false,
                        "status": "accepted"
                    },
                    {
                        "amount": 30250,
                        "createdDatetime": "2022-03-15T06:02:47.395Z",
                        "externalData": [],
                        "isMaxBid": false,
                        "status": "accepted"
                    },
                    {
                        "amount": 44650,
                        "auctionPlatformId": "sdrwd",
                        "auctionPlatformUserId": "094c5519-bcaf-4100-8a40-904e04a7ecff",
                        "createdDatetime": "2022-03-15T14:34:54.432Z",
                        "externalData": {
                            "request_id": "saddsddse"
                        },
                        "isMaxBid": false,
                        "status": "accepted"
                    },
                    {
                        "amount": 44750,
                        "auctionPlatformId": "rwffffc",
                        "auctionPlatformUserId": "094c5519-bcaf-4100-8a40-904e04a7ecff",
                        "createdDatetime": "2022-03-15T14:35:11.596Z",
                        "externalData": {
                            "request_id": "adfds"
                        },
                        "isMaxBid": false,
                        "status": "accepted"
                    }
                ],
1 Answers

If you want to hit two endpoints in sequence, use .then() to chain the second one

cy.request({
  'method': 'POST',
  'url': `${Cypress.env('ampApiPrefixForExternalEndpoints')}/bid`,
  ...
}).then((res) => {
  // verify 1st endpoint
  expect(res.status).to.eq(200);
}).then(() => {
  // ensure sequential calling
  cy.request({
    'method': 'GET',
    'url': `${Cypress.env('ampApiPrefixForExternalEndpoints')}/read`,
    ...
  }).then((res) => {
    // verify 2nd endpoint
    expect(res.status).to.eq(200);
    ...
  })
})
Related