mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-20 20:49:15 +00:00
fix
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
- [x] addKeyword: Opciones
|
- [x] addKeyword: Opciones
|
||||||
- [x] addAnswer: Opciones, media, buttons
|
- [x] addAnswer: Opciones, media, buttons
|
||||||
- [ ] Retornar SQL
|
- [ ] Retornar SQL
|
||||||
- [ ] Retornar JSON
|
- [ ] Retornar JSON (options)
|
||||||
- [ ] Recibir JSON
|
- [ ] Recibir JSON
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@@ -16,21 +16,19 @@ const addAnswer = (inCtx) => (answer, options) => {
|
|||||||
const ctxAnswer = () => {
|
const ctxAnswer = () => {
|
||||||
const ref = `ans_${generateRef()}`
|
const ref = `ans_${generateRef()}`
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
...getAnswerOptions(),
|
||||||
|
keyword: {},
|
||||||
|
}
|
||||||
|
|
||||||
const json = [].concat(inCtx.json).concat([
|
const json = [].concat(inCtx.json).concat([
|
||||||
{
|
{
|
||||||
ref,
|
ref,
|
||||||
keyword: lastCtx.ref,
|
keyword: lastCtx.ref,
|
||||||
answer,
|
answer,
|
||||||
|
options,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
/**
|
|
||||||
* Se guarda en db
|
|
||||||
*/
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
answer: getAnswerOptions(),
|
|
||||||
keyword: {},
|
|
||||||
}
|
|
||||||
|
|
||||||
return { ...lastCtx, ref, answer, json, options }
|
return { ...lastCtx, ref, answer, json, options }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const { generateRef } = require('../utils')
|
const { generateRef } = require('../utils')
|
||||||
const { addAnswer } = require('./addAnswer')
|
const { addAnswer } = require('./addAnswer')
|
||||||
|
const { toJson } = require('./toJson')
|
||||||
/**
|
/**
|
||||||
* addKeyword:
|
* addKeyword:
|
||||||
* Es necesario que genere id|hash
|
* Es necesario que genere id|hash
|
||||||
@@ -8,7 +9,7 @@ const { addAnswer } = require('./addAnswer')
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {*} message `string | string[]`
|
* @param {*} message `string | string[]`
|
||||||
* @param {*} options {sensitive:boolean} default
|
* @param {*} options {sensitive:boolean} default false
|
||||||
*/
|
*/
|
||||||
const addKeyword = (keyword, options) => {
|
const addKeyword = (keyword, options) => {
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +19,10 @@ const addKeyword = (keyword, options) => {
|
|||||||
*/
|
*/
|
||||||
const parseOptions = () => {
|
const parseOptions = () => {
|
||||||
const defaultProperties = {
|
const defaultProperties = {
|
||||||
sensitive: options?.sensitive ?? true,
|
sensitive:
|
||||||
|
typeof options?.sensitive === 'boolean'
|
||||||
|
? options?.sensitive
|
||||||
|
: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultProperties
|
return defaultProperties
|
||||||
@@ -31,6 +35,7 @@ const addKeyword = (keyword, options) => {
|
|||||||
{
|
{
|
||||||
ref,
|
ref,
|
||||||
keyword,
|
keyword,
|
||||||
|
options,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +51,7 @@ const addKeyword = (keyword, options) => {
|
|||||||
ctx,
|
ctx,
|
||||||
ref: ctx.ref,
|
ref: ctx.ref,
|
||||||
addAnswer: addAnswer(ctx),
|
addAnswer: addAnswer(ctx),
|
||||||
|
toJson: toJson(ctx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ test('Debere probar las addAnswer', () => {
|
|||||||
}
|
}
|
||||||
const MAIN_CTX = addKeyword('hola').addAnswer('etc', MOCK_OPT)
|
const MAIN_CTX = addKeyword('hola').addAnswer('etc', MOCK_OPT)
|
||||||
|
|
||||||
assert.is(MAIN_CTX.ctx.options.answer.media, MOCK_OPT.media)
|
assert.is(MAIN_CTX.ctx.options.media, MOCK_OPT.media)
|
||||||
assert.is(MAIN_CTX.ctx.options.answer.buttons.length, 1)
|
assert.is(MAIN_CTX.ctx.options.buttons.length, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Debere probar error las addAnswer', () => {
|
test('Debere probar error las addAnswer', () => {
|
||||||
@@ -71,8 +71,8 @@ test('Debere probar error las addAnswer', () => {
|
|||||||
}
|
}
|
||||||
const MAIN_CTX = addKeyword('hola').addAnswer('etc', MOCK_OPT)
|
const MAIN_CTX = addKeyword('hola').addAnswer('etc', MOCK_OPT)
|
||||||
|
|
||||||
assert.is(MAIN_CTX.ctx.options.answer.media, null)
|
assert.is(MAIN_CTX.ctx.options.media, null)
|
||||||
assert.is(MAIN_CTX.ctx.options.answer.buttons.length, 0)
|
assert.is(MAIN_CTX.ctx.options.buttons.length, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Obtener toJson', () => {
|
test('Obtener toJson', () => {
|
||||||
@@ -91,4 +91,25 @@ test('Obtener toJson', () => {
|
|||||||
assert.match(ctxC.ref, /^ans_/)
|
assert.match(ctxC.ref, /^ans_/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('addKeyword toJson con sensitive', () => {
|
||||||
|
const [ctxA] = addKeyword('hola').toJson()
|
||||||
|
assert.is(ctxA.options.sensitive, false)
|
||||||
|
const [ctxB] = addKeyword('hola', { sensitive: true }).toJson()
|
||||||
|
assert.is(ctxB.options.sensitive, true)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('addAnswer toJson con IMG', () => {
|
||||||
|
const [, ctxB, ctxC] = addKeyword('hola')
|
||||||
|
.addAnswer('bye!', {
|
||||||
|
media: 'http://mock.img/file-a.png',
|
||||||
|
})
|
||||||
|
.addAnswer('otro!', {
|
||||||
|
media: 'http://mock.img/file-b.png',
|
||||||
|
})
|
||||||
|
.toJson()
|
||||||
|
|
||||||
|
assert.is(ctxB.options.media, 'http://mock.img/file-a.png')
|
||||||
|
assert.is(ctxC.options.media, 'http://mock.img/file-b.png')
|
||||||
|
})
|
||||||
|
|
||||||
test.run()
|
test.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user