Skip to content

Commit 102c392

Browse files
author
Alejandro Fernández Gómez
committed
Scaffold fetchSearchResults
Add a test suite as well to help the candidates with the implementation.
1 parent efcbef3 commit 102c392

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

db/db.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,8 @@
835835
975360,
836836
974127,
837837
974425,
838-
974127
838+
974127,
839+
918256
839840
]
840841
},
841842
{

src/api/search.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function fetchSearchResults(query) {
2+
// Write your code here
3+
}

src/api/search.spec.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { fetchSearchResults } from './search';
2+
3+
describe('fetchSearchResults', () => {
4+
// Replace `xit` for `it` in each test
5+
xit('Returns a promise', () => {
6+
expect(fetchSearchResults()).toBeInstanceOf(Promise);
7+
});
8+
9+
xit('Returns an empty response if no query is given', done => {
10+
return fetchSearchResults().then(results => {
11+
expect(results).toEqual([]);
12+
done();
13+
});
14+
});
15+
16+
xit('Returns an empty response if query is ""', done => {
17+
return fetchSearchResults('').then(results => {
18+
expect(results).toEqual([]);
19+
done();
20+
});
21+
});
22+
23+
xit('Throws if query has not type `string`', () => {
24+
expect(() => {
25+
fetchSearchResults({});
26+
}).toThrow(TypeError);
27+
28+
expect(() => {
29+
fetchSearchResults([]);
30+
}).toThrow(TypeError);
31+
32+
expect(() => {
33+
fetchSearchResults(NaN);
34+
}).toThrow(TypeError);
35+
36+
expect(() => {
37+
fetchSearchResults(12345);
38+
}).toThrow(TypeError);
39+
40+
expect(() => {
41+
fetchSearchResults(true);
42+
}).toThrow(TypeError);
43+
});
44+
45+
xit('Returns an array of products when a query is given', done => {
46+
const expected = [
47+
{
48+
productUrl:
49+
'https://www.tiqets.com/en/barcelona-c66342/sagrada-familia-fast-track-p918256',
50+
image:
51+
'https://aws-tiqets-cdn.imgix.net/images/content/3ca6b020234e47448d46547ff3ac6b3f.jpg?auto=format&fit=crop&h=500&ixlib=python-1.1.2&q=70&w=500&s=04a6235ad28f4e3ce24d3db42d3dc3de',
52+
id: 918256,
53+
title: 'Sagrada Familia: Fast Track',
54+
price: 17.0,
55+
summary:
56+
"Make seeing the Sagrada Familia the first thing you do in Barcelona! The lines can be long, so join the many people who visited Barcelona's top attraction with our fast-track tickets and save yourself time and money.",
57+
},
58+
];
59+
60+
return fetchSearchResults('sagrada familia').then(results => {
61+
expect(results).toEqual(expected);
62+
done();
63+
});
64+
});
65+
});

0 commit comments

Comments
 (0)