Skip to content

Commit

Permalink
feat: completely test events COMITTED_TRANSACTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 16, 2024
1 parent 290eba5 commit c839ff8
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 26 deletions.
12 changes: 7 additions & 5 deletions docs/events/CommittedTransactions.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
"type": "array"
},
"Time": {
"type": "string",
"format": "date-time",
"title": "Normalized date"
"properties": {},
"additionalProperties": false,
"type": "object"
},
"Transaction": {
"properties": {
Expand Down Expand Up @@ -126,8 +126,7 @@
"postings",
"metadata",
"timestamp",
"id",
"revertedAt"
"id"
]
},
"Volumes": {
Expand All @@ -137,6 +136,9 @@
},
"output": {
"$ref": "#/$defs/Int"
},
"balance": {
"$ref": "#/$defs/Int"
}
},
"additionalProperties": false,
Expand Down
12 changes: 7 additions & 5 deletions docs/events/RevertedTransaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
]
},
"Time": {
"type": "string",
"format": "date-time",
"title": "Normalized date"
"properties": {},
"additionalProperties": false,
"type": "object"
},
"Transaction": {
"properties": {
Expand Down Expand Up @@ -120,8 +120,7 @@
"postings",
"metadata",
"timestamp",
"id",
"revertedAt"
"id"
]
},
"Volumes": {
Expand All @@ -131,6 +130,9 @@
},
"output": {
"$ref": "#/$defs/Int"
},
"balance": {
"$ref": "#/$defs/Int"
}
},
"additionalProperties": false,
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ require (
github.com/onsi/gomega v1.34.2
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
github.com/r3labs/diff v1.1.0
github.com/shomali11/xsql v0.0.0-20190608141458-bf76292144df
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand All @@ -42,7 +41,6 @@ require (
go.uber.org/fx v1.22.2
go.uber.org/mock v0.4.0
golang.org/x/oauth2 v0.23.0
gotest.tools/v3 v3.5.1
)

require (
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4=
github.com/puzpuzpuz/xsync/v3 v3.4.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
github.com/r3labs/diff v1.1.0 h1:V53xhrbTHrWFWq3gI4b94AjgEJOerO1+1l0xyHOBi8M=
github.com/r3labs/diff v1.1.0/go.mod h1:7WjXasNzi0vJetRcB/RqNl5dlIsmXcTTLmF5IoH6Xig=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/riandyrn/otelchi v0.10.0 h1:QMbR/FMDWBOkej6dfyWteYefUKqIFxnyrpaoWRJ9RPQ=
Expand Down Expand Up @@ -296,7 +294,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand Down
3 changes: 1 addition & 2 deletions internal/api/v1/controllers_accounts_add_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package v1

import (
"encoding/json"
"github.com/formancehq/ledger/pkg/accounts"
"net/http"
"net/url"

"github.com/formancehq/ledger/pkg/core/accounts"

"github.com/formancehq/go-libs/api"
"github.com/formancehq/go-libs/metadata"
"github.com/formancehq/ledger/internal/api/common"
Expand Down
3 changes: 1 addition & 2 deletions internal/machine/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package machine

import (
"fmt"

"github.com/formancehq/ledger/pkg/core/accounts"
"github.com/formancehq/ledger/pkg/accounts"
)

type AccountAddress string
Expand Down
3 changes: 1 addition & 2 deletions internal/machine/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package machine

import (
"fmt"

"github.com/formancehq/ledger/pkg/core/assets"
"github.com/formancehq/ledger/pkg/assets"
)

type Asset string
Expand Down
5 changes: 2 additions & 3 deletions internal/posting.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ledger

import (
"github.com/formancehq/ledger/pkg/accounts"
"github.com/formancehq/ledger/pkg/assets"
"math/big"

"github.com/formancehq/ledger/pkg/core/accounts"
"github.com/formancehq/ledger/pkg/core/assets"

"github.com/pkg/errors"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion pkg/testserver/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (e *EventMatcher) Match(actual any) (success bool, err error) {
return false, fmt.Errorf("unable to unmarshal msg: %s", err)
}

Expect(ev.Type).To(Equal(e.eventName))

rawSchema := jsonschema.Reflect(e.expected)
data, err := json.Marshal(rawSchema)
if err != nil {
Expand Down Expand Up @@ -155,8 +157,9 @@ func (e *EventMatcher) NegatedFailureMessage(_ any) (message string) {

var _ types.GomegaMatcher = (*EventMatcher)(nil)

func Event(expected any) types.GomegaMatcher {
func Event(eventName string, expected any) types.GomegaMatcher {
return &EventMatcher{
expected: expected,
eventName: eventName,
}
}
3 changes: 2 additions & 1 deletion test/e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/formancehq/go-libs/metadata"
"github.com/formancehq/go-libs/time"
"github.com/formancehq/ledger/internal/bus"
"github.com/formancehq/ledger/pkg/events"
"github.com/nats-io/nats.go"
"io"
"math/big"
Expand Down Expand Up @@ -144,7 +145,7 @@ var _ = Context("Ledger integration tests", func() {
msgs = testServer.GetValue().Subscribe()
})
It("should receive an event", func() {
Eventually(msgs).Should(Receive(Event(bus.CommittedTransactions{
Eventually(msgs).Should(Receive(Event(events.EventTypeCommittedTransactions, bus.CommittedTransactions{
Ledger: "foo",
Transactions: []ledger.Transaction{{
TransactionData: ledger.TransactionData{
Expand Down

0 comments on commit c839ff8

Please sign in to comment.