-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab95fec
commit 04ec3f0
Showing
1 changed file
with
73 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,116 @@ | ||
package intouchpay_test | ||
package Intouchpay_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
intouchpay "github.com/samueltuyizere/go-intouchpay" | ||
Intouchpay "github.com/samueltuyizere/go-intouchpay" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Should create a new instance of Client with the provided username, account number, and partner password | ||
func TestNewClientWithValidInputs(t *testing.T) { | ||
username := "testuser" | ||
accountNumber := "123456789" | ||
partnerPassword := "password" | ||
// Returns a new instance of Client with the provided parameters | ||
|
||
// Creates a new client with valid input parameters | ||
func TestNewClientWithValidInputParameters(t *testing.T) { | ||
const ( | ||
username = "testuser" | ||
accountNumber = "1234567890" | ||
partnerPassword = "password" | ||
callbackUrl = "https://example.com/callback" | ||
sid = 12345 | ||
) | ||
|
||
client := intouchpay.NewClient(username, accountNumber, partnerPassword) | ||
client := Intouchpay.NewClient(username, accountNumber, partnerPassword, callbackUrl, sid) | ||
|
||
if client.Username != username { | ||
t.Errorf("Expected username to be %s, but got %s", username, client.Username) | ||
t.Errorf("Expected username %s, but got %s", username, client.Username) | ||
} | ||
|
||
if client.AccountNo != accountNumber { | ||
t.Errorf("Expected account number to be %s, but got %s", accountNumber, client.AccountNo) | ||
t.Errorf("Expected account number %s, but got %s", accountNumber, client.AccountNo) | ||
} | ||
|
||
if client.PartnerPassword != partnerPassword { | ||
t.Errorf("Expected partner password to be %s, but got %s", partnerPassword, client.PartnerPassword) | ||
t.Errorf("Expected password %s, but got %s", partnerPassword, client.PartnerPassword) | ||
} | ||
|
||
if client.CallbackURL != callbackUrl { | ||
t.Errorf("Expected callback URL %s, but got %s", callbackUrl, client.CallbackURL) | ||
} | ||
|
||
if client.Sid != sid { | ||
t.Errorf("Expected SID %d, but got %d", sid, client.Sid) | ||
} | ||
|
||
if client.HTTPClient.Timeout != 5*time.Second { | ||
t.Errorf("Expected timeout to be 5 seconds, but got %s", client.HTTPClient.Timeout) | ||
t.Errorf("Expected timeout of %s, but got %s", 5*time.Second, client.HTTPClient.Timeout) | ||
} | ||
} | ||
|
||
// Should set the HTTPClient timeout to 5 seconds | ||
func TestNewClientWithDefaultTimeout(t *testing.T) { | ||
// Sets the HTTP client timeout to 5 seconds | ||
func TestNewClientSetsHTTPClientTimeout(t *testing.T) { | ||
username := "testuser" | ||
accountNumber := "123456789" | ||
accountNumber := "1234567890" | ||
partnerPassword := "password" | ||
callbackUrl := "https://example.com/callback" | ||
sid := 12345 | ||
|
||
client := intouchpay.NewClient(username, accountNumber, partnerPassword) | ||
client := Intouchpay.NewClient(username, accountNumber, partnerPassword, callbackUrl, sid) | ||
|
||
if client.HTTPClient.Timeout != 5*time.Second { | ||
t.Errorf("Expected timeout to be 5 seconds, but got %s", client.HTTPClient.Timeout) | ||
} | ||
assert.Equal(t, 5*time.Second, client.HTTPClient.Timeout) | ||
} | ||
|
||
// Should handle empty username, account number, and partner password strings | ||
func TestNewClientWithEmptyInputs(t *testing.T) { | ||
username := "" | ||
accountNumber := "" | ||
partnerPassword := "" | ||
// Returns a pointer to a new client instance | ||
func TestNewClientReturnsPointerToNewInstance(t *testing.T) { | ||
username := "testuser" | ||
accountNumber := "1234567890" | ||
partnerPassword := "password" | ||
callbackUrl := "https://example.com/callback" | ||
sid := 12345 | ||
|
||
client := intouchpay.NewClient(username, accountNumber, partnerPassword) | ||
client := Intouchpay.NewClient(username, accountNumber, partnerPassword, callbackUrl, sid) | ||
|
||
if client.Username != username { | ||
t.Errorf("Expected username to be %s, but got %s", username, client.Username) | ||
} | ||
if client.AccountNo != accountNumber { | ||
t.Errorf("Expected account number to be %s, but got %s", accountNumber, client.AccountNo) | ||
} | ||
if client.PartnerPassword != partnerPassword { | ||
t.Errorf("Expected partner password to be %s, but got %s", partnerPassword, client.PartnerPassword) | ||
} | ||
assert.NotNil(t, client) | ||
} | ||
|
||
// Should handle invalid or empty HTTPClient | ||
func TestNewClientWithInvalidHTTPClient(t *testing.T) { | ||
username := "testuser" | ||
accountNumber := "123456789" | ||
// Returns a pointer to a new client instance with empty username | ||
func TestNewClientReturnsPointerToNewInstanceWithEmptyUsername(t *testing.T) { | ||
username := "" | ||
accountNumber := "1234567890" | ||
partnerPassword := "password" | ||
callbackUrl := "https://example.com/callback" | ||
sid := 12345 | ||
|
||
client := &intouchpay.Client{ | ||
Username: username, | ||
AccountNo: accountNumber, | ||
PartnerPassword: partnerPassword, | ||
HTTPClient: nil, | ||
} | ||
client := Intouchpay.NewClient(username, accountNumber, partnerPassword, callbackUrl, sid) | ||
|
||
if client.HTTPClient != nil { | ||
t.Errorf("Expected HTTPClient to be nil, but got %v", client.HTTPClient) | ||
} | ||
assert.NotNil(t, client) | ||
assert.Equal(t, username, client.Username) | ||
} | ||
|
||
// Should handle invalid or empty timeout value | ||
func TestNewClientWithInvalidTimeout(t *testing.T) { | ||
// Returns a pointer to a new client instance with empty account number | ||
func TestNewClientReturnsPointerToNewInstanceWithEmptyAccountNumber(t *testing.T) { | ||
username := "testuser" | ||
accountNumber := "123456789" | ||
accountNumber := "" | ||
partnerPassword := "password" | ||
callbackUrl := "https://example.com/callback" | ||
sid := 12345 | ||
|
||
client := &intouchpay.Client{ | ||
Username: username, | ||
AccountNo: accountNumber, | ||
PartnerPassword: partnerPassword, | ||
HTTPClient: &http.Client{ | ||
Timeout: 0, | ||
}, | ||
} | ||
client := Intouchpay.NewClient(username, accountNumber, partnerPassword, callbackUrl, sid) | ||
|
||
if client.HTTPClient.Timeout != 0 { | ||
t.Errorf("Expected timeout to be 0, but got %s", client.HTTPClient.Timeout) | ||
} | ||
assert.NotNil(t, client) | ||
assert.Equal(t, accountNumber, client.AccountNo) | ||
} | ||
|
||
// Should handle special characters and whitespace in username, account number, and partner password strings | ||
func TestNewClientWithSpecialCharacters(t *testing.T) { | ||
username := "test@user" | ||
accountNumber := "123 456 789" | ||
partnerPassword := "pass word" | ||
// Returns a pointer to a new client instance with empty partner password | ||
func TestNewClientReturnsPointerToNewInstanceWithEmptyPartnerPassword(t *testing.T) { | ||
username := "testuser" | ||
accountNumber := "1234567890" | ||
partnerPassword := "" | ||
callbackUrl := "https://example.com/callback" | ||
sid := 12345 | ||
|
||
client := intouchpay.NewClient(username, accountNumber, partnerPassword) | ||
client := Intouchpay.NewClient(username, accountNumber, partnerPassword, callbackUrl, sid) | ||
|
||
if client.Username != username { | ||
t.Errorf("Expected username to be %s, but got %s", username, client.Username) | ||
} | ||
if client.AccountNo != accountNumber { | ||
t.Errorf("Expected account number to be %s, but got %s", accountNumber, client.AccountNo) | ||
} | ||
if client.PartnerPassword != partnerPassword { | ||
t.Errorf("Expected partner password to be %s, but got %s", partnerPassword, client.PartnerPassword) | ||
} | ||
assert.NotNil(t, client) | ||
assert.Equal(t, partnerPassword, client.PartnerPassword) | ||
} |