petfinder
Version:
Petfinder API module.
119 lines (105 loc) • 4.32 kB
JavaScript
describe('Petfinder', function () {
describe('Shelter', function() {
/***
* #findShelter
* retrieve a list of shelters near
***/
describe('#findShelter', function() {
it('should return 25 shelters near 90210', function(done) {
petfinder.findShelter('90210', {}, function(err, shelters) {
expect(shelters).to.be.instanceof(Array);
expect(shelters.length).to.be.equal(25);
done();
});
});
it('should return 25 shelters near "Beverly Hills, CA"', function(done) {
petfinder.findShelter('Beverly Hills, CA', {}, function(err, shelters) {
expect(shelters).to.be.instanceof(Array);
expect(shelters.length).to.be.equal(25);
done();
});
});
it('should error if no location is supplied.', function(done) {
petfinder.findShelter('', {}, function(err, shelters) {
expect(err).to.exist.and.be.instanceof(Error)
.and.have.property('message', 'Must supply location.');
done();
});
});
}); // end #findShelter
/***
* #getShelter
* retrieve shelter info
***/
describe('#getShelter', function() {
it('should return "The Kris Kelly Foundation" when given shelterId ="CA1117"', function(done) {
petfinder.getShelter('CA1117', {}, function(err, shelter) {
expect(shelter).to.exist.and.have.property('id', 'CA1117');
done();
});
});
it('should error if no shelterId given', function(done) {
petfinder.getShelter('', {}, function(err, shelter) {
expect(err).to.exist.and.be.instanceof(Error)
.and.have.property('message', 'Must supply shelter id.');
done();
});
});
}); // end #getShelter
/***
* #getPetsInShelter
***/
describe('#getPetsInShelter', function() {
it('should return pets that are in a given shelter', function(done) {
petfinder.getPetsInShelter('CA1117', {}, function(err, pets) {
expect(pets.length).to.be.above(1);
expect(pets[0]).to.have.property('shelterId', 'CA1117');
expect(pets[5]).to.have.property('shelterId', 'CA1117');
done();
});
});
it('should return only pet dogs that are in a given shelter', function(done) {
petfinder.getPetsInShelter('CA1117', {'animal':'dog'}, function(err, pets) {
expect(pets.length).to.be.above(1);
expect(pets[0]).to.have.property('animal', 'Dog');
expect(pets[2]).to.have.property('animal', 'Dog');
done();
});
});
it('should return error when given no shelter id', function(done) {
petfinder.getShelter('', {}, function(err, shelter) {
expect(err).to.exist.and.be.instanceof(Error)
.and.have.property('message', 'Must supply shelter id.');
done();
});
});
}); // end #getPetsInShelter
/***
* #getSheltersWithBreeds list all available breeds in a specific shelter
* replay is having issues skipping this test although code works
***/
describe('#getSheltersWithBreeds', function() {
it.skip('should return a list of shelters that have a specific breed', function(done) {
petfinder.getSheltersWithBreeds('cat', 'Tabby', {'count':10}, function(err, shelters) {
expect(shelters).to.be.instanceof(Array);
expect(shelters.length).to.be.above(1);
done();
});
});
it('should return error when given no animal type.', function(done) {
petfinder.getSheltersWithBreeds('', 'Tabby', {'count':10}, function(err, shelter) {
expect(err).to.exist.and.be.instanceof(Error)
.and.have.property('message', 'Must supply animal type.');
done();
});
});
it('should return error when given no breed', function(done) {
petfinder.getSheltersWithBreeds('cat', '', {'count':10}, function(err, shelter) {
expect(err).to.exist.and.be.instanceof(Error)
.and.have.property('message', 'Must supply breed.');
done();
});
});
});
}); // end Shelter
});