mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat(EN-208): enable default & minimum polling period specifically for Stripe * feat(EN-208): update openAPI + fix compile-configs tool to support Durations * feat(EN-208): created helper type for period so it's easier to generalize * feat(EN-208): enable pollingPeriod for atlar * feat(EN-208): same treatment for bankingbridge * feat(EN-208): change column * feat(EN-208): added pollingPeriod for generic. * feat(EN-208): increase, couldn't connecto properly * feat(EN-208): added pollingPeriod for mangopay, modulr, moneycorp, qonto and wise * feat(EN-208): fixed openapi and sdk * fix: change global default/min pollingPeriod * fix: e2e tests
100 lines
2.7 KiB
Go
100 lines
2.7 KiB
Go
package stripe
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/formancehq/payments/internal/models"
|
|
"github.com/go-playground/validator/v10"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("unmarshalAndValidateConfig", func() {
|
|
var (
|
|
payload json.RawMessage
|
|
expectedError error
|
|
config Config
|
|
err error
|
|
)
|
|
|
|
JustBeforeEach(func() {
|
|
config, err = unmarshalAndValidateConfig(payload)
|
|
})
|
|
|
|
Context("with valid configuration and explicit polling period", func() {
|
|
BeforeEach(func() {
|
|
// 45 minutes in nanoseconds
|
|
payload = json.RawMessage(`{"apiKey":"sk_test_123","pollingPeriod":"45m"}`)
|
|
expectedError = nil
|
|
})
|
|
|
|
It("should successfully unmarshal and validate with given polling period", func() {
|
|
Expect(err).To(BeNil())
|
|
Expect(config.APIKey).To(Equal("sk_test_123"))
|
|
Expect(config.PollingPeriod.Duration()).To(Equal(45 * time.Minute))
|
|
})
|
|
})
|
|
|
|
Context("with missing polling period", func() {
|
|
BeforeEach(func() {
|
|
payload = json.RawMessage(`{"apiKey":"sk_test_123"}`)
|
|
expectedError = nil
|
|
})
|
|
|
|
It("should default to 30 minutes", func() {
|
|
Expect(err).To(BeNil())
|
|
Expect(config.PollingPeriod.Duration()).To(Equal(30 * time.Minute))
|
|
})
|
|
})
|
|
|
|
Context("with polling period lower than minimum", func() {
|
|
BeforeEach(func() {
|
|
// 5 minutes in nanoseconds
|
|
payload = json.RawMessage(`{"apiKey":"sk_test_123","pollingPeriod":"5m"}`)
|
|
expectedError = nil
|
|
})
|
|
|
|
It("should coerce to minimum 20 minutes", func() {
|
|
Expect(err).To(BeNil())
|
|
Expect(config.PollingPeriod.Duration()).To(Equal(20 * time.Minute))
|
|
})
|
|
})
|
|
|
|
Context("with missing apiKey", func() {
|
|
BeforeEach(func() {
|
|
// 30 minutes in nanoseconds
|
|
payload = json.RawMessage(`{"pollingPeriod":"30m"}`)
|
|
})
|
|
|
|
It("should return a validation error", func() {
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err).To(BeAssignableToTypeOf(validator.ValidationErrors{}))
|
|
})
|
|
})
|
|
|
|
Context("with invalid JSON payload", func() {
|
|
BeforeEach(func() {
|
|
payload = json.RawMessage(`{"apiKey":sk_test_123}`)
|
|
expectedError = models.ErrInvalidConfig
|
|
})
|
|
|
|
It("should return an unmarshalling error wrapped as invalid config", func() {
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err).To(MatchError(ContainSubstring(expectedError.Error())))
|
|
})
|
|
})
|
|
})
|
|
|
|
var _ = Describe("marshall", func() {
|
|
It("keeps duration in string format", func() {
|
|
raw := json.RawMessage(`{"apiKey":"sk_test_123", "pollingPeriod":"30m"}`)
|
|
config, err := unmarshalAndValidateConfig(raw)
|
|
Expect(err).To(BeNil())
|
|
marshaledConfig, err := json.Marshal(config)
|
|
Expect(err).To(BeNil())
|
|
Expect(string(marshaledConfig)).To(ContainSubstring(`"pollingPeriod":"30m0s"`))
|
|
Expect(string(marshaledConfig)).To(ContainSubstring(`"apiKey":"sk_test_123"`))
|
|
})
|
|
})
|