Skip to content

Commit da872c8

Browse files
committed
Clean up
1 parent 68eb279 commit da872c8

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

lib/parse-result.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module.exports = function (options) {
1515
throw new errors.Forbidden('`parseI18nResult` can only be run on a `after` hook.')
1616
}
1717

18-
if (!options.language) options.language = 'en'
19-
2018
context.result = parseResult(context.result, options.language, options.fields)
2119

2220
return context
@@ -35,14 +33,14 @@ function parseResult (result, language, props = []) {
3533
return null
3634
}
3735

38-
let data = [].concat(result.data || result)
36+
const data = [].concat(result.data || result)
3937

4038
data.forEach((item, index) => {
4139
Object.keys(item)
4240
.forEach(key => {
4341
if (props.includes(key)) {
4442
// Find data of specified language, otherwise fallback to default
45-
let res = data[index][key][language] || data[index][key][defaults.language]
43+
const res = data[index][key][language] || data[index][key][defaults.language]
4644
if (res || res === '') {
4745
Object.assign(data[index], { [key]: res })
4846
}

test/parse-result.test.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,6 @@ const makeHook = require('../lib/parse-result')
44
const parseResult = makeHook({ fields: ['title', 'description'] })
55

66
describe('Result', function () {
7-
it('empty description string', function () {
8-
const context = {
9-
type: 'after',
10-
result: {
11-
data: [
12-
{
13-
title: {
14-
en: 'another title'
15-
},
16-
description: {
17-
en: ''
18-
}
19-
}
20-
]
21-
}
22-
}
23-
24-
makeHook({ fields: ['title', 'description'], language: 'en' })(context)
25-
const { result } = context
26-
27-
assert.strictEqual(result.data[0].title, 'another title', 'we have converted the title')
28-
assert.strictEqual(result.data[0].description, '', 'we have the correct description')
29-
})
30-
317
it('transforms the result as object', function () {
328
const context = {
339
type: 'after',
@@ -64,8 +40,8 @@ describe('Result', function () {
6440

6541
parseResult(context)
6642
const { result } = context
67-
assert.strictEqual(result.data[0].title, '', 'Output not matched !!!! ??? error')
68-
assert.strictEqual(result.data[0].description, '', 'Empty str')
43+
assert.strictEqual(result.data[0].title, '', 'Space not parsed correctly')
44+
assert.strictEqual(result.data[0].description, '', 'Space not parsed correctly')
6945
})
7046

7147
it('ignores already transformed result', function () {

0 commit comments

Comments
 (0)