Skip to content

Commit

Permalink
Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle committed Nov 5, 2021
1 parent 06b629c commit 4ed573d
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions test/test-photo.js
Expand Up @@ -5,48 +5,59 @@
* See the LICENSE file for more details.
*/

const should = require('chai').should();
const chai = require('chai');
const rewire = require('rewire');

const assert = chai.assert;
chai.use(require('chai-as-promised'));

const epflPeopleApi = require('../src/index.js');

describe('epfl-people-api hasPhoto', function () {
this.timeout(10000);

it('should throw an exception with sciper xxx', () => {
return epflPeopleApi.hasPhoto('xxx').then(() => {
}).catch((err) => err.message.should.equal('Expected a sciper'));
const getException = async () => {
await epflPeopleApi.hasPhoto('xxx', 'en');
};
return assert.isRejected(getException(), TypeError).then((err) => {
assert.equal(err.message, 'Expected a sciper');
});
});

it('should throw an exception with sciper 69', () => {
return epflPeopleApi.hasPhoto(69).then(() => {
}).catch((err) => err.message.should.equal('Expected a sciper'));
const getException = async () => {
await epflPeopleApi.hasPhoto(69);
};
return assert.isRejected(getException(), TypeError).then((err) => {
assert.equal(err.message, 'Expected a sciper');
});
});

it('should throw an exception with sciper 1000051', () => {
return epflPeopleApi.hasPhoto(1000051).then(() => {
}).catch((err) => err.message.should.equal('Expected a sciper'));
const getException = async () => {
await epflPeopleApi.hasPhoto(1000051);
};
return assert.isRejected(getException(), TypeError).then((err) => {
assert.equal(err.message, 'Expected a sciper');
});
});

it('should fail with a wrong service url', (done) => {
it('should fail with a wrong service url', async () => {
const epflPeopleApiMock = rewire('../src/index.js');
epflPeopleApiMock.__set__('PHOTO_URL', 'foobar');
const result = epflPeopleApiMock.hasPhoto(280556, 'en');
result.then((response) => {
should.fail();
done();
}).catch((reason) => done());

const photo = await epflPeopleApiMock.hasPhoto(280556, 'en');
assert.equal(photo, false);
});

it('shouldn\'t find photo of Lindo Duratti', () => {
return epflPeopleApi.hasPhoto(128871).then((hasPhoto) => {
hasPhoto.should.equal(false);
});
it('shouldn\'t find photo of Lindo Duratti', async () => {
const photo = await epflPeopleApi.hasPhoto(128871);
assert.equal(photo, false);
});

it('should find photo of Anastasiia Oryshchuk', () => {
return epflPeopleApi.hasPhoto(278890).then((hasPhoto) => {
hasPhoto.should.equal(true);
});
it('should find photo of Anastasiia Oryshchuk', async () => {
const photo = await epflPeopleApi.hasPhoto(278890);
assert.equal(photo, true);
});
});

0 comments on commit 4ed573d

Please sign in to comment.