freeCodeCamp/curriculum/challenges/ukrainian/06-quality-assurance/quality-assurance-and-testi.../run-functional-tests-on-an-...

127 lines
4.1 KiB
Markdown
Raw Normal View History

---
id: 587d824f367417b2b2512c5b
title: Запуск функціональних тестів на відповідь API за допомогою методу Chai-HTTP IV - PUT
challengeType: 2
forumTopicId: 301591
dashedName: run-functional-tests-on-an-api-response-using-chai-http-iv---put-method
---
# --description--
Нагадуємо, що цей проєкт створюється на основі наступного стартового проєкту на <a href="https://replit.com/github/freeCodeCamp/boilerplate-mochachai" target="_blank" rel="noopener noreferrer nofollow">Replit</a> або клонований з <a href="https://github.com/freeCodeCamp/boilerplate-mochachai/" target="_blank" rel="noopener noreferrer nofollow">GitHub</a>.
Ця вправа схожа на попередню.
Тепер, коли ви знаєте, як перевірити запит `PUT`, ваша черга зробити це з нуля.
# --instructions--
У межах `tests/2_functional-tests.js` змініть `'Send {surname: "da Verrazzano"}'`, перевірте (`// #4`) та використайте методи `put` та `send`, щоб перевірити кінцеву точку `'/travellers'`.
Надішліть наступний об'єкт JSON з вашим PUT-запитом:
```json
{
"surname": "da Verrazzano"
}
```
Перевірте наступне у межах виклику `request.end`:
1. `status` має бути `200`
2. `type` має бути `application/json`
3. `body.name` має бути `Giovanni`
4. `body.surname` має бути `da Verrazzano`
Дотримуйтесь порядку тверджень вище ми покладаємося на нього. Також обов'язково видаліть `assert.fail()` після завершення.
# --hints--
Необхідно пройти всі тести
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Перевірте значення `res.status` на 200
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.assertions[0].method, 'equal');
assert.equal(data.assertions[0].args[0], 'res.status');
assert.equal(data.assertions[0].args[1], '200');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Перевірте значення `res.type` на `'application/json'`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.assertions[1].method, 'equal');
assert.equal(data.assertions[1].args[0], 'res.type');
assert.match(data.assertions[1].args[1], /('|")application\/json\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Перевірте значення `res.body.name` на `'Giovanni'`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.assertions[2].method, 'equal');
assert.equal(data.assertions[2].args[0], 'res.body.name');
assert.match(data.assertions[2].args[1], /('|")Giovanni\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
Перевірте значення `res.body.surname` на `'da Verrazzano'`
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.assertions[3].method, 'equal');
assert.equal(data.assertions[3].args[0], 'res.body.surname');
assert.match(data.assertions[3].args[1], /('|")da Verrazzano\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--
```js
/**
Backend challenges don't need solutions,
because they would need to be tested against a full working project.
Please check our contributing guidelines to learn more.
*/
```