ussd-tg-proxy/tests/request.test.js
Mohammed Sohail 2a42a5882c
release: v0.2.0
updates:

* add tests for most modules
* add confini for loading configs
* add contact spoof check
* add optional webhook support
* add error handling
* add pino logger
* update keyboard regex
2022-01-17 15:35:36 +03:00

32 lines
727 B
JavaScript

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();
});
});