-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer_test.go
More file actions
80 lines (69 loc) · 1.72 KB
/
Copy pathcustomer_test.go
File metadata and controls
80 lines (69 loc) · 1.72 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package xledger_test
import (
"context"
"encoding/json"
"testing"
"github.com/omniboost/go-xledger"
)
func TestCustomerGetAll(t *testing.T) {
var result []xledger.Customer
var after *string
variables := map[string]interface{}{
"after": after,
}
for {
q := struct {
Data xledger.QLQueryPaginated[xledger.Customer] `graphql:"customers(ownerSet: CURRENT, objectStatus: OPEN, first: 500, after: $after)"`
}{}
err := client.GraphQLClient().Query(context.Background(), &q, variables)
if err != nil {
t.Fatal(err)
}
variables["after"] = ""
for _, edge := range q.Data.Edges {
result = append(result, edge.Node)
variables["after"] = edge.Cursor
}
if variables["after"] == "" {
break
}
}
t.Log(len(result))
}
func TestCustomerGet(t *testing.T) {
variables := map[string]interface{}{
"code": "10000133",
}
q := struct {
Data xledger.QLQueryPaginated[xledger.Customer] `graphql:"customers(first: 1, filter: {code: $code})"`
}{}
err := client.GraphQLClient().Query(context.Background(), &q, variables)
if err != nil {
t.Fatal(err)
}
if len(q.Data.Edges) == 0 {
t.Fatal("no customer found")
}
t.Log(q.Data.Edges[0].Node)
d, _ := json.Marshal(q.Data.Edges[0].Node)
t.Log(string(d))
}
func TestCustomerAdd(t *testing.T) {
q := struct {
Data xledger.QLQuery[xledger.Company] `graphql:"addCustomers(inputs: {node :$node})"`
}{}
variables := map[string]any{
"node": xledger.CustomerInput{
Description: "Omniboost TEST",
Code: "OMNI1234",
TaxNumber: "NO999999999",
Phone: "12345678",
},
}
err := client.GraphQLClient().Mutate(context.Background(), &q, variables)
if err != nil {
t.Fatal(err)
}
d, _ := json.Marshal(q.Data.Edges[0].Node)
t.Log(string(d))
}