114 lines
2.9 KiB
JavaScript
114 lines
2.9 KiB
JavaScript
const test = require("tap").test;
|
|
const rangi = require("rangi");
|
|
|
|
const lib = require("../../lib");
|
|
const conf = require("../../config");
|
|
|
|
test("Reset Pin", async (t) => {
|
|
t.before((t) => {
|
|
if (!process.env.CURRENT_PIN || !process.env.NEW_PIN) {
|
|
t.bailout("ENV not set");
|
|
}
|
|
});
|
|
|
|
const sessionId = lib.newSession();
|
|
const currentPin = process.env.CURRENT_PIN;
|
|
const newPin = process.env.NEW_PIN;
|
|
|
|
t.test("Display menu and Sarafu balance", async (t) => {
|
|
await lib.wait(conf.test.waitNextMenu);
|
|
const r = await lib.ussdClient(conf.user.ussdPhone, sessionId);
|
|
console.log(rangi.cyan(r.text));
|
|
|
|
t.equal(r.code, "CON");
|
|
t.match(r.text, /Balance/g);
|
|
t.end();
|
|
});
|
|
|
|
t.test("Go to My Accont menu", async (t) => {
|
|
await lib.wait(conf.test.waitNextMenu);
|
|
const r = await lib.ussdClient(conf.user.ussdPhone, sessionId, "3");
|
|
console.log(rangi.cyan(r.text));
|
|
|
|
t.equal(r.code, "CON");
|
|
t.match(r.text, /PIN options/g);
|
|
t.end();
|
|
});
|
|
|
|
t.test("Go to Pin options", async (t) => {
|
|
await lib.wait(conf.test.waitNextMenu);
|
|
const r = await lib.ussdClient(conf.user.ussdPhone, sessionId, "3*5");
|
|
console.log(rangi.cyan(r.text));
|
|
|
|
t.equal(r.code, "CON");
|
|
t.match(r.text, /Change my PIN/g);
|
|
t.end();
|
|
});
|
|
|
|
t.test("Start Pin Change", async (t) => {
|
|
await lib.wait(conf.test.waitNextMenu);
|
|
const r = await lib.ussdClient(conf.user.ussdPhone, sessionId, "3*5*1");
|
|
console.log(rangi.cyan(r.text));
|
|
|
|
t.equal(r.code, "CON");
|
|
t.match(r.text, /Enter current PIN/g);
|
|
t.end();
|
|
});
|
|
|
|
t.test("Enter current Pin", async (t) => {
|
|
await lib.wait(conf.test.waitNextMenu);
|
|
const r = await lib.ussdClient(
|
|
conf.user.ussdPhone,
|
|
sessionId,
|
|
`3*5*1*${currentPin}`
|
|
);
|
|
console.log(rangi.cyan(r.text));
|
|
|
|
t.equal(r.code, "CON");
|
|
t.match(r.text, /new four number PIN/g);
|
|
t.end();
|
|
});
|
|
|
|
t.test("Enter new Pin", async (t) => {
|
|
await lib.wait(conf.test.waitNextMenu);
|
|
const r = await lib.ussdClient(
|
|
conf.user.ussdPhone,
|
|
sessionId,
|
|
`3*5*1*${currentPin}*${newPin}`
|
|
);
|
|
console.log(rangi.cyan(r.text));
|
|
|
|
t.equal(r.code, "CON");
|
|
t.match(r.text, /new four number PIN again/g);
|
|
t.end();
|
|
});
|
|
|
|
t.test("Enter new Pin agin", async (t) => {
|
|
await lib.wait(conf.test.waitNextMenu);
|
|
const r = await lib.ussdClient(
|
|
conf.user.ussdPhone,
|
|
sessionId,
|
|
`3*5*1*${currentPin}*${newPin}*${newPin}`
|
|
);
|
|
console.log(rangi.cyan(r.text));
|
|
|
|
t.equal(r.code, "CON");
|
|
t.match(r.text, /Your request has been sent/g);
|
|
t.end();
|
|
});
|
|
|
|
t.test("Exit", async (t) => {
|
|
await lib.wait(conf.test.waitNextMenu);
|
|
const r = await lib.ussdClient(
|
|
conf.user.ussdPhone,
|
|
sessionId,
|
|
`3*5*1*${currentPin}*${newPin}*${newPin}*99`
|
|
);
|
|
console.log(rangi.cyan(r.text));
|
|
|
|
t.equal(r.code, "END");
|
|
t.match(r.text, /Thank/g);
|
|
t.end();
|
|
});
|
|
});
|