70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
|
const test = require("tap").test;
|
||
|
|
||
|
const util = require("../src/util");
|
||
|
|
||
|
test("util", (t) => {
|
||
|
t.plan(4);
|
||
|
|
||
|
t.test("keyboard from single digit reply options", (t) => {
|
||
|
const rawText = `CON Balance 80.0 GFT
|
||
|
1. Send
|
||
|
2. My Sarafu
|
||
|
3. My Account
|
||
|
4. Help`;
|
||
|
|
||
|
const expectKeyboard = [["1"], ["2"], ["3"], ["4"]];
|
||
|
const output = util.createKeyboard(rawText);
|
||
|
|
||
|
t.same(output, expectKeyboard);
|
||
|
t.end();
|
||
|
});
|
||
|
|
||
|
t.test("keyboard from multi digit reply options", (t) => {
|
||
|
const rawText = `CON For assistance call 0757628885
|
||
|
00. Back
|
||
|
99. Exit`;
|
||
|
|
||
|
const expectKeyboard = [["00"], ["99"]];
|
||
|
const output = util.createKeyboard(rawText);
|
||
|
|
||
|
t.same(output, expectKeyboard);
|
||
|
t.end();
|
||
|
});
|
||
|
|
||
|
t.test("keyboard from mixed count digit reply options", (t) => {
|
||
|
const rawText = `CON For assistance call 0757628885
|
||
|
1. Option
|
||
|
00. Back
|
||
|
99. Exit`;
|
||
|
|
||
|
const expectKeyboard = [["1"], ["00"], ["99"]];
|
||
|
const output = util.createKeyboard(rawText);
|
||
|
|
||
|
t.same(output, expectKeyboard);
|
||
|
t.end();
|
||
|
});
|
||
|
|
||
|
t.test("code, text and keyboard from raw response", (t) => {
|
||
|
const rawText = `CON Balance 80.0 GFT
|
||
|
1. Send
|
||
|
2. My Sarafu
|
||
|
3. My Account
|
||
|
4. Help`;
|
||
|
|
||
|
const expectKeyboard = [["1"], ["2"], ["3"], ["4"]];
|
||
|
const expect = {
|
||
|
code: "CON",
|
||
|
text: `Balance 80.0 GFT
|
||
|
1. Send
|
||
|
2. My Sarafu
|
||
|
3. My Account
|
||
|
4. Help`,
|
||
|
keyboard: expectKeyboard,
|
||
|
};
|
||
|
const output = util.parseUssdResponse(rawText);
|
||
|
|
||
|
t.same(output, expect);
|
||
|
t.end();
|
||
|
});
|
||
|
});
|