ussd-tg-proxy/tests/request.test.js

32 lines
727 B
JavaScript
Raw Permalink Normal View History

const test = require("tap").test;
const request = require("../src/request");
const config = require("../src/config");
test("request", (t) => {
t.plan(3);
t.test("correctly formed request", async (t) => {
const body = await request.proxy("123", "254711777734");
t.equal(body.slice(0, 3), "CON");
t.end();
});
t.test("bad request (4XX)", async (t) => {
// non ussd response
const body = await request.proxy("123", "255711777734");
t.not(body.slice(0, 3), "CON");
t.end();
});
t.test("request error or (5XX)", async (t) => {
config.store.USSD_ENDPOINT = "https://nonexistent";
const body = await request.proxy();
t.equal(body.slice(0, 3), "ERR");
t.end();
});
});