mirror of
https://github.com/hanzo-fi/webhooks.git
synced 2026-10-30 20:32:55 +00:00
100 lines
2.6 KiB
Go
100 lines
2.6 KiB
Go
//go:build it
|
|
|
|
package test_suite
|
|
|
|
import (
|
|
"github.com/hanzo-fi/go-libs/v2/logging"
|
|
"github.com/hanzo-fi/go-libs/v2/testing/platform/pgtesting"
|
|
webhooks "github.com/hanzo-fi/webhooks/pkg"
|
|
"github.com/hanzo-fi/webhooks/pkg/client/models/components"
|
|
"github.com/hanzo-fi/webhooks/pkg/client/models/operations"
|
|
"github.com/hanzo-fi/webhooks/pkg/client/models/sdkerrors"
|
|
"github.com/hanzo-fi/webhooks/pkg/testserver"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Context("Config deletion", func() {
|
|
var (
|
|
db = pgtesting.UsePostgresDatabase(pgServer)
|
|
srv = testserver.NewTestServer(func() testserver.Configuration {
|
|
return testserver.Configuration{
|
|
Postgres: db.GetValue().ConnectionOptions(),
|
|
Topics: []string{},
|
|
Debug: debug,
|
|
Output: GinkgoWriter,
|
|
NatsURL: natsServer.GetValue().URL,
|
|
}
|
|
})
|
|
ctx = logging.TestingContext()
|
|
secret = webhooks.NewSecret()
|
|
insertResp *components.ConfigResponse
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
cfg := components.ConfigUser{
|
|
Endpoint: "https://example.com",
|
|
Secret: &secret,
|
|
EventTypes: []string{
|
|
"ledger.committed_transactions",
|
|
},
|
|
}
|
|
response, err := srv.GetValue().Client().Webhooks.V1.InsertConfig(
|
|
ctx,
|
|
cfg,
|
|
)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
insertResp = response.ConfigResponse
|
|
})
|
|
|
|
Context("deleting the inserted one", func() {
|
|
BeforeEach(func() {
|
|
_, err := srv.GetValue().Client().Webhooks.V1.DeleteConfig(
|
|
ctx,
|
|
operations.DeleteConfigRequest{
|
|
ID: insertResp.Data.ID,
|
|
},
|
|
)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
})
|
|
|
|
Context("getting all configs", func() {
|
|
It("should return 0 config", func() {
|
|
response, err := srv.GetValue().Client().Webhooks.V1.GetManyConfigs(
|
|
ctx,
|
|
operations.GetManyConfigsRequest{},
|
|
)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(response.ConfigsResponse.Cursor.HasMore).To(BeFalse())
|
|
Expect(response.ConfigsResponse.Cursor.Data).To(BeEmpty())
|
|
})
|
|
})
|
|
|
|
AfterEach(func() {
|
|
_, err := srv.GetValue().Client().Webhooks.V1.DeleteConfig(
|
|
ctx,
|
|
operations.DeleteConfigRequest{
|
|
ID: insertResp.Data.ID,
|
|
},
|
|
)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.(*sdkerrors.ErrorResponse).ErrorCode).To(Equal(components.ErrorsEnumNotFound))
|
|
})
|
|
})
|
|
|
|
Context("trying to delete an unknown ID", func() {
|
|
It("should fail", func() {
|
|
_, err := srv.GetValue().Client().Webhooks.V1.DeleteConfig(
|
|
ctx,
|
|
operations.DeleteConfigRequest{
|
|
ID: "unknown",
|
|
},
|
|
)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.(*sdkerrors.ErrorResponse).ErrorCode).To(Equal(components.ErrorsEnumNotFound))
|
|
})
|
|
})
|
|
})
|