@voxgig/create-sdkgen 0.0.2 → 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 (89) hide show
  1. package/bin/run-create-sdkgen.js~ +1 -0
  2. package/package.json +3 -1
  3. package/tm/standard/.env.local +2 -0
  4. package/tm/standard/build/sdk.js +25 -0
  5. package/tm/standard/def/DEFINITION.md +2 -0
  6. package/tm/standard/model/.model-config/model-config.jsonic +13 -0
  7. package/tm/standard/model/go.jsonic +6 -0
  8. package/tm/standard/model/js.jsonic +6 -0
  9. package/tm/standard/model/php.jsonic +6 -0
  10. package/tm/standard/model/py.jsonic +7 -0
  11. package/tm/standard/model/rb.jsonic +6 -0
  12. package/tm/standard/model/sdk.jsonic.off +60 -0
  13. package/tm/standard/package.json +30 -0
  14. package/tm/standard/src/Root.ts +60 -0
  15. package/tm/standard/src/go/Entity_go.ts +226 -0
  16. package/tm/standard/src/go/MainEntity_go.ts +26 -0
  17. package/tm/standard/src/go/Main_go.ts +168 -0
  18. package/tm/standard/src/go/Quick_go.ts +108 -0
  19. package/tm/standard/src/go/ReadmeInstall_go.ts +19 -0
  20. package/tm/standard/src/go/ReadmeQuick_go.ts +45 -0
  21. package/tm/standard/src/go/TestAcceptEntity_go.ts +219 -0
  22. package/tm/standard/src/go/TestAccept_go.ts +38 -0
  23. package/tm/standard/src/go/TestEntity_go.ts +79 -0
  24. package/tm/standard/src/go/TestMain_go.ts +61 -0
  25. package/tm/standard/src/go/Test_go.ts +20 -0
  26. package/tm/standard/src/js/Entity_js.ts +135 -0
  27. package/tm/standard/src/js/MainEntity_js.ts +22 -0
  28. package/tm/standard/src/js/Main_js.ts +128 -0
  29. package/tm/standard/src/js/Quick_js.ts +72 -0
  30. package/tm/standard/src/js/ReadmeInstall_js.ts +19 -0
  31. package/tm/standard/src/js/ReadmeQuick_js.ts +27 -0
  32. package/tm/standard/src/js/TestAcceptEntity_js.ts +101 -0
  33. package/tm/standard/src/js/TestAccept_js.ts +60 -0
  34. package/tm/standard/src/js/TestEntity_js.ts +24 -0
  35. package/tm/standard/src/js/TestMain_js.ts +123 -0
  36. package/tm/standard/src/js/Test_js.ts +24 -0
  37. package/tm/standard/src/php/Entity_php.ts +97 -0
  38. package/tm/standard/src/php/MainEntity_php.ts +43 -0
  39. package/tm/standard/src/php/Main_php.ts +50 -0
  40. package/tm/standard/src/php/Quick_php.ts +59 -0
  41. package/tm/standard/src/php/TestAcceptEntity_php.ts +81 -0
  42. package/tm/standard/src/php/TestAccept_php.ts +33 -0
  43. package/tm/standard/src/php/TestEntity_php.ts +64 -0
  44. package/tm/standard/src/php/TestMain_php.ts +120 -0
  45. package/tm/standard/src/php/Test_php.ts +21 -0
  46. package/tm/standard/src/py/Entity_py.ts +98 -0
  47. package/tm/standard/src/py/MainEntity_py.ts +19 -0
  48. package/tm/standard/src/py/Main_py.ts +211 -0
  49. package/tm/standard/src/py/Quick_py.ts +133 -0
  50. package/tm/standard/src/py/TestAcceptEntity_py.ts +47 -0
  51. package/tm/standard/src/py/TestAccept_py.ts +77 -0
  52. package/tm/standard/src/py/TestEntity_py.ts +50 -0
  53. package/tm/standard/src/py/TestMain_py.ts +103 -0
  54. package/tm/standard/src/py/Test_py.ts +28 -0
  55. package/tm/standard/src/rb/Client_rb.ts +142 -0
  56. package/tm/standard/src/rb/Entity_rb.ts +153 -0
  57. package/tm/standard/src/rb/Error_rb.ts +56 -0
  58. package/tm/standard/src/rb/MainEntity_rb.ts +16 -0
  59. package/tm/standard/src/rb/Main_rb.ts +55 -0
  60. package/tm/standard/src/rb/Quick_rb.ts +65 -0
  61. package/tm/standard/src/rb/ReadmeInstall_rb.ts +19 -0
  62. package/tm/standard/src/rb/ReadmeQuick_rb.ts +30 -0
  63. package/tm/standard/src/rb/TestAcceptEntity_rb.ts +83 -0
  64. package/tm/standard/src/rb/TestAccept_rb.ts +45 -0
  65. package/tm/standard/src/rb/TestEntity_rb.ts +82 -0
  66. package/tm/standard/src/rb/TestMain_rb.ts +67 -0
  67. package/tm/standard/src/rb/Test_rb.ts +27 -0
  68. package/tm/standard/src/tsconfig.json +15 -0
  69. package/tm/standard/tm/go/.env.example +2 -0
  70. package/tm/standard/tm/go/LICENSE +22 -0
  71. package/tm/standard/tm/go/go.mod +5 -0
  72. package/tm/standard/tm/go/go.sum +2 -0
  73. package/tm/standard/tm/js/LICENSE +22 -0
  74. package/tm/standard/tm/js/package.json +17 -0
  75. package/tm/standard/tm/php/LICENSE +22 -0
  76. package/tm/standard/tm/py/LICENSE +22 -0
  77. package/tm/standard/tm/py/MANIFEST.in +4 -0
  78. package/tm/standard/tm/py/Makefile +14 -0
  79. package/tm/standard/tm/py/pyproject.toml +4 -0
  80. package/tm/standard/tm/py/pytest.ini +3 -0
  81. package/tm/standard/tm/py/requirements.txt +4 -0
  82. package/tm/standard/tm/py/setup.cfg +2 -0
  83. package/tm/standard/tm/py/setup.py +82 -0
  84. package/tm/standard/tm/rb/.rspec +1 -0
  85. package/tm/standard/tm/rb/Gemfile +21 -0
  86. package/tm/standard/tm/rb/LICENSE +22 -0
  87. package/tm/standard/tm/rb/Rakefile +6 -0
  88. package/tm/standard/tm/rb/spec/spec_helper.rb +22 -0
  89. package/tm/standard/tm/rb/tm.gemspec +39 -0
@@ -0,0 +1,142 @@
1
+ import {
2
+ cmp,
3
+ each,
4
+ camelify,
5
+ File,
6
+ Content,
7
+ Folder,
8
+ snakify,
9
+ } from '@voxgig/sdkgen';
10
+
11
+
12
+ import { MainEntity } from './MainEntity_rb'
13
+
14
+
15
+ const Client = cmp(async function Client(props: any) {
16
+ const { build } = props;
17
+ const { model } = props.ctx$;
18
+
19
+ const entity = model.main.sdk.entity;
20
+
21
+ Folder({ name: "lib" }, () => {
22
+ Folder({ name: snakify(model.Name) + "_sdk" }, () => {
23
+ File({ name: "client.rb" }, () => {
24
+ Content(`
25
+ # ${model.Name} ${build.Name} SDK
26
+
27
+ require 'json'
28
+ require 'net/http'
29
+ `);
30
+
31
+ each(entity, (entity: any) => {
32
+ entity.Name = camelify(entity.name);
33
+ Content(`
34
+ require_relative './${snakify(entity.Name)}'
35
+ `);
36
+ });
37
+
38
+ const validate_options = each(build.options).reduce(
39
+ (a: string, opt: any) =>
40
+ a +
41
+ ("String" === opt.kind
42
+ ? ` required('String','${opt.name}', @options)\n`
43
+ : ""),
44
+ ""
45
+ );
46
+
47
+ Content(`
48
+ module ${model.Name}SDK
49
+ class Client
50
+ attr_reader :options
51
+
52
+ def initialize(opts = {})
53
+ @options = ${model.Name}SDK.options.merge(opts)
54
+ ${validate_options}
55
+ @options[:fetch] ||= ->(url, method, apikey, body = nil) {
56
+ default_fetch(url, method, apikey, body)
57
+ }
58
+ end
59
+
60
+ def endpoint(op, ent)
61
+ data = ent.data
62
+ definition = ent.def
63
+ base_url = "#{options[:endpoint]}/#{definition[:name]}"
64
+
65
+ if (op == 'load' || op == 'remove') && data[:id] != nil
66
+ "#{base_url}/#{data[:id]}"
67
+ else
68
+ base_url
69
+ end
70
+ end
71
+
72
+ def method(op, ent)
73
+ ent.nil? && op == 'save' ? 'create' : op
74
+ {
75
+ 'create' => 'POST',
76
+ 'save' => 'PUT',
77
+ 'load' => 'GET',
78
+ 'list' => 'GET',
79
+ 'remove' => 'DELETE'
80
+ }[op]
81
+ end
82
+
83
+ def body(op, ent)
84
+ msg = ent.data.dup
85
+ JSON.generate(msg)
86
+ end
87
+
88
+ `);
89
+
90
+ each(entity, (entity: any) => {
91
+ MainEntity({ model, build, entity });
92
+ });
93
+
94
+ Content(`
95
+
96
+ private
97
+
98
+ def required(type, name, options)
99
+ val = options[name.to_sym]
100
+ unless val.is_a?(Object.const_get(type))
101
+ raise ArgumentError, "${model.Name}SDK: Invalid option: #{name}=#{val}: must be of type #{type}"
102
+ end
103
+ end
104
+
105
+ def default_fetch(url, method, apikey, body = nil)
106
+ uri = URI(url)
107
+ http = Net::HTTP.new(uri.host, uri.port)
108
+ http.use_ssl = (uri.scheme == "https")
109
+
110
+ request = build_request(uri, method, apikey, body)
111
+
112
+ begin
113
+ response = http.request(request)
114
+ response
115
+ rescue SocketError => e
116
+ raise ${model.Name}NetworkError.new("Network unreachable: #{e.message}")
117
+ rescue Timeout::Error => e
118
+ raise ${model.Name}TimeoutError.new("Request timed out: #{e.message}")
119
+ rescue StandardError => e
120
+ raise ${model.Name}SDKError.new("Unexpected error: #{e.message}")
121
+ end
122
+ end
123
+
124
+ def build_request(uri, method, apikey, body)
125
+ request = Net::HTTP.const_get(method.capitalize).new(uri)
126
+ request['Content-Type'] = 'application/json'
127
+ request['Authorization'] = "Bearer #{apikey}"
128
+ request.body = body if %i[post put].include?(method.downcase.to_sym) && body
129
+ request
130
+ end
131
+ end
132
+ end
133
+
134
+ `);
135
+ });
136
+ });
137
+ });
138
+ });
139
+
140
+
141
+ export { Client };
142
+
@@ -0,0 +1,153 @@
1
+ import {
2
+ cmp,
3
+ File,
4
+ Content,
5
+ Folder,
6
+ snakify,
7
+ } from '@voxgig/sdkgen';
8
+
9
+ const Entity = cmp(function Entity(props: any) {
10
+ const { build, entity } = props;
11
+ const { model } = props.ctx$;
12
+
13
+ Folder({ name: "lib" }, () => {
14
+ Folder({ name: snakify(model.Name) + "_sdk" }, () => {
15
+ File({ name: snakify(entity.Name) + ".rb" }, () => {
16
+ Content(`
17
+ # ${model.Name} ${build.Name} ${entity.Name}
18
+
19
+ require 'json'
20
+ require 'net/http'
21
+
22
+ class ${entity.Name}
23
+ attr_accessor :sdk, :def, :data
24
+
25
+ def initialize(sdk, data = nil)
26
+ @sdk = sdk
27
+ @def = {
28
+ name: "${entity.name}"
29
+ }
30
+ @data = data
31
+ end
32
+
33
+ def handle_result(op, res, spec)
34
+ status = res.code.to_i
35
+
36
+ case status
37
+ when 200
38
+ json = JSON.parse(res.body, symbolize_names: true)
39
+ yield(json)
40
+ when 400
41
+ raise ${model.Name}BadRequestError.new("Bad request", status, res.body)
42
+ when 401
43
+ raise ${model.Name}AuthenticationError.new("Authentication failed", status, res.body)
44
+ when 404
45
+ raise ${model.Name}NotFoundError.new("Resource not found", status, res.body)
46
+ when 429
47
+ raise ${model.Name}RateLimitError.new("Rate limit exceeded", status, res.body)
48
+ when 400..499
49
+ raise ${model.Name}ClientError.new("Client error", status, res.body)
50
+ when 500..599
51
+ raise ${model.Name}ServerError.new("Server error", status, res.body)
52
+ else
53
+ raise ${model.Name}SDKError.new("HTTP-ERROR: #{op}: ${entity.name}: #{status}", status, res.body)
54
+ end
55
+ end
56
+
57
+ def save(data)
58
+ op = 'save'
59
+ self.data = data
60
+ # TODO: validate data
61
+
62
+ body = sdk.body('save', self)
63
+ method = sdk.method('save', self)
64
+ url = sdk.endpoint('save', self)
65
+
66
+ spec = {}
67
+ res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
68
+
69
+ handle_result(op, res, spec) do |json|
70
+ self.data = json
71
+ self
72
+ end
73
+ end
74
+
75
+ def create(data)
76
+ op = 'create'
77
+ self.data = data
78
+
79
+ body = sdk.body('create', self)
80
+ method = sdk.method('create', self)
81
+ url = sdk.endpoint('create', self)
82
+
83
+ spec = {}
84
+ res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
85
+
86
+ handle_result(op, res, spec) do |json|
87
+ self.data = json
88
+ self
89
+ end
90
+ end
91
+
92
+ def load(data)
93
+ op = 'load'
94
+ self.data = data
95
+ # TODO: check if data.id is defined
96
+
97
+ body = sdk.body('load', self)
98
+ method = sdk.method('load', self)
99
+ url = sdk.endpoint('load', self)
100
+
101
+ spec = {}
102
+ res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
103
+
104
+ handle_result(op, res, spec) do |json|
105
+ self.data = json
106
+ self
107
+ end
108
+ end
109
+
110
+ def list(data = {})
111
+ op = 'list'
112
+ self.data = data
113
+ # TODO: check if data.id is defined
114
+
115
+ body = sdk.body('load', self)
116
+ method = sdk.method('load', self)
117
+ url = sdk.endpoint('load', self)
118
+
119
+ spec = {}
120
+ res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
121
+
122
+ handle_result(op, res, spec) do |json|
123
+ return json[:list].map { |data| sdk.${entity.Name}(data) }
124
+ end
125
+ end
126
+
127
+ def remove(data)
128
+ op = 'remove'
129
+ self.data = data
130
+
131
+ body = sdk.body('remove', self)
132
+ method = sdk.method('remove', self)
133
+ url = sdk.endpoint('remove', self)
134
+
135
+ spec = {}
136
+ res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
137
+
138
+ handle_result(op, res, spec) do |json|
139
+ self.data = json
140
+ self
141
+ end
142
+ end
143
+
144
+ end
145
+
146
+ `);
147
+ });
148
+ });
149
+ });
150
+ });
151
+
152
+
153
+ export { Entity };
@@ -0,0 +1,56 @@
1
+ import {
2
+ cmp,
3
+ File,
4
+ Content,
5
+ Folder,
6
+ snakify,
7
+ } from '@voxgig/sdkgen';
8
+
9
+ const Error = cmp(function Error(props: any) {
10
+ const { build, entity } = props;
11
+ const { model } = props.ctx$;
12
+
13
+ Folder({ name: "lib" }, () => {
14
+ Folder({ name: snakify(model.Name) + "_sdk" }, () => {
15
+ File({ name: "errors.rb" }, () => {
16
+ Content(`
17
+
18
+ module ${model.Name}SDK
19
+ class ${model.Name}SDKError < StandardError
20
+ attr_reader :status, :body, :response
21
+
22
+ def initialize(message, status = nil, body = nil, response = nil)
23
+ super(message)
24
+ @status = status
25
+ @body = body
26
+ @response = response
27
+ end
28
+
29
+ def to_s
30
+ "#{message} (status: #{status || 'N/A'}, response body: #{body || 'N/A'})"
31
+ end
32
+ end
33
+
34
+ # Network errors
35
+ class ${model.Name}NetworkError < ${model.Name}SDKError; end
36
+ class ${model.Name}TimeoutError < ${model.Name}SDKError; end
37
+
38
+ # API errors
39
+ class ${model.Name}BadRequestError < ${model.Name}SDKError; end
40
+ class ${model.Name}AuthenticationError < ${model.Name}SDKError; end
41
+ class ${model.Name}NotFoundError < ${model.Name}SDKError; end
42
+ class ${model.Name}RateLimitError < ${model.Name}SDKError; end
43
+ class ${model.Name}ClientError < ${model.Name}SDKError; end
44
+ class ${model.Name}ServerError < ${model.Name}SDKError; end
45
+ end
46
+
47
+
48
+
49
+ `);
50
+ });
51
+ });
52
+ });
53
+ });
54
+
55
+
56
+ export { Error };
@@ -0,0 +1,16 @@
1
+ import { cmp, Content } from '@voxgig/sdkgen';
2
+
3
+ const MainEntity = cmp(async function MainEntity(props: any) {
4
+ const { entity } = props;
5
+
6
+ const def = JSON.stringify(entity);
7
+
8
+ Content(`
9
+ def ${entity.Name}(data={})
10
+ ${entity.Name}.new(self, data)
11
+ end
12
+
13
+ `);
14
+ });
15
+
16
+ export { MainEntity };
@@ -0,0 +1,55 @@
1
+ import {
2
+ cmp,
3
+ File,
4
+ Content,
5
+ Copy,
6
+ Folder,
7
+ snakify,
8
+ } from '@voxgig/sdkgen';
9
+
10
+ import { Test } from "./Test_rb";
11
+ import { Error } from "./Error_rb";
12
+ import { Client } from './Client_rb';
13
+
14
+ const Main = cmp(async function Main(props: any) {
15
+ const { build } = props;
16
+ const { model } = props.ctx$;
17
+
18
+ Copy({ from: "tm/" + build.name + "/Gemfile", name: "Gemfile" });
19
+ Copy({ from: "tm/" + build.name + "/" + 'tm.gemspec', name: snakify(model.Name) + "_sdk.gemspec" });
20
+ Copy({ from: "tm/" + build.name + "/Rakefile", name: "Rakefile" });
21
+
22
+ Test({ build });
23
+ Error({ model, build });
24
+ Client({ model, build });
25
+
26
+ Folder({ name: "lib" }, () => {
27
+ File({ name: snakify(model.Name) + "_sdk.rb" }, () => {
28
+ Content(`
29
+ # ${model.Name} ${build.Name} SDK
30
+ `);
31
+
32
+ Content(`
33
+
34
+ require_relative "${model.name}_sdk/client"
35
+
36
+ module ${model.Name}SDK
37
+ class << self
38
+ attr_accessor :options
39
+
40
+ def options
41
+ @options ||= {}
42
+ end
43
+
44
+ def configure
45
+ yield self
46
+ end
47
+ end
48
+ end
49
+ `);
50
+ });
51
+ });
52
+ });
53
+
54
+
55
+ export { Main };
@@ -0,0 +1,65 @@
1
+ import { cmp, File, Content } from '@voxgig/sdkgen';
2
+
3
+ const Quick = cmp(function Quick(props: any) {
4
+ const { build } = props;
5
+ const { model } = props.ctx$;
6
+
7
+ File({ name: "quick.rb" }, () => {
8
+ Content(`
9
+ require 'dotenv'
10
+ Dotenv.load
11
+ require_relative '../lib/${model.name}_sdk'
12
+
13
+ def run
14
+
15
+ client = ${model.Name}SDK::Client.new(
16
+ {
17
+ endpoint: ENV['${model.NAME}_ENDPOINT'],
18
+ apikey: ENV['${model.NAME}_APIKEY'],
19
+ }
20
+ )
21
+
22
+ # Test listing assets
23
+ out = client.Geofence.list()
24
+ puts "Geofence.list: #{out.inspect}\n\n"
25
+
26
+ # Test loading an asset
27
+ out = client.Geofence.load({id: 1})
28
+ puts "Geofence.load: #{out.inspect}\n\n"
29
+
30
+ # Check if endpoint includes localhost
31
+ if ENV['${model.NAME}_ENDPOINT'].include? 'localhost'
32
+ # Test creating an asset
33
+ out = client.Geofence.create({
34
+ id: 'CF49B47C-317B-4387-83C3-4A23715B1C45',
35
+ name: 'Geofence 1',
36
+ desc: 'Geofence 1 description',
37
+ custom: { foo: 'bar' },
38
+ extent_id: 'CF49B47C-317B-4387-83C3-4A23715B1C45'
39
+ })
40
+ puts "Geofence.create: #{out.inspect}\n\n"
41
+
42
+ # Test updating an asset
43
+ out = client.Geofence.save({
44
+ id: 'CF49B47C-317B-4387-83C3-4A23715B1C45',
45
+ name: 'Geofence 1',
46
+ desc: 'Geofence 1 description',
47
+ custom: { foo: 'bar' },
48
+ extent_id: 'CF49B47C-317B-4387-83C3-4A23715B1C45'
49
+ })
50
+ puts "Geofence.save: #{out.inspect}\n\n"
51
+
52
+ # Test deleting an asset
53
+ out = client.Geofence.remove({id: 'CF49B47C-317B-4387-83C3-4A23715B1C45'})
54
+ puts "Geofence.remove: #{out.inspect}\n\n"
55
+
56
+ end
57
+ end
58
+
59
+ run
60
+
61
+ `);
62
+ });
63
+ });
64
+
65
+ export { Quick };
@@ -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('```ruby')
9
+ Content(`
10
+ gem install ${build.module.name}
11
+ `)
12
+ Content('```')
13
+
14
+ })
15
+
16
+
17
+ export {
18
+ ReadmeInstall
19
+ }
@@ -0,0 +1,30 @@
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('```ruby')
9
+ Content(`
10
+ require('${build.module.name}')
11
+
12
+ client = ${model.Name}SDK::Client.new(
13
+ {
14
+ endpoint: ENV['${model.NAME}_ENDPOINT'],
15
+ apikey: ENV['${model.NAME}_APIKEY'],
16
+ }
17
+ )
18
+
19
+ # List all buildings
20
+ buildings = client.Building.list()
21
+ puts "Buildings: #{buildings.inspect}"
22
+ `)
23
+ Content('```')
24
+
25
+ })
26
+
27
+
28
+ export {
29
+ ReadmeQuick
30
+ }
@@ -0,0 +1,83 @@
1
+
2
+ import { cmp, camelify, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const TestAcceptEntity = cmp(function TestEntity(props: any) {
6
+ const { entity } = props
7
+
8
+ entity.Name = camelify(entity.name)
9
+
10
+ Content(`
11
+ describe '${entity.name}-load' do
12
+ it 'loads the entity correctly' do
13
+ out = @client.${entity.Name}.load(id: 't01')
14
+ # puts '${entity.name}-load', out
15
+
16
+ expect(out.data).to be_a(Hash)
17
+ end
18
+ end
19
+
20
+ describe '${entity.name}-list' do
21
+ it 'lists the entity correctly' do
22
+ out = @client.${entity.Name}.list
23
+ # puts '${entity.name}-list', out
24
+
25
+ expect(out).to be_a(Array)
26
+ end
27
+ end
28
+
29
+ describe '${entity.name}-create' do
30
+ it 'creates the entity correctly' do
31
+ out = @client.${entity.Name}.create(${JSON.stringify(generateObjectFromFields(entity.field))})
32
+ # puts '${entity.name}-create', out
33
+
34
+ expect(out.data).to be_a(Hash)
35
+ end
36
+ end
37
+
38
+ describe '${entity.name}-save' do
39
+ it 'saves the entity correctly' do
40
+ out = @client.${entity.Name}.save(${JSON.stringify(generateObjectFromFields(entity.field))})
41
+ # puts '${entity.name}-save', out
42
+
43
+ expect(out.data).to be_a(Hash)
44
+ end
45
+ end
46
+
47
+ describe '${entity.name}-remove' do
48
+ it 'removes the entity correctly' do
49
+ out = @client.${entity.Name}.remove(id: 't01')
50
+ # puts '${entity.name}-remove', out
51
+
52
+ expect(out.data).to be_a(Hash)
53
+ end
54
+ end
55
+
56
+ `);
57
+ })
58
+
59
+ function generateObjectFromFields(fields: any) {
60
+ const getRandomString = (length: number): string =>
61
+ Array.from({ length }, () => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.charAt(Math.floor(Math.random() * 62))).join('');
62
+
63
+ const defaultValues: Record<string, any> = {
64
+ number: Math.floor(Math.random() * 100),
65
+ string: getRandomString(5),
66
+ object: { [getRandomString(3)]: getRandomString(3) },
67
+ boolean: Math.random() > 0.5,
68
+ array: Array.from({ length: 3 }, () => getRandomString(3)),
69
+ }
70
+
71
+ const result: Record<string, any> = {}
72
+
73
+ for (const key in fields) {
74
+ result[key] = defaultValues[fields[key].type] ?? null;
75
+ }
76
+
77
+ return result
78
+ }
79
+
80
+
81
+ export {
82
+ TestAcceptEntity
83
+ }
@@ -0,0 +1,45 @@
1
+
2
+ import { cmp, each, File, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ import { TestAcceptEntity } from "./TestAcceptEntity_rb"
6
+
7
+
8
+ const TestAccept = cmp(function TestMain_js(props: any) {
9
+ const { build } = props
10
+ const { model } = props.ctx$
11
+
12
+
13
+ File({ name: model.name + '_sdk_spec.rb' }, () => {
14
+
15
+ Content(`
16
+ RSpec.describe '${model.Name}SDK::Client Acceptance Tests' do
17
+ before(:each) do
18
+ @client = ${model.Name}SDK::Client.new(
19
+ apikey: ENV['${model.NAME}_APIKEY'],
20
+ endpoint: ENV['${model.NAME}_ENDPOINT']
21
+ )
22
+ end
23
+
24
+ it 'happy' do
25
+ out = @client.Geofence.load(id: 'gf01')
26
+ # puts 'Geofence-load', out.inspect
27
+ expect(out.data[:id]).to eq('gf01')
28
+ end
29
+ `)
30
+
31
+ each(model.main.sdk.entity, (entity: any) => {
32
+ TestAcceptEntity({ model, build, entity })
33
+ })
34
+
35
+ Content(`end`)
36
+
37
+
38
+ })
39
+ })
40
+
41
+
42
+ export {
43
+ TestAccept
44
+ }
45
+