I have to test my bookshelf-api back-end in get all scenario. I want to get my all books with :
- status code 200 as successful status
- sorting by name, reading, and finish query
My handler file on handler.js with filter function on filter.js
pm.response.to.have.status(200);
});
pm.test('response header Content-Type should be application/json', () => {
pm.expect(pm.response.headers.get('Content-Type')).to.equals('application/json; charset=utf-8');
});
pm.test('response body should be an object', () => {
const responseJson = pm.response.json();
pm.expect(responseJson).to.be.an('object');
});
pm.test('response body object should have correct property and value', () => {
const responsJson = pm.response.json();
pm.expect(responsJson).to.haveOwnProperty('status');
pm.expect(responsJson).to.haveOwnProperty('data');
pm.expect(responsJson.status).to.equals('success');
pm.expect(responsJson.data).to.be.an('object');
});
pm.test('response body data object should have a array books and contains one items', () => {
const responseJson = pm.response.json();
const { data } = responseJson;
pm.expect(data).to.haveOwnProperty('books');
pm.expect(data.books).to.be.an('array');
pm.expect(data.books).to.lengthOf(1);
});
pm.test('the books should have contains only id, name, and publisher property', () => {
const responseJson = pm.response.json();
const { data: { books } } = responseJson;
books.forEach((book) => {
pm.expect(Object.keys(book)).to.lengthOf(3);
pm.expect(book).to.haveOwnProperty('id');
pm.expect(book).to.haveOwnProperty('name');
pm.expect(book).to.haveOwnProperty('publisher');
});
});```
But i had 4 fails
[![enter image description here][1]][1]
And this is my repository
https://github.com/faqirilmu31/bookshelf-api
Please anyone could help me?
[1]: https://i.stack.imgur.com/McQkO.png