Skip to content

Commit

Permalink
Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle committed Nov 4, 2021
1 parent ac0b924 commit 5c42cb3
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions test/test-find.js
Expand Up @@ -5,38 +5,38 @@
* 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 find', function () {
this.timeout(10000);

// Sadly...
it('shouldn\'t find Taylor Swift', () => {
return epflPeopleApi.find(
'Taylor Swift',
'en'
).then((res) => res.length.should.equal(0));
it('shouldn\'t find Taylor Swift', async () => {
const list = await epflPeopleApi.find('Taylor Swift', 'en');
assert.equal(list.length, 0);
});

it('should find Lindo Duratti', () => {
return epflPeopleApi.find(
'Lindo Duratti'
).then((res) => {
res.length.should.equal(1);
res[0].sciper.should.equal('128871');
});
it('should find Lindo Duratti', async () => {
const list = await epflPeopleApi.find('Lindo Duratti');
assert.equal(list.length, 1);
assert.equal(list[0].sciper, '128871');
});

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

const getException = async () => {
await epflPeopleApiMock.find('Lindo', 'en');
};
return assert.isRejected(getException(), TypeError).then((err) => {
assert.equal(err.code, 'ERR_INVALID_URL');
assert.include(err.message, 'Invalid URL');
});
});
});

0 comments on commit 5c42cb3

Please sign in to comment.