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