Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
chore: return default stats if no locales passed
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler committed Aug 30, 2020
1 parent 1db6ead commit 56eaa93
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/routes/stats.js
Expand Up @@ -14,6 +14,14 @@ router.get('/', async (req, res) => {
const queryLocales = req.query.locales || '';
const locales = queryLocales.split(',');

if (locales.length === 1 && !locales[0]) {
return res.json({
all: 0,
user: 0,
userUnreviewed: 0,
});
}

debug('GET_STATS', sessionUserId);

try {
Expand Down
14 changes: 14 additions & 0 deletions server/tests/routes/stats.test.js
Expand Up @@ -49,6 +49,20 @@ test.serial('should get stats', async (t) => {
});
});

test.serial('should return default stats if no locale passed', async (t) => {
const response = await request(app)
.get('/sentence-collector/stats?locales=');

t.log(response);

t.is(response.status, 200);
t.deepEqual(response.body, {
all: 0,
user: 0,
userUnreviewed: 0,
});
});

test.serial('should pass on error message', async (t) => {
sentences.getUserAddedSentencesPerLocale.rejects(new Error('nope'));

Expand Down

0 comments on commit 56eaa93

Please sign in to comment.