add answer options

This commit is contained in:
Leifer Mendez
2022-11-02 20:15:14 +01:00
parent c05470c045
commit 5fa6660afd
3 changed files with 40 additions and 7 deletions

View File

@@ -11,7 +11,7 @@
- [x] addKeyword
- [x] addAnswer
- [x] addKeyword: Opciones
- [ ] addAnswer: Opciones
- [x] addAnswer: Opciones, media, buttons
- [ ] Retornar SQL
- [ ] Retornar JSON
- [ ] Recibir JSON

View File

@@ -1,6 +1,17 @@
const { generateRef } = require('../utils')
/**
*
* @param answer string
* @param options {media:string, buttons:[]}
* @returns
*/
const addAnswer = (inCtx) => (answer, options) => {
const getAnswerOptions = () => ({
media: typeof options?.media === 'string' ? `${options?.media}` : null,
buttons: Array.isArray(options?.buttons) ? options.buttons : [],
})
const lastCtx = inCtx.hasOwnProperty('ctx') ? inCtx.ctx : inCtx
const ctxAnswer = () => {
const ref = generateRef()
@@ -8,7 +19,12 @@ const addAnswer = (inCtx) => (answer, options) => {
* Se guarda en db
*/
return { ...lastCtx, ref, answer }
const options = {
answer: getAnswerOptions(),
keyword: {},
}
return { ...lastCtx, ref, answer, options }
}
const ctx = ctxAnswer()
@@ -21,8 +37,3 @@ const addAnswer = (inCtx) => (answer, options) => {
}
module.exports = { addAnswer }
// await inout
// .addKeyword('hola')
// .addAnswer('Bienvenido a tu tienda 🥲')
// .addAnswer('escribe *catalogo* o *ofertas*')

View File

@@ -53,4 +53,26 @@ test('Debere probar las poptions', () => {
assert.is(MAIN_CTX.ctx.options.sensitive, false)
})
test('Debere probar las addAnswer', () => {
const MOCK_OPT = {
media: 'http://image.mock/mock.png',
buttons: [1],
}
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)
})
test('Debere probar error las addAnswer', () => {
const MOCK_OPT = {
media: { a: 1, b: [] },
buttons: 'test',
}
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)
})
test.run()