4.1 KiB
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d824f367417b2b2512c5b | Запуск функціональних тестів на відповідь API за допомогою методу Chai-HTTP IV - PUT | 2 | 301591 | run-functional-tests-on-an-api-response-using-chai-http-iv---put-method |
--description--
Нагадуємо, що цей проєкт створюється на основі наступного стартового проєкту на Replit або клонований з GitHub.
Ця вправа схожа на попередню.
Тепер, коли ви знаєте, як перевірити запит PUT
, ваша черга зробити це з нуля.
--instructions--
У межах tests/2_functional-tests.js
змініть 'Send {surname: "da Verrazzano"}'
, перевірте (// #4
) та використайте методи put
та send
, щоб перевірити кінцеву точку '/travellers'
.
Надішліть наступний об'єкт JSON з вашим PUT-запитом:
{
"surname": "da Verrazzano"
}
Перевірте наступне у межах виклику request.end
:
status
має бути200
type
має бутиapplication/json
body.name
має бутиGiovanni
body.surname
має бутиda Verrazzano
Дотримуйтесь порядку тверджень вище – ми покладаємося на нього. Також обов'язково видаліть assert.fail()
після завершення.
--hints--
Необхідно пройти всі тести
(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
(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'
(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'
(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'
(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--
/**
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.
*/