Skip to content

Commit

Permalink
Merge 4ccf596 into 8f00ce9
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle committed Apr 22, 2019
2 parents 8f00ce9 + 4ccf596 commit 06af3c1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Expand Up @@ -60,6 +60,15 @@ epflMenuApi.findMenu({
}).catch(function(err) {
console.log(err);
});

epflMenuApi.findResto().then(function(restos) {
console.log(restos[0].restoName); //=> 'L'Esplanade'
console.log(restos[0].restoID); //=> '32'
console.log(restos[0].type); //=> 'self-service'
console.log(restos[0].plan); //=> 'CO160'
}).catch(function(err) {
console.log(err);
});
```

API
Expand Down Expand Up @@ -121,7 +130,13 @@ Pasta: `Pâtes`<br>
Pizza: `Pizza`<br>
Thai: `Thaï`<br>
Vegan: `Végétalien`<br>
Vegetarian: `Végétarien`<br>
Vegetarian: `Végétarien`

### .findResto()

Type: `function`

Returns a Promise with a list of restaurant as parameter.

See also
--------
Expand Down
10 changes: 10 additions & 0 deletions src/index.js
Expand Up @@ -6,6 +6,7 @@
const got = require('got');

const MENUS_URL = 'https://menus.epfl.ch/cgi-bin/ws-getMenus';
const RESTOS_URL = 'https://menus.epfl.ch/cgi-bin/ws-getRestos';

const DEFAULT_MENUS_OPTIONS = {
language: 'en',
Expand Down Expand Up @@ -39,3 +40,12 @@ exports.findMenu = (opts = DEFAULT_MENUS_OPTIONS) => {
}).catch((err) => reject(err));
});
};

exports.findResto = () => {
return new Promise((resolve, reject) => {
got(RESTOS_URL).then((response) => {
const data = JSON.parse(response.body);
resolve(data.restos);
}).catch((err) => reject(err));
});
};
30 changes: 30 additions & 0 deletions test/test-findResto.js
@@ -0,0 +1,30 @@
/*
* (c) William Belle, 2019.
* See the LICENSE file for more details.
*/

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

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

describe('epfl-menu-api findResto', function () {
this.timeout(10000);

it('should contains at least 5 restos', function () {
return epflMenuApi.findResto().then((restos) => {
var enoughRestos = Object.keys(restos).length > 4;
enoughRestos.should.equal(true);
});
});

it('should fail with a wrong service url', (done) => {
let epflMenuApiMock = rewire('../src/index.js');
epflMenuApiMock.__set__('RESTOS_URL', 'foobar');
let result = epflMenuApiMock.findResto();
result.then((response) => {
should.fail();
done();
}).catch((reason) => done());
});
});

0 comments on commit 06af3c1

Please sign in to comment.