File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed
Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 1+ import { v4 } from "uuid" ;
2+ import { test , expect , describe } from "vitest" ;
3+ import "dotenv/config" ;
4+
5+ import { CallConnect } from "../src" ;
6+
7+ const apiUrl = process . env . AUTHSIGNAL_CALL_CONNECT_URL ;
8+ const apiSecretKey = process . env . AUTHSIGNAL_CALL_CONNECT_API_SECRET_KEY ;
9+
10+ if ( ! apiUrl ) {
11+ console . log ( "AUTHSIGNAL_CALL_CONNECT_URL is undefined in env" ) ;
12+ process . exit ( 1 ) ;
13+ }
14+
15+ if ( ! apiSecretKey ) {
16+ console . log ( "AUTHSIGNAL_CALL_CONNECT_API_SECRET_KEY is undefined in env" ) ;
17+ process . exit ( 1 ) ;
18+ }
19+
20+ const client = new CallConnect ( { apiSecretKey, apiUrl} ) ;
21+
22+ describe ( "authsignal call connect tests" , ( ) => {
23+ test ( "start call test" , async ( ) => {
24+ const referenceId = v4 ( ) ;
25+ const channel = "WHATSAPP" ;
26+
27+ const startCallRequest = {
28+ referenceId,
29+ phoneNumber : "+6427123456" ,
30+ } ;
31+
32+ const startCallResponse = await client . startCall ( startCallRequest ) ;
33+
34+ expect ( startCallResponse ) . toBeDefined ( ) ;
35+ expect ( startCallResponse . channel ) . toEqual ( channel ) ;
36+ } ) ;
37+ } ) ;
Original file line number Diff line number Diff line change @@ -188,10 +188,13 @@ describe("authsignal client tests", () => {
188188 } catch ( ex ) {
189189 const isAuthsignalError = ex instanceof AuthsignalError ;
190190
191+ if ( ! isAuthsignalError ) {
192+ throw new Error ( "Expected AuthsignalError to be thrown" ) ;
193+ }
194+
191195 const expectedDescription =
192196 "The request is unauthorized. Check that your API key and region base URL are correctly configured." ;
193197
194- expect ( isAuthsignalError ) . toBeTruthy ( ) ;
195198 expect ( ex . statusCode ) . toEqual ( 401 ) ;
196199 expect ( ex . errorCode ) . toEqual ( "unauthorized" ) ;
197200 expect ( ex . errorDescription ) . toEqual ( expectedDescription ) ;
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ describe("authsignal webhook tests", () => {
2626 try {
2727 client . webhook . constructEvent ( payload , signature ) ;
2828 } catch ( ex ) {
29+ if ( ! ( ex instanceof Error ) ) {
30+ throw new Error ( "Expected Error to be thrown" ) ;
31+ }
32+
2933 expect ( ex . message ) . toEqual ( "Signature format is invalid." ) ;
3034 }
3135 } ) ;
@@ -37,6 +41,10 @@ describe("authsignal webhook tests", () => {
3741 try {
3842 client . webhook . constructEvent ( payload , signature ) ;
3943 } catch ( ex ) {
44+ if ( ! ( ex instanceof Error ) ) {
45+ throw new Error ( "Expected Error to be thrown" ) ;
46+ }
47+
4048 expect ( ex . message ) . toEqual ( "Timestamp is outside the tolerance zone." ) ;
4149 }
4250 } ) ;
@@ -49,6 +57,10 @@ describe("authsignal webhook tests", () => {
4957 try {
5058 client . webhook . constructEvent ( payload , signature ) ;
5159 } catch ( ex ) {
60+ if ( ! ( ex instanceof Error ) ) {
61+ throw new Error ( "Expected Error to be thrown" ) ;
62+ }
63+
5264 expect ( ex . message ) . toEqual ( "Signature mismatch." ) ;
5365 }
5466 } ) ;
You can’t perform that action at this time.
0 commit comments