-
-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(release): 0.1.21
- Loading branch information
Showing
97 changed files
with
659 additions
and
1,008 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no -- commitlint --edit | ||
npm run lint:fix && npx --no -- commitlint --edit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
packages/**/lib | ||
packages/docs/*.json | ||
packages/docs/ | ||
**/.git | ||
**/.svn | ||
**/.hg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"recommendations": ["xyc.vscode-mdx-preview"] | ||
"recommendations": ["xyc.vscode-mdx-preview", "vivaxy.vscode-conventional-commits", "mhutchie.git-graph"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,7 @@ const { test } = require('uvu') | |
const assert = require('uvu/assert') | ||
const MOCK_DB = require('../packages/database/src/mock') | ||
const PROVIDER_DB = require('../packages/provider/src/mock') | ||
const { | ||
addKeyword, | ||
createBot, | ||
createFlow, | ||
createProvider, | ||
} = require('../packages/bot/index') | ||
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index') | ||
|
||
/** | ||
* Falsear peticion async | ||
|
@@ -21,11 +16,7 @@ const fakeHTTP = async (fakeData = []) => { | |
} | ||
|
||
test(`[Caso - 05] Continuar Flujo (continueFlow)`, async () => { | ||
const MOCK_VALUES = [ | ||
'¿CUal es tu email?', | ||
'Continuamos....', | ||
'¿Cual es tu edad?', | ||
] | ||
const MOCK_VALUES = ['¿CUal es tu email?', 'Continuamos....', '¿Cual es tu edad?'] | ||
const provider = createProvider(PROVIDER_DB) | ||
const database = new MOCK_DB() | ||
|
||
|
@@ -39,26 +30,20 @@ test(`[Caso - 05] Continuar Flujo (continueFlow)`, async () => { | |
const validation = ctx.body.includes('@') | ||
|
||
if (validation) { | ||
const getDataFromApi = await fakeHTTP([ | ||
'Gracias por tu email se ha validado de manera correcta', | ||
]) | ||
const getDataFromApi = await fakeHTTP(['Gracias por tu email se ha validado de manera correcta']) | ||
return flowDynamic(getDataFromApi) | ||
} | ||
return fallBack(validation) | ||
} | ||
) | ||
.addAnswer(MOCK_VALUES[1]) | ||
.addAnswer( | ||
MOCK_VALUES[2], | ||
{ capture: true }, | ||
async (ctx, { flowDynamic, fallBack }) => { | ||
if (ctx.body !== '18') { | ||
await delay(50) | ||
return fallBack(false, 'Ups creo que no eres mayor de edad') | ||
} | ||
return flowDynamic('Bien tu edad es correcta!') | ||
.addAnswer(MOCK_VALUES[2], { capture: true }, async (ctx, { flowDynamic, fallBack }) => { | ||
if (ctx.body !== '18') { | ||
await delay(50) | ||
return fallBack(false, 'Ups creo que no eres mayor de edad') | ||
} | ||
) | ||
return flowDynamic('Bien tu edad es correcta!') | ||
}) | ||
.addAnswer('Puedes pasar') | ||
|
||
createBot({ | ||
|
@@ -98,10 +83,7 @@ test(`[Caso - 05] Continuar Flujo (continueFlow)`, async () => { | |
assert.is('this is not email value', getHistory[1]) | ||
assert.is(MOCK_VALUES[0], getHistory[2]) | ||
assert.is('[email protected]', getHistory[3]) | ||
assert.is( | ||
'1 Gracias por tu email se ha validado de manera correcta', | ||
getHistory[4] | ||
) | ||
assert.is('1 Gracias por tu email se ha validado de manera correcta', getHistory[4]) | ||
assert.is(MOCK_VALUES[1], getHistory[5]) | ||
assert.is(MOCK_VALUES[2], getHistory[6]) | ||
assert.is('20', getHistory[7]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const { test } = require('uvu') | ||
const assert = require('uvu/assert') | ||
const MOCK_DB = require('../packages/database/src/mock') | ||
const PROVIDER_DB = require('../packages/provider/src/mock') | ||
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index') | ||
|
||
/** | ||
* Falsear peticion async | ||
* @param {*} fakeData | ||
* @returns | ||
*/ | ||
const fakeHTTP = async (fakeData = []) => { | ||
await delay(5) | ||
const data = fakeData.map((u, i) => ({ body: `${i + 1} ${u}` })) | ||
return Promise.resolve(data) | ||
} | ||
|
||
let STATE_APP = {} | ||
|
||
test(`[Caso - 07] Retornar estado`, async () => { | ||
const MOCK_VALUES = ['¿Cual es tu nombre?', '¿Cual es tu edad?', 'Tu datos son:'] | ||
const provider = createProvider(PROVIDER_DB) | ||
const database = new MOCK_DB() | ||
|
||
const flujoPrincipal = addKeyword(['hola']) | ||
.addAnswer( | ||
MOCK_VALUES[0], | ||
{ | ||
capture: true, | ||
}, | ||
async (ctx, { flowDynamic, fallBack }) => { | ||
STATE_APP[ctx.from] = { ...STATE_APP[ctx.from], name: ctx.body } | ||
|
||
flowDynamic('Gracias por tu nombre!') | ||
} | ||
) | ||
.addAnswer( | ||
MOCK_VALUES[1], | ||
{ | ||
capture: true, | ||
}, | ||
async (ctx, { flowDynamic, endFlow }) => { | ||
STATE_APP[ctx.from] = { ...STATE_APP[ctx.from], age: ctx.body } | ||
|
||
await flowDynamic('Gracias por tu edad!') | ||
} | ||
) | ||
.addAnswer(MOCK_VALUES[2], null, async (ctx, { flowDynamic }) => { | ||
flowDynamic(`Nombre: ${STATE_APP[ctx.from].name} Edad: ${STATE_APP[ctx.from].age}`) | ||
}) | ||
.addAnswer('🤖🤖 Gracias por tu participacion') | ||
|
||
createBot({ | ||
database, | ||
flow: createFlow([flujoPrincipal]), | ||
provider, | ||
}) | ||
|
||
provider.delaySendMessage(0, 'message', { | ||
from: '000', | ||
body: 'hola', | ||
}) | ||
|
||
provider.delaySendMessage(20, 'message', { | ||
from: '000', | ||
body: 'Leifer', | ||
}) | ||
|
||
provider.delaySendMessage(40, 'message', { | ||
from: '000', | ||
body: '90', | ||
}) | ||
|
||
await delay(1200) | ||
const getHistory = database.listHistory.map((i) => i.answer) | ||
assert.is(MOCK_VALUES[0], getHistory[0]) | ||
assert.is('Leifer', getHistory[1]) | ||
assert.is('Gracias por tu nombre!', getHistory[2]) | ||
assert.is('¿Cual es tu edad?', getHistory[3]) | ||
assert.is('90', getHistory[4]) | ||
assert.is('Gracias por tu edad!', getHistory[5]) | ||
assert.is('Tu datos son:', getHistory[6]) | ||
assert.is('Nombre: Leifer Edad: 90', getHistory[7]) | ||
assert.is('🤖🤖 Gracias por tu participacion', getHistory[8]) | ||
assert.is(undefined, getHistory[9]) | ||
}) | ||
|
||
test.run() | ||
|
||
function delay(ms) { | ||
return new Promise((res) => setTimeout(res, ms)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { test } = require('uvu') | ||
const assert = require('uvu/assert') | ||
const MOCK_DB = require('../packages/database/src/mock') | ||
const PROVIDER_DB = require('../packages/provider/src/mock') | ||
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index') | ||
|
||
test(`[Caso - 08] Regular expression on keyword`, async () => { | ||
const provider = createProvider(PROVIDER_DB) | ||
const database = new MOCK_DB() | ||
|
||
const REGEX_CREDIT_NUMBER = `/(^4[0-9]{12}(?:[0-9]{3})?$)|(^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$)|(3[47][0-9]{13})|(^3(?:0[0-5]|[68][0-9])[0-9]{11}$)|(^6(?:011|5[0-9]{2})[0-9]{12}$)|(^(?:2131|1800|35\d{3})\d{11}$)/gm` | ||
const flujoPrincipal = addKeyword(REGEX_CREDIT_NUMBER, { regex: true }) | ||
.addAnswer(`Gracias por proporcionar un numero de tarjeta valido`) | ||
.addAnswer('Fin!') | ||
|
||
createBot({ | ||
database, | ||
flow: createFlow([flujoPrincipal]), | ||
provider, | ||
}) | ||
|
||
provider.delaySendMessage(0, 'message', { | ||
from: '000', | ||
body: 'hola', | ||
}) | ||
|
||
provider.delaySendMessage(20, 'message', { | ||
from: '000', | ||
body: '374245455400126', | ||
}) | ||
|
||
await delay(40) | ||
const getHistory = database.listHistory.map((i) => i.answer) | ||
assert.is('Gracias por proporcionar un numero de tarjeta valido', getHistory[0]) | ||
assert.is('Fin!', getHistory[1]) | ||
assert.is(undefined, getHistory[2]) | ||
}) | ||
|
||
test.run() | ||
|
||
function delay(ms) { | ||
return new Promise((res) => setTimeout(res, ms)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { test } = require('uvu') | ||
const assert = require('uvu/assert') | ||
const MOCK_DB = require('../packages/database/src/mock') | ||
const PROVIDER_MOCK = require('../packages/provider/src/mock') | ||
const { addKeyword, createBot, createFlow, createProvider } = require('../packages/bot/index') | ||
|
||
let PROVIDER = undefined | ||
|
||
test(`[Caso - 09] Check provider WS`, async () => { | ||
const [VALUE_A, VALUE_B] = ['hola', 'buenas'] | ||
|
||
const flow = addKeyword(VALUE_A).addAnswer(VALUE_B, null, async (_, { provider }) => { | ||
PROVIDER = provider | ||
}) | ||
const provider = createProvider(PROVIDER_MOCK) | ||
const database = new MOCK_DB() | ||
|
||
createBot({ | ||
database, | ||
flow: createFlow([flow]), | ||
provider, | ||
}) | ||
|
||
provider.delaySendMessage(100, 'message', { | ||
from: '000', | ||
body: VALUE_A, | ||
}) | ||
|
||
await delay(100) | ||
|
||
const prevMsg = database.getPrevByNumber('000') | ||
|
||
assert.is(prevMsg.answer, VALUE_B) | ||
assert.is(typeof PROVIDER.sendMessage, 'function') | ||
}) | ||
|
||
test.run() | ||
|
||
function delay(ms) { | ||
return new Promise((res) => setTimeout(res, ms)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.