Skip to content

Commit 0fa73e5

Browse files
author
Kristján Oddsson
authored
Fix 392 (#393)
* fix: don't add a instance if there's no image * chore: re-record test mock data * chore(lint): fix lint errors
1 parent 80a663b commit 0fa73e5

File tree

3 files changed

+5717
-5657
lines changed

3 files changed

+5717
-5657
lines changed

endpoints/cinema/index.js

+21-23
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,27 @@ app.get('/cinema', (req, res) => {
5959
showtimes.push(theater)
6060
})
6161

62-
const urls = movie
63-
.find('img')
64-
.attr('src')
65-
.match(/\/images\/poster\/.+\.(jpg|jpeg|png)/ig) || []
66-
67-
const imgUrl = `http://kvikmyndir.is${urls[0]}`
68-
69-
const realeasedYear = movie
70-
.find('.mynd_titill_artal')
71-
.text()
72-
.replace('/[()]/g', '')
73-
74-
// Create an object of info
75-
// and add it to the 'results' array.
76-
obj.results.push({
77-
title: movie.find('.title').remove('.year').html().trim(),
78-
released: realeasedYear,
79-
restricted: null,
80-
imdb: movie.find('.imdbEinkunn').text().trim(),
81-
imdbLink: movie.find('.imdbEinkunn a').attr('href') ? movie.find('.imdbEinkunn a').attr('href').trim() : '',
82-
image: imgUrl,
83-
showtimes,
84-
})
62+
const src = movie.find('img').attr('src')
63+
if (src) {
64+
const urls = src.match(/\/images\/poster\/.+\.(jpg|jpeg|png)/ig) || []
65+
const imgUrl = `http://kvikmyndir.is${urls[0]}`
66+
const realeasedYear = movie
67+
.find('.mynd_titill_artal')
68+
.text()
69+
.replace('/[()]/g', '')
70+
71+
// Create an object of info
72+
// and add it to the 'results' array.
73+
obj.results.push({
74+
title: movie.find('.title').remove('.year').html().trim(),
75+
released: realeasedYear,
76+
restricted: null,
77+
imdb: movie.find('.imdbEinkunn').text().trim(),
78+
imdbLink: movie.find('.imdbEinkunn a').attr('href') ? movie.find('.imdbEinkunn a').attr('href').trim() : '',
79+
image: imgUrl,
80+
showtimes,
81+
})
82+
}
8583
})
8684

8785
return res.cache().json(obj)
+11-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
describe('cinema', () => { })
1+
const request = require('request')
2+
const helpers = require('../../../lib/test_helpers')
3+
4+
describe('/cinema', () => {
5+
it('should return an array of objects containing correct fields', (done) => {
6+
const fieldsToCheckFor = ['title', 'released', 'restricted', 'imdb', 'imdbLink', 'image', 'showtimes']
7+
const params = helpers.testRequestParams('/cinema')
8+
const resultHandler = helpers.testRequestHandlerForFields(done, fieldsToCheckFor)
9+
request.get(params, resultHandler)
10+
})
11+
})
212
describe('cinema theaters', () => { })

0 commit comments

Comments
 (0)