@voxgig/create-sdkgen 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +2 -0
  2. package/bin/run-create-sdkgen.js +265 -1
  3. package/bin/run-create-sdkgen.js~ +1 -0
  4. package/dist/create-sdkgen.d.ts +2 -0
  5. package/dist/create-sdkgen.js +51 -2
  6. package/dist/create-sdkgen.js.map +1 -1
  7. package/dist/standard/ModelSdk.d.ts +2 -0
  8. package/dist/standard/ModelSdk.js +71 -0
  9. package/dist/standard/ModelSdk.js.map +1 -0
  10. package/dist/standard/Root.d.ts +2 -0
  11. package/dist/standard/Root.js +76 -0
  12. package/dist/standard/Root.js.map +1 -0
  13. package/dist/tsconfig.tsbuildinfo +1 -1
  14. package/package.json +9 -6
  15. package/src/create-sdkgen.ts +71 -3
  16. package/src/standard/ModelSdk.ts +92 -0
  17. package/src/standard/ModelSdk.ts~ +1 -0
  18. package/src/standard/Root.ts +107 -0
  19. package/src/standard/Root.ts~ +3 -0
  20. package/tm/standard/.env.local +2 -0
  21. package/tm/standard/build/sdk.js +25 -0
  22. package/tm/standard/def/DEFINITION.md +2 -0
  23. package/tm/standard/model/.model-config/model-config.jsonic +13 -0
  24. package/tm/standard/model/go.jsonic +6 -0
  25. package/tm/standard/model/js.jsonic +6 -0
  26. package/tm/standard/model/php.jsonic +6 -0
  27. package/tm/standard/model/py.jsonic +7 -0
  28. package/tm/standard/model/rb.jsonic +6 -0
  29. package/tm/standard/model/sdk.jsonic.off +60 -0
  30. package/tm/standard/package.json +30 -0
  31. package/tm/standard/src/Root.ts +60 -0
  32. package/tm/standard/src/go/Entity_go.ts +226 -0
  33. package/tm/standard/src/go/MainEntity_go.ts +26 -0
  34. package/tm/standard/src/go/Main_go.ts +168 -0
  35. package/tm/standard/src/go/Quick_go.ts +108 -0
  36. package/tm/standard/src/go/ReadmeInstall_go.ts +19 -0
  37. package/tm/standard/src/go/ReadmeQuick_go.ts +45 -0
  38. package/tm/standard/src/go/TestAcceptEntity_go.ts +219 -0
  39. package/tm/standard/src/go/TestAccept_go.ts +38 -0
  40. package/tm/standard/src/go/TestEntity_go.ts +79 -0
  41. package/tm/standard/src/go/TestMain_go.ts +61 -0
  42. package/tm/standard/src/go/Test_go.ts +20 -0
  43. package/tm/standard/src/js/Entity_js.ts +135 -0
  44. package/tm/standard/src/js/MainEntity_js.ts +22 -0
  45. package/tm/standard/src/js/Main_js.ts +128 -0
  46. package/tm/standard/src/js/Quick_js.ts +72 -0
  47. package/tm/standard/src/js/ReadmeInstall_js.ts +19 -0
  48. package/tm/standard/src/js/ReadmeQuick_js.ts +27 -0
  49. package/tm/standard/src/js/TestAcceptEntity_js.ts +101 -0
  50. package/tm/standard/src/js/TestAccept_js.ts +60 -0
  51. package/tm/standard/src/js/TestEntity_js.ts +24 -0
  52. package/tm/standard/src/js/TestMain_js.ts +123 -0
  53. package/tm/standard/src/js/Test_js.ts +24 -0
  54. package/tm/standard/src/php/Entity_php.ts +97 -0
  55. package/tm/standard/src/php/MainEntity_php.ts +43 -0
  56. package/tm/standard/src/php/Main_php.ts +50 -0
  57. package/tm/standard/src/php/Quick_php.ts +59 -0
  58. package/tm/standard/src/php/TestAcceptEntity_php.ts +81 -0
  59. package/tm/standard/src/php/TestAccept_php.ts +33 -0
  60. package/tm/standard/src/php/TestEntity_php.ts +64 -0
  61. package/tm/standard/src/php/TestMain_php.ts +120 -0
  62. package/tm/standard/src/php/Test_php.ts +21 -0
  63. package/tm/standard/src/py/Entity_py.ts +98 -0
  64. package/tm/standard/src/py/MainEntity_py.ts +19 -0
  65. package/tm/standard/src/py/Main_py.ts +211 -0
  66. package/tm/standard/src/py/Quick_py.ts +133 -0
  67. package/tm/standard/src/py/TestAcceptEntity_py.ts +47 -0
  68. package/tm/standard/src/py/TestAccept_py.ts +77 -0
  69. package/tm/standard/src/py/TestEntity_py.ts +50 -0
  70. package/tm/standard/src/py/TestMain_py.ts +103 -0
  71. package/tm/standard/src/py/Test_py.ts +28 -0
  72. package/tm/standard/src/rb/Client_rb.ts +142 -0
  73. package/tm/standard/src/rb/Entity_rb.ts +153 -0
  74. package/tm/standard/src/rb/Error_rb.ts +56 -0
  75. package/tm/standard/src/rb/MainEntity_rb.ts +16 -0
  76. package/tm/standard/src/rb/Main_rb.ts +55 -0
  77. package/tm/standard/src/rb/Quick_rb.ts +65 -0
  78. package/tm/standard/src/rb/ReadmeInstall_rb.ts +19 -0
  79. package/tm/standard/src/rb/ReadmeQuick_rb.ts +30 -0
  80. package/tm/standard/src/rb/TestAcceptEntity_rb.ts +83 -0
  81. package/tm/standard/src/rb/TestAccept_rb.ts +45 -0
  82. package/tm/standard/src/rb/TestEntity_rb.ts +82 -0
  83. package/tm/standard/src/rb/TestMain_rb.ts +67 -0
  84. package/tm/standard/src/rb/Test_rb.ts +27 -0
  85. package/tm/standard/src/tsconfig.json +15 -0
  86. package/tm/standard/tm/go/.env.example +2 -0
  87. package/tm/standard/tm/go/LICENSE +22 -0
  88. package/tm/standard/tm/go/go.mod +5 -0
  89. package/tm/standard/tm/go/go.sum +2 -0
  90. package/tm/standard/tm/js/LICENSE +22 -0
  91. package/tm/standard/tm/js/package.json +17 -0
  92. package/tm/standard/tm/php/LICENSE +22 -0
  93. package/tm/standard/tm/py/LICENSE +22 -0
  94. package/tm/standard/tm/py/MANIFEST.in +4 -0
  95. package/tm/standard/tm/py/Makefile +14 -0
  96. package/tm/standard/tm/py/pyproject.toml +4 -0
  97. package/tm/standard/tm/py/pytest.ini +3 -0
  98. package/tm/standard/tm/py/requirements.txt +4 -0
  99. package/tm/standard/tm/py/setup.cfg +2 -0
  100. package/tm/standard/tm/py/setup.py +82 -0
  101. package/tm/standard/tm/rb/.rspec +1 -0
  102. package/tm/standard/tm/rb/Gemfile +21 -0
  103. package/tm/standard/tm/rb/LICENSE +22 -0
  104. package/tm/standard/tm/rb/Rakefile +6 -0
  105. package/tm/standard/tm/rb/spec/spec_helper.rb +22 -0
  106. package/tm/standard/tm/rb/tm.gemspec +39 -0
@@ -0,0 +1,168 @@
1
+
2
+ import { cmp, each, camelify, File, Content, Copy } from '@voxgig/sdkgen'
3
+
4
+ import { MainEntity } from './MainEntity_go'
5
+ import { Test } from './Test_go'
6
+
7
+
8
+ const Main = cmp(async function Main(props: any) {
9
+ const { build } = props
10
+ const { model } = props.ctx$
11
+
12
+ const entity = model.main.sdk.entity
13
+ const options = build.options
14
+
15
+ Copy({ from: 'tm/' + build.name + '/.env.example', name: '.env.example' })
16
+ Copy({ from: 'tm/' + build.name + '/go.mod', name: 'go.mod' })
17
+ Copy({ from: 'tm/' + build.name + '/go.sum', name: 'go.sum' })
18
+ Test({ build })
19
+ File({ name: model.name + 'sdk.' + build.name }, () => {
20
+
21
+ Content(`
22
+ // ${model.Name} ${build.Name} SDK
23
+
24
+ package ${model.name}sdk
25
+
26
+ import(
27
+ "bytes"
28
+ "encoding/json"
29
+ "fmt"
30
+ "net/http"
31
+ "errors"
32
+ "reflect"
33
+ )
34
+
35
+ type endpointConfig struct {
36
+ op string
37
+ id string
38
+ name string
39
+ apiUrl string
40
+ }
41
+
42
+ type fetchConfig struct {
43
+ op string
44
+ url string
45
+ apikey string
46
+ }
47
+
48
+ type spec struct {
49
+ body *bytes.Buffer
50
+ url string
51
+ method string
52
+ contentType string
53
+ authorization string
54
+ }
55
+
56
+ type Options struct {`)
57
+ each(options, (option: any) => {
58
+ if (option.kind != "Any") {
59
+ Content(`
60
+ ${camelify(option.name)} ${option.kind.toLowerCase()}
61
+ `)
62
+ }
63
+ }); Content(`
64
+ }
65
+
66
+ type ${model.name} struct {
67
+ httpClient http.Client
68
+ options Options
69
+ }
70
+
71
+ func method(op string) string {
72
+ operations := map[string]string {
73
+ "create": "POST",
74
+ "save": "PUT",
75
+ "load": "GET",
76
+ "list": "GET",
77
+ "remove": "DELETE",
78
+ }
79
+
80
+ return operations[op]
81
+ }
82
+
83
+ func endpoint(config endpointConfig) string {
84
+ url := fmt.Sprintf("%v/%v", config.apiUrl, config.name)
85
+
86
+ if config.op == "load" || config.op == "remove" {
87
+ url += fmt.Sprintf("/%v", config.id)
88
+ }
89
+
90
+ return url
91
+ }
92
+
93
+ func body[T any](data T) ([]byte, error) {
94
+ var msg []byte
95
+ msg, err := json.Marshal(data)
96
+ if err != nil {
97
+ return nil, err
98
+ }
99
+ return msg, nil
100
+ }
101
+
102
+ func fetchSpec[T any](config fetchConfig, data T) (spec, error){
103
+ method := method(config.op)
104
+ buffBody := bytes.NewBuffer([]byte{})
105
+
106
+ if method != "GET" && method != "DELETE" {
107
+ parsedBody, err := body(data)
108
+ if err != nil {
109
+ return spec{}, err
110
+ }
111
+ buffBody = bytes.NewBuffer(parsedBody)
112
+ }
113
+
114
+ spec := spec{
115
+ url: config.url,
116
+ method: method,
117
+ contentType: "application/json",
118
+ authorization: fmt.Sprintf("Bearer %v", config.apikey),
119
+ body: buffBody,
120
+ }
121
+ return spec, nil
122
+ }
123
+
124
+ `)
125
+
126
+ each(entity, (entity: any) => {
127
+ MainEntity({ model, build, entity })
128
+ })
129
+
130
+ Content(`
131
+ func validateOptions(options Options) error {
132
+ e := reflect.ValueOf(&options).Elem()
133
+
134
+ for i := 0; i < e.NumField(); i++ {
135
+ field := e.Field(i)
136
+ fieldName := e.Type().Field(i).Name
137
+ fieldValue := field.Interface()
138
+
139
+ if field.IsZero() {
140
+ return errors.New(fmt.Sprintf("${model.Name}SDK: Invalid options: opt: %v value: %v",
141
+ fieldName, fieldValue))
142
+ }
143
+ }
144
+ return nil
145
+ }
146
+
147
+ func new${model.Name}SDK(options Options) (*${model.name}, error) {
148
+ sdk := new(${model.name})
149
+ sdk.options = options
150
+ sdk.httpClient = *http.DefaultClient
151
+ return sdk, nil
152
+ }
153
+
154
+ func Make(options Options) (*${model.name}, error) {
155
+ err := validateOptions(options)
156
+ if err != nil {
157
+ return nil, err
158
+ }
159
+ return new${model.Name}SDK(options)
160
+ }
161
+ `)
162
+ })
163
+ })
164
+
165
+
166
+ export {
167
+ Main
168
+ }
@@ -0,0 +1,108 @@
1
+
2
+ import { cmp, File, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const Quick = cmp(function Quick(props: any) {
6
+ const { build } = props
7
+ const { model } = props.ctx$
8
+
9
+ File({ name: 'quick_test.' + build.name }, () => {
10
+
11
+ Content(`
12
+ package ${model.name}sdk
13
+
14
+ import (
15
+ "log"
16
+ "os"
17
+ "strings"
18
+ "testing"
19
+
20
+ "github.com/joho/godotenv"
21
+ )
22
+
23
+ func TestQuick(t *testing.T) {
24
+ err := godotenv.Load()
25
+ if err != nil {
26
+ t.Fatal("Error loading .env file for Quick test")
27
+ }
28
+
29
+ endpoint := os.Getenv("${model.NAME}_ENDPOINT")
30
+ apikey := os.Getenv("${model.NAME}_APIKEY")
31
+
32
+ var options Options
33
+ options.Apikey = apikey
34
+ options.Endpoint = endpoint
35
+ client, err := Make(options)
36
+ if err != nil {
37
+ t.Fatalf("Error creating a new client Quick: %q", err)
38
+ }
39
+
40
+ data := GeofenceData{
41
+ Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
42
+ }
43
+
44
+ out, err := client.Geofence().Load(data)
45
+ if err != nil {
46
+ t.Fatalf("Error running Quick load method: %q", err)
47
+ }
48
+ log.Print("Geofence.load", out.Data)
49
+
50
+ out2, err := client.Geofence().List()
51
+ if err != nil {
52
+ t.Fatalf("Error running Quick list method: %q", err)
53
+ }
54
+ log.Print("Geofence.list", out2[0].Data, out2[1].Data)
55
+
56
+ if strings.Contains(endpoint, "localhost") {
57
+ //Create Quick Test
58
+ data := GeofenceData{
59
+ Name: "Geofence 1",
60
+ Desc: "Geofence 1 description",
61
+ Extent_id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
62
+ Custom: map[string]any{
63
+ "foo": "bar",
64
+ },
65
+ }
66
+ out, err := client.Geofence().Create(data)
67
+ if err != nil {
68
+ t.Fatalf("Error running Quick create method: %q", err)
69
+ }
70
+ log.Print("Geofence.create", out.Data)
71
+
72
+ //Save Quick Test
73
+ data = GeofenceData{
74
+ Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
75
+ Name: "Geofence 1",
76
+ Desc: "Geofence 1 description",
77
+ Extent_id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
78
+ Custom: map[string]any{
79
+ "foo": "bar",
80
+ },
81
+ }
82
+ out, err = client.Geofence().Save(data)
83
+ if err != nil {
84
+ t.Fatalf("Error running Quick save method: %q", err)
85
+ }
86
+ log.Print("Geofence.save", out.Data)
87
+
88
+ //Remove Quick Test
89
+ data = GeofenceData{
90
+ Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
91
+ }
92
+ out, err = client.Geofence().Remove(data)
93
+ if err != nil {
94
+ t.Fatalf("Error running Quick remove method: %q", err)
95
+ }
96
+ log.Print("Geofence.remove ", out)
97
+ }
98
+ }
99
+ `)
100
+
101
+ })
102
+ })
103
+
104
+
105
+ export {
106
+ Quick
107
+ }
108
+
@@ -0,0 +1,19 @@
1
+
2
+ import { cmp, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const ReadmeInstall = cmp(function ReadmeInstall(props: any) {
6
+ const { build } = props
7
+
8
+ Content('```go')
9
+ Content(`
10
+ go get ${build.module.name}
11
+ `)
12
+ Content('```')
13
+
14
+ })
15
+
16
+
17
+ export {
18
+ ReadmeInstall
19
+ }
@@ -0,0 +1,45 @@
1
+
2
+ import { cmp, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
6
+ const { build, ctx$: { model } } = props
7
+
8
+ Content('```go')
9
+ Content(`
10
+ package main
11
+
12
+ import (
13
+ "log"
14
+ "os"
15
+
16
+ "${build.module.name}"
17
+ )
18
+
19
+ func main() {
20
+ var options ${model.name}sdk.Options
21
+ options.Apikey = os.Getenv("${model.NAME}_APIKEY")
22
+ options.Endpoint = os.Getenv("${model.NAME}_ENDPOINT")
23
+
24
+ client, err := ${model.name}sdk.Make(options)
25
+ if err != nil {
26
+ log.Fatal(err)
27
+ }
28
+
29
+ buildings, err := client.Building().List()
30
+ if err != nil {
31
+ log.Println("Error running building list:", err)
32
+ return
33
+ }
34
+
35
+ log.Println("Buildings", buildings)
36
+ }
37
+ `)
38
+ Content('```')
39
+
40
+ })
41
+
42
+
43
+ export {
44
+ ReadmeQuick
45
+ }
@@ -0,0 +1,219 @@
1
+
2
+ import { cmp, each, camelify, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const TestAcceptEntity = cmp(function TestAcceptEntity(props: any) {
6
+ const { model, entity } = props
7
+
8
+ entity.Name = camelify(entity.name)
9
+
10
+ const valueMap: Record<string, any> = {
11
+ "custom": "map[string]any{\"test\": \"test\"}",
12
+ "xval": "rand.Float64()",
13
+ "yval": "rand.Float64()",
14
+ "zval": "rand.Float64()",
15
+ "xlen": "rand.Int()",
16
+ "ylen": "rand.Int()",
17
+ "parent_xlen": "rand.Int()",
18
+ "parent_xval": "rand.Float64()",
19
+ "parent_xyangle": "rand.Float64()",
20
+ "parent_ylen": "rand.Int()",
21
+ "parent_yval": "rand.Float64()",
22
+ "parent_zval": "rand.Float64()",
23
+ "polygon": "struct{Points [][]float64}{[][]float64{{ 1.34},{12.33}}}",
24
+ "has_parent": true,
25
+ "primary": true,
26
+ }
27
+
28
+ Content(`
29
+ func Test${entity.Name}AcceptList(t *testing.T) {
30
+ err := godotenv.Load()
31
+ if err != nil {
32
+ t.Fatal("Error loading .env file for Test${entity.Name}AcceptList")
33
+ }
34
+ endpoint := os.Getenv("${model.NAME}_ENDPOINT")
35
+ apikey := os.Getenv("${model.NAME}_APIKEY")
36
+
37
+ var options ${model.name}sdk.Options
38
+ options.Apikey = apikey
39
+ options.Endpoint = endpoint
40
+ client, err := ${model.name}sdk.Make(options)
41
+ if err != nil {
42
+ t.Fatalf("Error creating a new client ${entity.name} list: %q", err)
43
+ }
44
+
45
+ entities, err := client.${entity.Name}().List()
46
+ if err != nil {
47
+ t.Fatalf("Error running ${entity.name} list method: %v", err)
48
+ }
49
+
50
+ if len(entities) == 0 {
51
+ t.Fatalf("Error getting ${entity.name} accept list length == 0 and got %v",
52
+ len(entities))
53
+ }
54
+
55
+ got := entities[0].Data
56
+
57
+ if got.Id == "" {
58
+ t.Fatal("Error getting ${entity.name} accept list - id equal to empty string")
59
+ }
60
+ }
61
+
62
+
63
+ func Test${entity.Name}AcceptLoad(t *testing.T) {
64
+ err := godotenv.Load()
65
+ if err != nil {
66
+ t.Fatal("Error loading .env file for Test${entity.Name}AcceptLoad")
67
+ }
68
+ endpoint := os.Getenv("${model.NAME}_ENDPOINT")
69
+ apikey := os.Getenv("${model.NAME}_APIKEY")
70
+
71
+ var options ${model.name}sdk.Options
72
+ options.Apikey = apikey
73
+ options.Endpoint = endpoint
74
+ client, err := ${model.name}sdk.Make(options)
75
+ if err != nil {
76
+ t.Fatalf("Error creating a new client ${entity.name} load: %q", err)
77
+ }
78
+
79
+ data := ${model.name}sdk.${entity.Name}Data{
80
+ Id: "t01",
81
+ }
82
+
83
+ client${entity.Name}, err := client.${entity.Name}().Load(data)
84
+ if err != nil {
85
+ t.Fatalf("Error running ${entity.name} load method: %v", err)
86
+ }
87
+
88
+ got := client${entity.Name}.Data
89
+
90
+ if got.Id == "" {
91
+ t.Fatal("Error getting ${entity.name} accept load - id equal to empty string")
92
+ }
93
+ }
94
+
95
+ func Test${entity.Name}AcceptCreate(t *testing.T) {
96
+ err := godotenv.Load()
97
+ if err != nil {
98
+ t.Fatal("Error loading .env file for Test${entity.Name}AcceptCreate")
99
+ }
100
+ endpoint := os.Getenv("${model.NAME}_ENDPOINT")
101
+ apikey := os.Getenv("${model.NAME}_APIKEY")
102
+
103
+ var options ${model.name}sdk.Options
104
+ options.Apikey = apikey
105
+ options.Endpoint = endpoint
106
+ client, err := ${model.name}sdk.Make(options)
107
+ if err != nil {
108
+ t.Fatalf("Error creating a new client ${entity.name} create: %q", err)
109
+ }
110
+
111
+ data := ${model.name}sdk.${entity.Name}Data{
112
+ `)
113
+ each(entity.field, (field: any) => {
114
+ const value = valueMap[field.name] ? valueMap[field.name] : field.type
115
+
116
+ if (value == "string") {
117
+ Content(`
118
+ ${field.Name}: "test",
119
+ `)
120
+ return
121
+ }
122
+ Content(`
123
+ ${field.Name}: ${value},
124
+ `)
125
+ })
126
+ Content(`
127
+ }
128
+
129
+ client${entity.Name}, err := client.${entity.Name}().Create(data)
130
+ if err != nil {
131
+ t.Fatalf("Error running ${entity.name} create method: %v", err)
132
+ }
133
+
134
+ got := client${entity.Name}.Data
135
+
136
+ if got.Id == "" {
137
+ t.Fatal("Error getting ${entity.name} accept create - id equal to empty string")
138
+ }
139
+ }
140
+
141
+
142
+ func Test${entity.Name}AcceptSave(t *testing.T) {
143
+ err := godotenv.Load()
144
+ if err != nil {
145
+ t.Fatal("Error loading .env file for Test${entity.Name}AcceptSave")
146
+ }
147
+ endpoint := os.Getenv("${model.NAME}_ENDPOINT")
148
+ apikey := os.Getenv("${model.NAME}_APIKEY")
149
+
150
+ var options ${model.name}sdk.Options
151
+ options.Apikey = apikey
152
+ options.Endpoint = endpoint
153
+ client, err := ${model.name}sdk.Make(options)
154
+ if err != nil {
155
+ t.Fatalf("Error creating a new client ${entity.name} save: %q", err)
156
+ }
157
+
158
+ data := ${model.name}sdk.${entity.Name}Data{
159
+ `)
160
+ each(entity.field, (field: any) => {
161
+ const value = valueMap[field.name] ? valueMap[field.name] : field.type
162
+
163
+ if (value == "string") {
164
+ Content(`
165
+ ${field.Name}: "test",
166
+ `)
167
+ return
168
+ }
169
+ Content(`
170
+ ${field.Name}: ${value},
171
+ `)
172
+ })
173
+ Content(`
174
+ }
175
+
176
+ client${entity.Name}, err := client.${entity.Name}().Save(data)
177
+ if err != nil {
178
+ t.Fatalf("Error running ${entity.name} save method: %v", err)
179
+ }
180
+
181
+ got := client${entity.Name}.Data
182
+
183
+ if got.Id == "" {
184
+ t.Fatal("Error getting ${entity.name} accept create - id equal to empty string")
185
+ }
186
+ }
187
+
188
+ func Test${entity.Name}AcceptRemove(t *testing.T) {
189
+ err := godotenv.Load()
190
+ if err != nil {
191
+ t.Fatal("Error loading .env file for Test${entity.Name}AcceptRemove")
192
+ }
193
+ endpoint := os.Getenv("${model.NAME}_ENDPOINT")
194
+ apikey := os.Getenv("${model.NAME}_APIKEY")
195
+
196
+ var options ${model.name}sdk.Options
197
+ options.Apikey = apikey
198
+ options.Endpoint = endpoint
199
+ client, err := ${model.name}sdk.Make(options)
200
+ if err != nil {
201
+ t.Fatalf("Error creating a new client ${entity.name} remove: %q", err)
202
+ }
203
+
204
+ data := ${model.name}sdk.${entity.Name}Data{
205
+ Id: "t01",
206
+ }
207
+
208
+ _, err = client.${entity.Name}().Remove(data)
209
+ if err != nil {
210
+ t.Fatalf("Error running ${entity.name} remove method: %v", err)
211
+ }
212
+ }
213
+ `);
214
+ })
215
+
216
+
217
+ export {
218
+ TestAcceptEntity
219
+ }
@@ -0,0 +1,38 @@
1
+
2
+ import { cmp, each, File, Content } from '@voxgig/sdkgen'
3
+
4
+ import { TestAcceptEntity } from './TestAcceptEntity_go'
5
+
6
+
7
+ const TestAccept = cmp(function TestAccept(props: any) {
8
+ const { build } = props
9
+ const { model } = props.ctx$
10
+
11
+
12
+ File({ name: model.name + 'sdk_accept_test.' + build.name }, () => {
13
+
14
+ Content(`
15
+ package ${model.name}sdk_test
16
+
17
+ import (
18
+ "math/rand"
19
+ "testing"
20
+ "os"
21
+
22
+ "github.com/joho/godotenv"
23
+ "github.com/${model.name}/${model.name}-sdk"
24
+ )
25
+ `)
26
+
27
+ each(model.main.sdk.entity, (entity: any) => {
28
+ TestAcceptEntity({ model, build, entity })
29
+ })
30
+
31
+ })
32
+ })
33
+
34
+
35
+ export {
36
+ TestAccept
37
+ }
38
+
@@ -0,0 +1,79 @@
1
+
2
+ import { cmp, camelify, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const TestEntity = cmp(function TestEntity(props: any) {
6
+ const { entity } = props
7
+
8
+ entity.Name = camelify(entity.name)
9
+
10
+ Content(`
11
+ func Test${entity.Name}List(t *testing.T) {
12
+ endpoint := "http://test.com"
13
+ apikey := "apikey"
14
+ want := ${entity.Name}Data{
15
+ Id: "${entity.name}t01",
16
+ Name: "${entity.Name}T01",
17
+ }
18
+
19
+ var options Options
20
+ options.Apikey = apikey
21
+ options.Endpoint = endpoint
22
+ client, err := Make(options)
23
+ if err != nil {
24
+ t.Fatalf("Error creating a new client ${entity.name} list: %q", err)
25
+ }
26
+
27
+ respData := strings.NewReader(\`{"list":[{"id":"${entity.name}t01"},
28
+ {"id":"${entity.name}t02"}]}\`)
29
+ httpClientMock := createHttpClientMock(respData)
30
+ client.httpClient = *httpClientMock
31
+
32
+ entities, err := client.${entity.Name}().List()
33
+ if err != nil {
34
+ t.Fatalf("Error running ${entity.name} list method: %q", err)
35
+ }
36
+
37
+ got := entities[0].Data
38
+ if got.Id != want.Id {
39
+ t.Fatalf("Error getting ${entity.name} list want %v and got %v", want, got)
40
+ }
41
+ }
42
+
43
+ func Test${entity.Name}Load(t *testing.T) {
44
+ endpoint := "http://test.com"
45
+ apikey := "apikey"
46
+ want := ${entity.Name}Data{
47
+ Id: "${entity.name}t01",
48
+ }
49
+
50
+ var options Options
51
+ options.Apikey = apikey
52
+ options.Endpoint = endpoint
53
+ client, err := Make(options)
54
+ if err != nil {
55
+ t.Fatalf("Error creating a new client ${entity.name} load: %q", err)
56
+ }
57
+
58
+ respData := strings.NewReader(fmt.Sprintf(\`{"id":"${entity.name}t01"}\`))
59
+ httpClientMock := createHttpClientMock(respData)
60
+ client.httpClient = *httpClientMock
61
+
62
+ data := want
63
+ client${entity.Name}, err := client.${entity.Name}().Load(data)
64
+ if err != nil {
65
+ t.Fatalf("Error running ${entity.name} load method: %q", err)
66
+ }
67
+
68
+ got := client${entity.Name}.Data
69
+ if got.Id != want.Id {
70
+ t.Fatalf("Error getting ${entity.name} load want %v and got %v", want.Id, got.Id)
71
+ }
72
+ }
73
+ `)
74
+ })
75
+
76
+
77
+ export {
78
+ TestEntity
79
+ }