Skip to content

Commit

Permalink
Run integration tests only before releases (#257)
Browse files Browse the repository at this point in the history
* Tagging integration tests

* Use 'unit' tag on regular PR's

* Mocking tests

* Fix conflicts

* Mock response function

* Renaming Balance Platform tests
  • Loading branch information
michaelpaul authored Nov 3, 2023
1 parent 5803e7f commit 81e5da9
Show file tree
Hide file tree
Showing 27 changed files with 1,056 additions and 275 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@ jobs:
name: Build & Verify
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- uses: actions/setup-go@v4
with:
go-version: 1.13

- name: Get dependencies
run: go get -v -t -d ./...

- name: Build
run: go build -v .

- name: Test
run: go test ./...
run: go test -v ./... -tags $GO_TEST_TAGS
env:
GO_TEST_TAGS: ${{ github.ref == 'refs/heads/main' && 'integration' || 'unit' }}
ADYEN_API_KEY: ${{ secrets.ADYEN_API_KEY }}
ADYEN_MERCHANT: ${{ secrets.ADYEN_MERCHANT }}
ADYEN_PASSWORD: ${{ secrets.ADYEN_PASSWORD }}
Expand Down
3 changes: 3 additions & 0 deletions src/adyen/api_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

package adyen

import (
Expand Down
3 changes: 3 additions & 0 deletions tests/api_modifications_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

package tests

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package balanceplatform

import (
"github.com/adyen/adyen-go-api-library/v8/src/acswebhook"
Expand All @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
)

func Test_BalancePlatform_Acs_Webhooks_HandleRequest(t *testing.T) {
func TestHandleAuthenticationNotificationRequest(t *testing.T) {
t.Run("on balancePlatform.authentication.created", func(t *testing.T) {
notificationJson := `{
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package balanceplatform

import (
"testing"
Expand All @@ -9,8 +9,7 @@ import (
"github.com/adyen/adyen-go-api-library/v8/src/configurationwebhook"
)

func Test_BalancePlatform_Configuration_Webhooks_HandleRequest(t *testing.T) {

func TestHandleAccountHolderNotificationRequest(t *testing.T) {
t.Run("should return accountHolder created success", func(t *testing.T) {
notificationJson := `{
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package balanceplatform

import (
"testing"
Expand All @@ -8,8 +8,7 @@ import (
"github.com/adyen/adyen-go-api-library/v8/src/reportwebhook"
)

func Test_BalancePlatform_Report_Webhooks_HandleRequest(t *testing.T) {

func TestHandleReportNotificationRequest(t *testing.T) {
t.Run("should return report created success", func(t *testing.T) {
notificationJson := `{
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package balanceplatform

import (
"testing"
Expand All @@ -8,8 +8,7 @@ import (
"github.com/adyen/adyen-go-api-library/v8/src/transferwebhook"
)

func Test_BalancePlatform_Transfer_Webhooks_HandleRequest(t *testing.T) {

func TestHandleTransferNotificationRequest(t *testing.T) {
t.Run("should return transfer success", func(t *testing.T) {
notificationJson := `{
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tests
package balanceplatform

import (
"context"
"errors"
"github.com/adyen/adyen-go-api-library/v8/src/adyen"
"github.com/adyen/adyen-go-api-library/v8/src/balanceplatform"
"github.com/adyen/adyen-go-api-library/v8/src/common"
"github.com/adyen/adyen-go-api-library/v8/tests"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io"
Expand All @@ -15,7 +16,7 @@ import (
"testing"
)

func Test_BalancePlatform(t *testing.T) {
func TestBalancePlatform(t *testing.T) {
client := adyen.NewClient(&common.Config{
ApiKey: "YOUR_ADYEN_API_KEY",
Environment: "TEST",
Expand All @@ -24,19 +25,16 @@ func Test_BalancePlatform(t *testing.T) {
service := client.BalancePlatform()

mux := http.NewServeMux()
// Success case
mux.HandleFunc("/accountHolders/123", func(w http.ResponseWriter, r *http.Request) {
assert.Contains(t, [2]string{"GET", "PATCH"}, r.Method)
w.Header().Set("Content-Type", "application/json")
file, _ := os.Open("fixtures/account_holder.json")
io.Copy(w, file)
})
mockResponse := tests.MockResponse(t, mux)

// Success cases
mockResponse(http.StatusOK, "GET PATCH", "/accountHolders/123", "account_holder.json")
mux.HandleFunc("/accountHolders/123/balanceAccounts", func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "GET", r.Method)
assert.Equal(t, "5", r.URL.Query().Get("limit"))
assert.Equal(t, "42", r.URL.Query().Get("offset"))
w.Header().Set("Content-Type", "application/json")
file, _ := os.Open("fixtures/paginated_balance_accounts_response.json")
file, _ := os.Open("../fixtures/paginated_balance_accounts_response.json")
io.Copy(w, file)
})
mux.HandleFunc("/balanceAccounts/balanceAccountId/sweeps/sweepId", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -48,26 +46,11 @@ func Test_BalancePlatform(t *testing.T) {
require.Equal(t, "POST", r.Method)
// no response
})
mux.HandleFunc("/balanceAccounts/BA123/sweeps/SWPC123", func(w http.ResponseWriter, r *http.Request) {
assert.Contains(t, [2]string{"GET", "PATCH"}, r.Method)
w.Header().Set("Content-Type", "application/json")
file, _ := os.Open("fixtures/sweep.json")
io.Copy(w, file)
})
mux.HandleFunc("/transactionRules/transactionRuleId", func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "DELETE", r.Method)
w.Header().Set("Content-Type", "application/json")
file, _ := os.Open("fixtures/transaction_rule.json")
io.Copy(w, file)
})
mockResponse(http.StatusOK, "GET PATCH", "/balanceAccounts/BA123/sweeps/SWPC123", "sweep.json")
mockResponse(http.StatusOK, "DELETE", "/transactionRules/transactionRuleId", "transaction_rule.json")

// Error case
mux.HandleFunc("/paymentInstruments/666", func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "PATCH", r.Method)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnprocessableEntity)
file, _ := os.Open("fixtures/not_found.json")
io.Copy(w, file)
})
mockResponse(http.StatusUnprocessableEntity, "PATCH", "/paymentInstruments/666", "not_found.json")

mockServer := httptest.NewServer(mux)
defer mockServer.Close()
Expand Down
3 changes: 3 additions & 0 deletions tests/binlookup_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build integration
// +build integration

package tests

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tests
package checkout

import (
"context"
Expand Down
Loading

0 comments on commit 81e5da9

Please sign in to comment.