Skip to content

GleytonLima/simple-rule-notification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

798d167 · Dec 25, 2021

History

13 Commits
Dec 25, 2021
Dec 25, 2021
Dec 14, 2021
Dec 14, 2021
Dec 25, 2021
Dec 14, 2021
Dec 25, 2021
Dec 25, 2021
Dec 25, 2021
Dec 14, 2021
Dec 14, 2021

Repository files navigation

Node.js CI Coverage Status Mutation testing badge

Simple Rule Notification

Interpret some simples rules in json to generate notifications

About The Project

A way for persist some configurable rules for use in some data in frontend.

Usage

Install the package from npm:

npm i simple-rule-notification

Import the package:

const srn = require("simple-rule-notification");

Retrieve the following rules from backend:

const operacaoGrupo = {
    id: 1,
    acaoEnum: "CRIAR_REGISTRO_ATIVIDADE_NOTIFICACAO",
    operacaoRaiz: {
        id: 2,
        nomeCampo: "ocorrencia",
        comparadorEnum: "IGUAL",
        valor: "valor_esperado",
        proximaOperacao: null,
        operadorProximaOperacao: null,
    },
    tituloPadrao: "Ocorrência no Campo",
    mensagemPadrao: "O campo ocorrência foi preenchido.",
    tipoMensagem: "INFO",
    quantidadeDiasEntreDatasChave: null,
    respostasPadrao: null,
};

Then build a strategy and execute it, passing the data:

const data = {
    respostas: {
        ocorrencia: "valor_esperado",
    },
};
const applicableRule = srn.buildAcaoStrategy(operacaoGrupo, data).executar();

In this case the return will be:

{ "tipo": "CRIAR_REGISTRO_ATIVIDADE_NOTIFICACAO" }

If the entry has the following value:

const data = {
    respostas: {
        ocorrencia: "valor_nao_esperado",
    },
};

The return will be:

null;

Unit tests - Jest

npm test
--------------|---------|----------|---------|---------|-------------------
File          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------|---------|----------|---------|---------|-------------------
All files     |     100 |      100 |     100 |     100 |
 functions.ts |     100 |      100 |     100 |     100 |
 index.ts     |     100 |      100 |     100 |     100 |
--------------|---------|----------|---------|---------|-------------------

Mutation Test - Striker

npx stryker run
--------------|---------|----------|-----------|------------|----------|---------|
File          | % score | # killed | # timeout | # survived | # no cov | # error |
--------------|---------|----------|-----------|------------|----------|---------|
All files     |  100.00 |      101 |         0 |          0 |        0 |       8 |
 functions.ts |  100.00 |      101 |         0 |          0 |        0 |       8 |
--------------|---------|----------|-----------|------------|----------|---------|

About

Simple rule notification

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published