Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Merge 20e76d3 into 79725c4
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgdev committed May 17, 2016
2 parents 79725c4 + 20e76d3 commit 62f9bff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Projection.prototype.findTheaters = function(near, options, callback) {
}

var imdbId = null;
if (m.find('.info a').attr('href')) {
if (m.find('.info a[href*=imdb]') && m.find('.info a[href*=imdb]').attr('href')) {
var match = m.find('.info a[href*=imdb]').attr('href').match(/title\/(.*)\//);
if (match)
imdbId = match[1];
Expand Down Expand Up @@ -293,4 +293,4 @@ function formatShowtimes(showtimes) {
// console.log(movie);
// });

module.exports = Projection;
module.exports = Projection;
24 changes: 19 additions & 5 deletions test/projection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ describe('Projection', function() {
});
})

it('should return an error if no theaters are found', function(done) {
p.findTheaters('Innexistant Place', {}, function(err, theaters) {
assert.notEqual(err, null);
done();
});
})

it('should return theaters more quickly the second time', function(done) {
var start = new Date().getTime();
p.findTheaters('Montreal', {}, function(err, theaters) {
Expand All @@ -76,7 +83,7 @@ describe('Projection', function() {

describe('.findMovie()', function() {
it('should find a movie\'s showtimes by town', function(done){
p.findMovie('Sherbrooke', 'Ted 2', {}, function(err, movie){
p.findMovie('Sherbrooke', 'Captain America: Civil War', {}, function(err, movie){
assert.equal(err, null);
assert(movie);
assert(movie.theaters.length > 0);
Expand All @@ -87,7 +94,7 @@ describe('Projection', function() {
})

it('should find a movie\'s showtimes by lat/long', function(done){
p.findMovie('45.3838273,-71.8958539', 'Ted 2', {}, function(err, movie){
p.findMovie('45.3838273,-71.8958539', 'Captain America: Civil War', {}, function(err, movie){
assert.equal(err, null);
assert(movie);
assert(movie.theaters.length > 0);
Expand Down Expand Up @@ -120,12 +127,19 @@ describe('Projection', function() {
});
})

it('should return an error if the movie is not found', function(done) {
p.findMovie('Montreal', 'Random movie name that does not exist', {}, function(err, theaters) {
assert.notEqual(err, null);
done();
});
})

it('should return a movie more quickly the second time', function(done) {
var start = new Date().getTime();
p.findMovie('Montreal', 'Mad Max', {}, function(err, theaters) {
p.findMovie('Montreal', 'Captain America: Civil War', {}, function(err, theaters) {
var t1 = new Date().getTime() - start;
start = new Date().getTime();
p.findMovie('Montreal', 'Mad Max', {}, function(err, theaters) {
p.findMovie('Montreal', 'Captain America: Civil War', {}, function(err, theaters) {
var t2 = new Date().getTime() - start;
assert(t1 >= t2); // ~500ms to ~10ms
assert(t2 < 100); // Expect cache to take lesser than 100ms
Expand All @@ -135,4 +149,4 @@ describe('Projection', function() {
})
})

})
})

0 comments on commit 62f9bff

Please sign in to comment.