-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from xendit/test/add_test
Test/add test
- Loading branch information
Showing
12 changed files
with
438 additions
and
615 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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
IGNORED_ERRORCODE=INVALID_API_KEY, |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,76 +1,67 @@ | ||
/* | ||
xendit-invoice-service_test | ||
Testing InvoiceApiService | ||
*/ | ||
|
||
// Code generated by OpenAPI Generator | ||
|
||
package xendit | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/joho/godotenv" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
xendit "github.com/xendit/xendit-go/v3" | ||
"github.com/xendit/xendit-go/v3/invoice" | ||
) | ||
|
||
func Test_xendit_InvoiceApiService(t *testing.T) { | ||
err := godotenv.Load(".env.api_test") | ||
if err != nil { | ||
log.Fatal("Error loading .env.api_test file") | ||
} | ||
|
||
apiKey := os.Getenv("XND_APIKEY") | ||
apiKey := os.Getenv("DEVELOPMENT_API_KEY") | ||
if apiKey == "" { | ||
t.Skip("XND_APIKEY not set") | ||
t.Skip("DEVELOPMENT_API_KEY not set") | ||
} | ||
|
||
apiClient := xendit.NewClient(apiKey) | ||
|
||
t.Run("Test InvoiceApiService CreateInvoice", func(t *testing.T) { | ||
|
||
resp, httpRes, err := apiClient.InvoiceApi.CreateInvoice(context.Background()).Execute() | ||
|
||
require.Nil(t, err) | ||
require.NotNil(t, resp) | ||
assert.Equal(t, 200, httpRes.StatusCode) | ||
|
||
createInvoiceRequest := *invoice.NewCreateInvoiceRequest(time.Now().Format("20060102150405"), float32(10000)) | ||
resp, httpRes, err := apiClient.InvoiceApi. | ||
CreateInvoice(context.Background()). | ||
CreateInvoiceRequest(createInvoiceRequest). | ||
Execute() | ||
|
||
if err != nil { | ||
fmt.Fprintf(os.Stdout, "CreateInvoice Err`: %v\n", err) | ||
} else { | ||
fmt.Fprintf(os.Stdout, "CreateInvoice Res`: %v\n", resp) | ||
|
||
require.NotNil(t, resp) | ||
assert.Equal(t, 200, httpRes.StatusCode) | ||
assert.Equal(t, invoice.InvoiceStatus("PENDING"), resp.Status) | ||
} | ||
}) | ||
|
||
t.Run("Test InvoiceApiService GetInvoiceById", func(t *testing.T) { | ||
|
||
var invoiceId string | ||
var invoiceId string = "654a103b5e6dfa587b6025c3" | ||
|
||
resp, httpRes, err := apiClient.InvoiceApi.GetInvoiceById(context.Background(), invoiceId).Execute() | ||
|
||
require.Nil(t, err) | ||
require.NotNil(t, resp) | ||
assert.Equal(t, 200, httpRes.StatusCode) | ||
if err != nil { | ||
fmt.Fprintf(os.Stdout, "GetInvoiceById Err`: %v\n", err) | ||
} else { | ||
fmt.Fprintf(os.Stdout, "GetInvoiceById Res`: %v\n", resp) | ||
|
||
}) | ||
|
||
t.Run("Test InvoiceApiService GetInvoices", func(t *testing.T) { | ||
|
||
resp, httpRes, err := apiClient.InvoiceApi.GetInvoices(context.Background()).Execute() | ||
|
||
require.Nil(t, err) | ||
require.NotNil(t, resp) | ||
assert.Equal(t, 200, httpRes.StatusCode) | ||
|
||
}) | ||
|
||
t.Run("Test InvoiceApiService ExpireInvoice", func(t *testing.T) { | ||
|
||
var invoiceId string | ||
|
||
resp, httpRes, err := apiClient.InvoiceApi.ExpireInvoice(context.Background(), invoiceId).Execute() | ||
|
||
require.Nil(t, err) | ||
require.NotNil(t, resp) | ||
assert.Equal(t, 200, httpRes.StatusCode) | ||
require.NotNil(t, resp) | ||
assert.Equal(t, 200, httpRes.StatusCode) | ||
} | ||
|
||
}) | ||
|
||
} |
Oops, something went wrong.