Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhamridho04 committed Sep 22, 2023
1 parent 62b5d14 commit f1fcfa2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"typings": "./index.d.ts",
"scripts": {
"dev": "nodemon example.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "nodemon ./test/searchNumber.test.js"
},
"repository": {
"type": "git",
Expand Down
65 changes: 65 additions & 0 deletions test/searchNumber.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const { GClient, GLocalAuth } = require("../index");
const qrcode = require("qrcode-terminal");
const readline = require("readline");

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

const client = new GClient({
// proxyAuthentication: { username: 'username', password: 'password' },
puppeteer: {
// args: ['--proxy-server=proxy-server-that-requires-authentication.example.com'],
headless: false,
},
authStrategy: new GLocalAuth({
clientId: "test-aja-inimah",
// dataPath: './.wwebjs_auth/'
}),
});

client.initialize();

client.on("loading_screen", (percent, message) => {
console.log("LOADING SCREEN", percent, message);
});

client.on("qr", (qr) => {
// NOTE: This event will not be fired if a session is specified.
console.log("QR RECEIVED", qr);
qrcode.generate(qr, { small: true });
});

client.on("authenticated", async () => {
console.log("AUTHENTICATED");
// client.searchNumber("ID", "085771116774").then((result) => {
// console.log(result);
// });
});

client.on("auth_failure", (msg) => {
// Fired if session restore was unsuccessful
console.error("AUTHENTICATION FAILURE", msg);
});

client.on("ready", () => {
console.log("READY");
hitung();
});

function hitung() {
rl.question("Masukan nomor: ", (nomor) => {
client.searchNumber("ID", nomor).then((result) => {
console.log(result);
});

rl.question("Ingin melakukan pencarian lagi? (y/n) ", (jawaban) => {
if (jawaban.toLowerCase() === "y") {
hitung();
} else {
rl.close();
}
});
});
}

0 comments on commit f1fcfa2

Please sign in to comment.