как проверить API с массивом на почтальоне - PullRequest
0 голосов
/ 28 июня 2019

Все API, используемые в приложении, имеют общую конечную точку: https://m.companyname.com/application/svcwebservice.php

JSON имеет вложенные массивы, и ответ выглядит так:

[{
    "usertype": [{
        "id": "1",
        "type": "Service Manager (Admin)",
        "description": "Service Manager (Admin)"
    }, {
        "id": "2",
        "type": "Customer Relations Executive",
        "description": "Customer Relations Executive"
    }, {
        "id": "3",
        "type": "Service Advisor",
        "description": "Service Advisor"
    }, {
        "id": "4",
        "type": "Accountant (Admin)",
        "description": "Accountant (Admin)"
    }, {
        "id": "5",
        "type": "Technician\/Mechanic",
        "description": "Technician\/Mechanic"
    }, {
        "id": "6",
        "type": "Sales Manager (Admin)",
        "description": "Sales Manager (Admin)"
    }, {
        "id": "7",
        "type": "Sales Consultant",
        "description": "Sales Consultant"
    }, {
        "id": "8",
        "type": "Receptionist",
        "description": "Receptionist"
    }, {
        "id": "9",
        "type": "Implant (Admin)",
        "description": "Implant (Admin)"
    }, {
        "id": "10",
        "type": "Vice President \/ General Manager - Sales (Admin)",
        "description": "Vice President \/ General Manager - Sales (Admin)"
    }, {
        "id": "11",
        "type": "Group Manager (Admin)",
        "description": "Group Manager (Admin)"
    }, {
        "id": "13",
        "type": "Coordinator",
        "description": "Coordinator"
    }, {
        "id": "14",
        "type": "Customer Relations Manager (Admin)",
        "description": "Customer Relations Manager (Admin)"
    }, {
        "id": "15",
        "type": "Receptionist",
        "description": "Receptionist"
    }, {
        "id": "16",
        "type": "Vice President \/ General Manager - Service (Admin)",
        "description": "Vice President \/ General Manager - Service (Admin)"
    }, {
        "id": "17",
        "type": "Principal (Admin)",
        "description": "Principal (Admin)"
    }, {
        "id": "18",
        "type": "CEO (Admin)",
        "description": "CEO (Admin)"
    }, {
        "id": "19",
        "type": "COO (Admin)",
        "description": "COO (Admin)"
    }, {
        "id": "20",
        "type": "Insurane Admin",
        "description": "Insurane Admin"
    }]
}]

И полезная нагрузка:requesttype: "getusertypes"

Эта же конечная точка API дает следующий ответ для другой полезной нагрузки, такой как:

[{
    "cards": [{
        "average_inv_amount": "26",
        "on_time_checkin": "100.00%",
        "ontime_pickup_percentage": "81.89%",
        "average_distance": "5.5",
        "cust_rating": "4.2",
        "total_vehicle": "4"
    }]
}, {
    "pickup_details": [{
        "name": "Awaiting",
        "value": "0"
    }, {
        "name": "Active Pickup",
        "value": "1"
    }, {
        "name": "Not Checked in",
        "value": "0"
    }, {
        "name": "Checked In",
        "value": "0"
    }, {
        "name": "Picked Up Today",
        "value": "1"
    }]
}, {
    "drop_details": [{
        "name": "Awaiting",
        "value": "0"
    }, {
        "name": "To Service Centre",
        "value": "0"
    }, {
        "name": "To Customer",
        "value": "0"
    }, {
        "name": "Active Dropoff ",
        "value": "0"
    }, {
        "name": "Delivered Today",
        "value": "0"
    }]
}, {
    "notification": [{
        "queue_paused_pickup": "0",
        "queue_paused_dropoff": "0",
        "not_checkedin": "1",
        "queue_cancelled": "2",
        "queue_rescheduled": "0",
        "queue_mishaps": "0"
    }]
}, {
    "prepaid": [{
        "pre_paid": "-250",
        "credit_limit": "10000",
        "show_add_credit": "1",
        "allow_booking": "1"
    }]
}]

и т. д.

Вопрос:

Как мне проверить это с помощью почтальона?

1 Ответ

0 голосов
/ 28 июня 2019

Это зависит от того, что вы хотите проверить.

Сначала проанализируйте ваш ответ с помощью var jsonData = pm.response.json();

Вы можете получить доступ к ним, индексировав, например,

pm.test("Your test name", function() {
    var jsonData = pm.response.json();

    //For Entry 4
    pm.expect(jsonData[0].usertype[3].id).to.eql("4");
    pm.expect(jsonData[0].usertype[3].type).to.eql("Accountant (Admin)");
    pm.expect(jsonData[0].usertype[3].description).to.eql("Accountant (Admin)");
});

Или итерируйтенад ними с помощью for-циклов.Но это сильно зависит от вашего теста.

...