-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.resolvers_test.go
55 lines (42 loc) · 1.36 KB
/
common.resolvers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package graphql
import (
"context"
"testing"
"github.com/gofrs/uuid"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
"github.com/surahman/FTeX/pkg/models"
)
func TestResolver_PriceQuoteResolvers(t *testing.T) {
t.Parallel()
resolver := priceQuoteResolver{}
clientID, err := uuid.NewV4()
require.NoError(t, err, "failed to generate client ID.")
rate := decimal.NewFromFloat(1234.56)
amount := decimal.NewFromFloat(78910.11)
priceQuote := &models.PriceQuote{
ClientID: clientID,
SourceAcc: "",
DestinationAcc: "",
Rate: rate,
Amount: amount,
}
t.Run("Client ID", func(t *testing.T) {
t.Parallel()
result, err := resolver.ClientID(context.TODO(), priceQuote)
require.NoError(t, err, "failed to resolve client id.")
require.Equal(t, clientID.String(), result, "client id mismatched.")
})
t.Run("Rate", func(t *testing.T) {
t.Parallel()
result, err := resolver.Rate(context.TODO(), priceQuote)
require.NoError(t, err, "failed to resolve rate.")
require.InDelta(t, rate.InexactFloat64(), result, 0.0001, "rate mismatched.")
})
t.Run("Amount", func(t *testing.T) {
t.Parallel()
result, err := resolver.Amount(context.TODO(), priceQuote)
require.NoError(t, err, "failed to resolve amount.")
require.InDelta(t, amount.InexactFloat64(), result, 0.0001, "amount mismatched.")
})
}