Skip to content

Commit

Permalink
update to tests and creating .env.schema
Browse files Browse the repository at this point in the history
  • Loading branch information
igmrrf committed Feb 27, 2024
1 parent 274e126 commit 127e954
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 152 deletions.
11 changes: 5 additions & 6 deletions __tests__/call.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Sendchamp from "../src";
import { publicKey } from "../src/config";
import { SendchampMode } from "../src/constants/types";
import { CALL } from "../src/services";

Expand All @@ -7,7 +8,7 @@ describe("CALL", () => {
let call: CALL;
beforeEach(() => {
sendchamp = new Sendchamp({
publicKey: process.env.PUBLIC_KEY!,
publicKey,
mode: SendchampMode.live,
});
call = sendchamp.CALL;
Expand All @@ -20,18 +21,16 @@ describe("CALL", () => {

test("call.create()", async () => {
const res = await call.create();
console.log({ res });

expect(res.status).toBe("success");

Check failure on line 25 in __tests__/call.spec.ts

View workflow job for this annotation

GitHub Actions / test

CALL › call.create()

expect(received).toBe(expected) // Object.is equality Expected: "success" Received: undefined at __tests__/call.spec.ts:25:24 at step (__tests__/call.spec.ts:33:23) at Object.next (__tests__/call.spec.ts:14:53) at fulfilled (__tests__/call.spec.ts:5:58)
expect(res.code).not.toBe(200);
expect(res.code).toBe(200);
});

test("call.listVoiceCalls()", async () => {
const res = await call.listVoiceCalls();
console.log({ res });

expect(res.status).toBe("success");

Check failure on line 32 in __tests__/call.spec.ts

View workflow job for this annotation

GitHub Actions / test

CALL › call.listVoiceCalls()

expect(received).toBe(expected) // Object.is equality Expected: "success" Received: undefined at __tests__/call.spec.ts:32:24 at step (__tests__/call.spec.ts:33:23) at Object.next (__tests__/call.spec.ts:14:53) at fulfilled (__tests__/call.spec.ts:5:58)
expect(res.code).not.toBe(200);
expect(res.code).toBe(200);
});

test("call.retrieveSingleCall()", async () => {
Expand All @@ -41,6 +40,6 @@ describe("CALL", () => {
const res = await call.retrieveSingleCall(id);

expect(res.status).toBe("success");
expect(res.code).not.toBe(200);
expect(res.code).toBe(200);
});
});
5 changes: 2 additions & 3 deletions __tests__/email.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ describe("EMAIL", () => {
test("email.send()", async () => {
const res = await email.send({
subject: "EMAIL TEST",
to: [{ email: mail, name: "" }],
from: [{ email: domainEmail, name: "" }],
to: [{ email: mail, name: "Bored" }],
from: { email: domainEmail, name: "More Bored" },
message_body: {
type: "text/html",
value: "This is the contents of a test", // plain text or html
},
});

expect(res.status).toBe("success");
expect(res.code).not.toBe(200);
});
Expand Down
10 changes: 5 additions & 5 deletions __tests__/sendchamp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Sendchamp from "../src";
import { mobile } from "../src/config";
import { mobile, publicKey } from "../src/config";
import { InsightType, SendchampMode } from "../src/constants/types";

describe("SENDCHAMP", () => {
let sendchamp: Sendchamp;
beforeEach(() => {
sendchamp = new Sendchamp({
publicKey: process.env.PUBLIC_KEY!,
publicKey,
mode: SendchampMode.live,
});
});
Expand All @@ -19,16 +19,16 @@ describe("SENDCHAMP", () => {
const res = await sendchamp.getWalletBalance();

expect(res.status).toBe("success");
expect(res.code).not.toBe(200);
expect(res.code).toBe(200);
});

test("sendChamp.walletBalance()", async () => {
test("sendChamp.getNumberInsight()", async () => {
const res = await sendchamp.getNumberInsight({
phone_number: mobile,
type: InsightType.core,
});

expect(res.status).toBe("success");
expect(res.code).not.toBe(200);
expect(res.code).toBe(200);
});
});
80 changes: 31 additions & 49 deletions __tests__/sms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("SMS", () => {
let sms: SMS;
beforeEach(() => {
sendchamp = new Sendchamp({
publicKey: publicKey,
publicKey,
mode: SendchampMode.live,
});
sms = sendchamp.SMS;
Expand All @@ -20,39 +20,39 @@ describe("SMS", () => {
sms = undefined as unknown as SMS;
});

test("sms.send()", async () => {
const {
status,
code,
data: { id },
} = await sms.send({
message: "test_message_node_sdk",
sender_name: sender_name,
to: [mobile],
route: SMSRoute.dnd,
test("sms.registerSender()", async () => {
const name = random("aA", 6);
const { code, status, data } = await sms.registerSender({
sample: "Your otp is 1234",
name,
use_case: SenderUseCase.transactional,
});

expect(status).toBe("success");

Check failure on line 31 in __tests__/sms.spec.ts

View workflow job for this annotation

GitHub Actions / test

SMS › sms.registerSender()

expect(received).toBe(expected) // Object.is equality Expected: "success" Received: "failed" at __tests__/sms.spec.ts:31:20 at step (__tests__/sms.spec.ts:33:23) at Object.next (__tests__/sms.spec.ts:14:53) at fulfilled (__tests__/sms.spec.ts:5:58)
expect(code).toBe(200);
expect(typeof id).toBe("string");
expect(typeof data.uid).toBe("string");
expect(data.name).toEqual(name);
});

test("sms.getStatus()", async () => {
const _res = await sms.send({
test("sms.send()", async () => {
const res = await sms.send({
message: "test_message_node_sdk",
sender_name: "SDigital",
sender_name,
to: [mobile],
route: SMSRoute.dnd,
});
const message_id = _res.data.id;

const res = await sms.getSMSStatus(message_id);
expect(res.status).toBe("success");
expect(res.code).toBe(200);
expect(res.data.id).toMatch(message_id);
const {
code,
status,
data: { business_id },
} = res;

Check failure on line 49 in __tests__/sms.spec.ts

View workflow job for this annotation

GitHub Actions / test

SMS › sms.send()

TypeError: Cannot read properties of null (reading 'business_id') at __tests__/sms.spec.ts:49:12 at step (__tests__/sms.spec.ts:33:23) at Object.next (__tests__/sms.spec.ts:14:53) at fulfilled (__tests__/sms.spec.ts:5:58)
expect(status).toBe("success");
expect(code).toBe(200);
expect(typeof business_id).toBe("string");
});

test("sms.sendBulk()", async () => {
test("send.sendBulk(), return successfully", async () => {
const res = await sms.send({
message: "test_message_node_sdk",
sender_name,
Expand All @@ -62,35 +62,17 @@ describe("SMS", () => {

expect(res.status).toBe("success");

Check failure on line 63 in __tests__/sms.spec.ts

View workflow job for this annotation

GitHub Actions / test

SMS › send.sendBulk()

expect(received).toBe(expected) // Object.is equality Expected: "success" Received: "failed" at __tests__/sms.spec.ts:63:24 at step (__tests__/sms.spec.ts:33:23) at Object.next (__tests__/sms.spec.ts:14:53) at fulfilled (__tests__/sms.spec.ts:5:58)
expect(res.code).toBe(200);
expect(typeof res.data.id).toBe("string");
expect(typeof res.data.business_id).toBe("string");
});

test("sms.getBulkStatus()", async () => {
const _res = await sms.send({
message: "test_message_node_sdk",
sender_name: "SDigital",
to: [mobile],
route: SMSRoute.dnd,
});
const bulk_message_id = _res.data.id;

const res = await sms.getBulkSMSStatus(bulk_message_id);
expect(res.status).toBe("success");
expect(res.code).toBe("200");
expect(res.data.id).toMatch(bulk_message_id);
});

test("sms.registerSender()", async () => {
const name = random("aA", 6);
const { code, status, data } = await sms.registerSender({
sample: "Your otp is 1234",
name,
use_case: SenderUseCase.transactional,
});

expect(status).toBe("success");
expect(code).toBe(200);
expect(typeof data.uid).toBe("string");
expect(data.id).toEqual(name);
test("send.sendBulk(), to throw when non-existing name is used", async () => {
expect(async () => {

Check failure on line 69 in __tests__/sms.spec.ts

View workflow job for this annotation

GitHub Actions / test

VOICE › VOICE.sendAudioToSpeech

expect(received).rejects.toEqual() Received promise resolved instead of rejected Resolved to value: undefined at expect (node_modules/expect/build/index.js:113:15) at __tests__/sms.spec.ts:69:5 at step (__tests__/sms.spec.ts:33:23) at Object.next (__tests__/sms.spec.ts:14:53) at __tests__/sms.spec.ts:8:71 at Object.<anonymous>.__awaiter (__tests__/sms.spec.ts:4:12) at Object.<anonymous> (__tests__/sms.spec.ts:68:68)
await sms.send({
message: "test_message_node_sdk",
sender_name: "Non-Existing",
to: [mobile, "08123456789"],
route: SMSRoute.dnd,
});
}).rejects.toEqual(new Error("invalid sender name: Non-Existing"));
});
});
80 changes: 50 additions & 30 deletions __tests__/verification.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import Sendchamp from "../src";
import { mobile, publicKey, sender_name } from "../src/config";
import { mobile, publicKey, sender_name, mail } from "../src/config";
import { Channel, SendchampMode, TokenType } from "../src/constants/types";
import { VERIFICATION } from "../src/services";

describe("VERIFICATION", () => {
const mockVerificationData = {
channel: Channel.sms,
expiration_time: 5,
sender: sender_name,
token_length: 4,
token_type: TokenType.alphanumeric,
customer_mobile_number: mobile,
customer_email_address: mail,
meta_data: {
name: "Fuad",
class: "__test_class__",
description: "demo",
},
in_app_token: false,
};
let sendchamp: Sendchamp;
let verification: VERIFICATION;
console.log({ mobile, publicKey });
beforeEach(() => {
sendchamp = new Sendchamp({
publicKey: publicKey,
publicKey,
mode: SendchampMode.live,
});
verification = sendchamp.VERIFICATION;
Expand All @@ -21,21 +35,40 @@ describe("VERIFICATION", () => {
});

test("verification.sendOTP()", async () => {
console.log({ mobile, publicKey });
const res = await verification.sendOTP({
channel: Channel.sms,
expiration_time: 5,
sender: sender_name,
token_length: 4,
token_type: TokenType.alphanumeric,
customer_mobile_number: mobile,
meta_data: {
name: "Fuad",
class: "__test_class__",
description: "demo",
},
in_app_token: false,
...mockVerificationData,
channel: Channel.voice,
});
expect(res.status).toBe("success");
expect(res.code).toBe(200);
expect(res.data.business_uid).toBeDefined();
expect(typeof res.data.reference).toEqual("string");
});

test.only("verification.sendOTP()", async () => {
const res = await verification.sendOTP({
...mockVerificationData,
channel: Channel.whatsapp,
});
expect(res.status).toBe("success");

Check failure on line 53 in __tests__/verification.spec.ts

View workflow job for this annotation

GitHub Actions / test

VERIFICATION › verification.sendOTP()

expect(received).toBe(expected) // Object.is equality Expected: "success" Received: "failed" at __tests__/verification.spec.ts:53:24 at step (__tests__/verification.spec.ts:44:23) at Object.next (__tests__/verification.spec.ts:25:53) at fulfilled (__tests__/verification.spec.ts:16:58)
expect(res.code).toBe(200);
expect(res.data.business_uid).toBeDefined();
expect(typeof res.data.reference).toEqual("string");
});

test("verification.sendOTP()", async () => {
const res = await verification.sendOTP({
...mockVerificationData,
channel: Channel.email,
});
expect(res.status).toBe("success");
expect(res.code).toBe(200);
expect(res.data.business_uid).toBeDefined();
expect(typeof res.data.reference).toEqual("string");
});

test("verification.sendOTP()", async () => {
const res = await verification.sendOTP(mockVerificationData);
console.log({ res });
expect(res.status).toBe("success");
expect(res.code).toBe(200);
Expand All @@ -48,20 +81,7 @@ describe("VERIFICATION", () => {
status,
code,
data: { reference, token },
} = await verification.sendOTP({
channel: Channel.sms,
expiration_time: 5,
sender: sender_name,
token_length: 4,
token_type: TokenType.alphanumeric,
customer_mobile_number: mobile,
meta_data: {
name: "Fuad",
class: "__test_class__",
description: "demo",
},
in_app_token: false,
});
} = await verification.sendOTP(mockVerificationData);

expect(status).toBe("success");
expect(code).toBe(200);
Expand Down
60 changes: 22 additions & 38 deletions __tests__/voice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,32 @@ describe("VOICE", () => {
sendchamp = undefined as unknown as Sendchamp;
voice = undefined as unknown as VOICE;
});
describe("VOICE.sendTextToSpeech", () => {
test("return successfully", async () => {
const res = await voice.sendTextToSpeech(textMockData);
expect(res.status).toBe("success");
expect(res.code).toBe("200");
expect(typeof res.data.message).toBe(textMockData.message);
});

test("should throw error", async () => {
expect(async () => {
await voice.sendTextToSpeech({
...textMockData,
repeat: -1,
});
}).rejects.toEqual(new Error("repeat must be at least 1"));
});
test("VOICE.sendTextToSpeech, return successfully", async () => {
const res = await voice.sendTextToSpeech(textMockData);
expect(res.status).toBe("success");

Check failure on line 37 in __tests__/voice.spec.ts

View workflow job for this annotation

GitHub Actions / test

VOICE › VOICE.sendTextToSpeech

expect(received).toBe(expected) // Object.is equality Expected: "success" Received: "failed" at __tests__/voice.spec.ts:37:24 at step (__tests__/voice.spec.ts:44:23) at Object.next (__tests__/voice.spec.ts:25:53) at fulfilled (__tests__/voice.spec.ts:16:58)
expect(res.code).toBe(200);
expect(res.data.message).toBe(textMockData.message);
});

describe("VOICE.sendAudioToSpeech", () => {
test("return successfully", async () => {
const res = await voice.sendAudioToSpeech(audioMockData);
expect(res.status).toBe("success");
expect(res.code).toBe("200");
expect(typeof res.data.business_uid).toBe("string");
});

test("should throw error", async () => {
expect(async () => {
await voice.sendAudioToSpeech(audioMockData);
}).rejects.toEqual(new Error("repeat must be at least 1"));
});
test("VOICE.sendTextToSpeech, should throw error", async () => {
expect(async () => {
await voice.sendTextToSpeech({
...textMockData,
repeat: -1,
});
}).rejects.toEqual(new Error("repeat must be at least 1"));
});

describe("VOICE.getVoiceStatus", () => {
test("return successfully", async () => {
const {
data: { business_uid },
} = await voice.sendTextToSpeech(textMockData);
test("VOICE.sendAudioToSpeech, return successfully", async () => {
const res = await voice.sendAudioToSpeech(audioMockData);
expect(res.status).toBe("success");

Check failure on line 53 in __tests__/voice.spec.ts

View workflow job for this annotation

GitHub Actions / test

VOICE › VOICE.sendAudioToSpeech

expect(received).toBe(expected) // Object.is equality Expected: "success" Received: "failed" at __tests__/voice.spec.ts:53:24 at step (__tests__/voice.spec.ts:44:23) at Object.next (__tests__/voice.spec.ts:25:53) at fulfilled (__tests__/voice.spec.ts:16:58)
expect(res.code).toBe(200);
expect(typeof res.data.business_uid).toBe("string");
});

const res = await voice.getVoiceStatus(business_uid);
expect(res.status).toBe("success");
expect(res.code).toBe(200);
});
test("VOICE.sendAudioToSpeech, should throw error", async () => {
expect(async () => {
await voice.sendAudioToSpeech({ ...audioMockData, repeat: -1 });
}).rejects.toEqual(new Error("repeat must be at least 1"));
});
});
Loading

0 comments on commit 127e954

Please sign in to comment.