Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
9512786
test(drivers): first draft of specs written
GabFitzgerald Oct 26, 2020
533b7e9
reverted chanages to repository files
GabFitzgerald Oct 26, 2020
3353c2b
style(drivers): crystal tool format
GabFitzgerald Oct 26, 2020
5ba475f
feat: add basic template to extend api_wrapper endpoint classes and m…
Oct 26, 2020
980bf26
refactor: update correct positioning of models with placeos::model as…
Oct 26, 2020
920f893
chore: add templates for all possible specs which map to rest-api con…
Oct 26, 2020
26fd016
style: reposition client methods to allign with rest-api action order
Oct 26, 2020
9a4c6ef
fix: cast type for response object correctly, set from_args for param…
Oct 26, 2020
e26c00a
fix: remove inheritance for webhook class
Oct 26, 2020
dc69c7e
refactor: add id fields to models
Oct 26, 2020
1dae3b9
broken: role enum - undefined constant
GabFitzgerald Oct 26, 2020
c97ff2b
fix(driver spec): role enum fixed
GabFitzgerald Oct 26, 2020
331a2d3
style(role enum): include Client::API::Models allows for Role:{role}
GabFitzgerald Oct 26, 2020
0ae1ea4
test(driver spec): first attempt to test paginatation?
GabFitzgerald Oct 27, 2020
52fb52a
Merge branch 'gab-tests' into test/integration
GabFitzgerald Oct 27, 2020
b9763c1
Update drivers.cr
GabFitzgerald Oct 27, 2020
cd7d238
Merge pull request #9 from PlaceOS/test/integration
GabFitzgerald Oct 27, 2020
a60058a
chore(driver spec): removed duplicate files
GabFitzgerald Oct 27, 2020
21b47a4
test: page spec, left pending
GabFitzgerald Oct 27, 2020
943b713
test(driver spec): compile and recompile
GabFitzgerald Oct 27, 2020
0e99231
small changes, nothing meaningful
GabFitzgerald Oct 28, 2020
b754fd8
test(oauth applications): specs for all methods
GabFitzgerald Oct 28, 2020
6bc7fe0
test(repositories): destroy, fetch and search methods tested
GabFitzgerald Oct 28, 2020
a4b3125
style: crystal tool format, and some other changes
GabFitzgerald Oct 28, 2020
a871c87
refactor: add more interfaces and update classes
Oct 28, 2020
0c2b6c1
refactor: update missing id params
Oct 28, 2020
c907ada
ref: implemented search module into cluster, domains, drivers, module…
GabFitzgerald Oct 28, 2020
e392f8a
style: crystal tool format
GabFitzgerald Oct 28, 2020
e027f9f
style: removed trailing white space
GabFitzgerald Oct 28, 2020
a3ca125
test: settings common methods
GabFitzgerald Oct 28, 2020
b4b406d
test: system_triggers fetch, search and detroy. todo create and update.
GabFitzgerald Oct 28, 2020
c327a79
ref: driver attributes depending on placeos-models
GabFitzgerald Oct 29, 2020
62d5ce9
style: drivers style
GabFitzgerald Oct 29, 2020
4c811d9
ref: zone models -> placeos-models
GabFitzgerald Oct 29, 2020
ffbee8d
style: zone spec
GabFitzgerald Oct 29, 2020
6acf80d
ref: modules, unsure about ping model
GabFitzgerald Oct 29, 2020
d4e68b3
refactor: update according to Caspians suggestion
Oct 29, 2020
e9711c5
ref: reposity model, and merge with latests commits
GabFitzgerald Oct 29, 2020
1dea1db
chore: add repositories spec
Oct 29, 2020
c60d5af
Merge with pull
Oct 29, 2020
27b4f5d
chore: extend spec coverage
Oct 29, 2020
a7a98e3
chore: users tests to be continued
GabFitzgerald Oct 30, 2020
a788f3a
Merge branch 'gab-tests' of github.com:PlaceOS/crystal-client into ga…
GabFitzgerald Oct 30, 2020
e7a3d4d
style(users): crystal tool format
GabFitzgerald Oct 30, 2020
5ecdc74
Merge branch 'gab-tests' of https://github.com/PlaceOS/crystal-client…
Oct 30, 2020
6a20364
chore: update user_specs, only #resource_token left
Oct 30, 2020
9841eb4
test: users
GabFitzgerald Oct 30, 2020
dd7b113
chore: domain specs + dev_guide.md
Oct 30, 2020
39e0a71
merged 1
GabFitzgerald Oct 30, 2020
cc64100
Merge branch 'gab-tests' of github.com:PlaceOS/crystal-client into ga…
GabFitzgerald Oct 30, 2020
3ba1a71
chore: trigger_instances -> placeos model
GabFitzgerald Oct 30, 2020
a554cbe
chore: add settings method spec
Oct 30, 2020
e9d47fa
chore: resolve merge conflict, remove authority model
Oct 30, 2020
a3ee1ec
chore: update dev guide
Oct 30, 2020
6deab48
chore: test coverage from modules and systems
Oct 30, 2020
deeae8c
chore: triggers specs:
GabFitzgerald Oct 30, 2020
0a8d25f
style: removing trailing whitespace
GabFitzgerald Oct 30, 2020
db7f0ad
docs: update progress
Oct 30, 2020
3b081bc
Merge branch 'gab-tests' of https://github.com/PlaceOS/crystal-client…
Oct 30, 2020
1c9f76a
chore: extend converage for root
Oct 30, 2020
6602a5b
style: whitespace
GabFitzgerald Oct 30, 2020
6e3e552
Merge branch 'gab-tests' of github.com:PlaceOS/crystal-client into ga…
GabFitzgerald Oct 30, 2020
0a7cd57
ref: auth models
GabFitzgerald Oct 30, 2020
9e8bb51
chore: add broker methods and template specs
Nov 2, 2020
27042dd
ref(settings): to placeos-models
GabFitzgerald Nov 2, 2020
12f20ba
Merge branch 'gab-tests' of github.com:PlaceOS/crystal-client into ga…
GabFitzgerald Nov 2, 2020
11e3b7d
ref(systems model): to placeos-models ControlSystems
GabFitzgerald Nov 2, 2020
4cb1de5
fix: to pass ci hopefully
GabFitzgerald Nov 2, 2020
6bd4af4
chore: update component method array
Nov 2, 2020
d21a773
chore: fix repo_type in repositories_spec - PlaceOS::Model::Repositor…
Nov 3, 2020
f089e22
fix: mistakes current version
GabFitzgerald Nov 3, 2020
ef63dce
fix: models fix
GabFitzgerald Nov 3, 2020
5a11fd3
style: crystal tool format
GabFitzgerald Nov 3, 2020
1548263
Merge pull request #11 from PlaceOS/gab-tests
GabFitzgerald Nov 3, 2020
b9ec02e
style: crystal tool format bug fixes
GabFitzgerald Nov 4, 2020
60a7a35
chore: driver role verbose
GabFitzgerald Nov 4, 2020
78e0994
chore: add repository type coverter with specs
Nov 4, 2020
7db8a27
chore: resolve merge conflict with repository
Nov 4, 2020
65ef0f1
chore: add json_serializable to enum from string
Nov 4, 2020
12a12f5
refactor: string value to int32 value for enum
Nov 4, 2020
619f837
refactor: update all models, remove to_json from spec, add client mod…
Nov 6, 2020
003703d
chore: update removing all .to_json from specs
Nov 6, 2020
92d9f6a
feat: allow auto-generate model passing all specs
Nov 6, 2020
1c0d681
refactor: replace extra model definition with generic method
Nov 9, 2020
421751b
refactor: update partial create and update methods macro
Nov 22, 2020
678ae8c
Merge branch 'master' into refactor/auto-generate-model
caspiano Mar 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ A library for building [crystal](crystal-lang.org/) applications that utilise Pl

## Usage

When initialialized via the host environment, the key `PLACE_URI` is expected.
When initialized via the host environment, the key `PLACE_URI` is expected.

### Authentication

Expand Down
4 changes: 2 additions & 2 deletions spec/placeos/api_wrapper/authority_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ module PlaceOS
authority = authority_api.fetch
authority.id.should eq("sgrp-oOO6aZj1-J")
authority.name.should eq(DOMAIN)
authority.description.should be_nil
authority.description.should eq(nil)
authority.login_url.should eq("/login?continue={{url}}")
authority.logout_url.should eq("/")
authority.config["universe"].as_i.should eq(42)
authority.config.not_nil!["universe"].as_i.should eq(42)
end
end
end
6 changes: 6 additions & 0 deletions spec/placeos/api_wrapper/auths/saml_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ module PlaceOS
describe Client::APIWrapper::Saml do
api = Client::APIWrapper.new DOMAIN
Client::APIWrapper::Saml.new api

it "#create" do
end

it "#update" do
end
end
end
75 changes: 75 additions & 0 deletions spec/placeos/api_wrapper/brokers_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require "../../spec_helper"

module PlaceOS
describe Client::APIWrapper::Repositories do
api = PlaceOS::Client::APIWrapper.new DOMAIN
client = Client::APIWrapper::Brokers.new api

brokers_json = {name: "hello"}.to_json

# brokers = Array(JSON::Any).from_json(brokers_json).map &.to_json

pending "#index" do
WebMock
.stub(:get, DOMAIN + client.base)
.to_return(body: brokers_json)
result = client.index
result.size.should eq(1)
# br = result.first
# br.should be_a(PlaceOS::Model::Broker)
# br.attribute.should be_a(attribute_value)
end

# describe "#create" do
# it "posts to the brokers endpoint" do
# WebMock
# .stub(:post, DOMAIN + client.base)
# .with(
# headers: {"Content-Type" => "application/json"},
# body: {
# driver_id: "abc-123",
# }.to_json
# )
# .to_return(body: brokers.first)
# result = client.create driver_id: "abc-123"
# result.should be_a(PlaceOS::Model::Broker)
# end
# end

# describe "#fetch" do
# it "inspects broker metadata" do
# broker_id = ""
# WebMock
# .stub(:get, DOMAIN + "#{client.base}/#{broker_id}")
# .to_return(body: brokers.first)
# result = client.fetch broker_id
# result.should be_a(PlaceOS::Model::Broker)
# end
# end

# describe "#update" do
# it "send a put request to the brokers endpoint" do
# broker_id = ""
# WebMock
# .stub(:put, DOMAIN + "#{client.base}/#{broker_id}")
# .with(
# headers: {"Content-Type" => "application/json"},
# body: {ignore_connected: true}.to_json
# )
# .to_return(body: brokers.first)
# result = client.update broker_id, ignore_connected: true
# result.should be_a(PlaceOS::Model::Broker)
# end
# end

# describe "#delete" do
# it "sends a delete request" do
# broker_id = ""
# WebMock
# .stub(:delete, DOMAIN + "#{client.base}/#{broker_id}")
# result = client.destroy broker_id
# result.should be_nil
# end
# end
end
end
23 changes: 23 additions & 0 deletions spec/placeos/api_wrapper/cluster_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "../../spec_helper"

module PlaceOS
describe Client::APIWrapper::Cluster do
# api = PlaceOS::Client::APIWrapper.new DOMAIN
# client = Client::APIWrapper::Cluster.new api

describe "#search" do
# WebMock
# .stub(:get, DOMAIN + client.base)
# .with(query: {include_status: "true"})
# .to_return(body: %())
# result = client.version
# result.should be_a(PlaceOS::Client::API::Models::Cluster)
end

describe "#fetch" do
end

describe "#destroy" do
end
end
end
43 changes: 43 additions & 0 deletions spec/placeos/api_wrapper/domains_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "../../spec_helper"

module PlaceOS
describe Client::APIWrapper::Domains do
api = PlaceOS::Client::APIWrapper.new DOMAIN
client = Client::APIWrapper::Domains.new api

it "#search" do
WebMock
.stub(:get, DOMAIN + client.base)
.with(query: {"offset" => "0", "limit" => "20"})
.to_return(body: %([{"created_at":1603948254,"updated_at":1603948254,"name":"localhost:8443/backoffice","description":"","domain":"localhost","login_url":"/login?continue={{url}}","logout_url":"/auth/logout","internals":{},"config":{},"id":"authority-G03OrvJj~5j"}]))
result = client.search offset: 0
result.size.should eq(1)
domain = result.first
domain.should be_a(PlaceOS::Model::Authority)
domain.should eq(Array(PlaceOS::Model::Authority).from_json(%([{"created_at":1603948254,"updated_at":1603948254,"name":"localhost:8443/backoffice","description":"","domain":"localhost","login_url":"/login?continue={{url}}","logout_url":"/auth/logout","internals":{},"config":{},"id":"authority-G03OrvJj~5j"}]))[0])
end

it "#fetch" do
WebMock
.stub(:get, DOMAIN + client.base + "/authority-G03OrvJj~5j")
.to_return(body: %({"created_at":1603948254,"updated_at":1603948254,"name":"localhost:8443/backoffice","description":"","domain":"localhost","login_url":"/login?continue={{url}}","logout_url":"/auth/logout","internals":{},"config":{},"id":"authority-G03OrvJj~5j"}))
result = client.fetch id: "authority-G03OrvJj~5j", complete: true
result.should be_a(PlaceOS::Model::Authority)
end

it "#destroy" do
WebMock
.stub(:delete, DOMAIN + "#{client.base}/authority-G0S_7R1hW3R")
result = client.destroy "authority-G0S_7R1hW3R"
result.should be_nil
end

it "#create" do
WebMock
.stub(:post, DOMAIN + client.base)
.to_return(body: %({"created_at":1604030519,"updated_at":1604030519,"name":"1234","description":"This is a test domain","domain":"localhost","login_url":"localhost:1234/login","logout_url":"localhost:1234/logout","internals":{},"config":{},"id":"authority-G0S_7R1hW3R"}))
result = client.create name: "1234", description: "This is a test domain", domain: "localhost", login_url: "localhost:1234/login", logout_url: "localhost:1234/logout"
result.should be_a(PlaceOS::Model::Authority)
end
end
end
125 changes: 125 additions & 0 deletions spec/placeos/api_wrapper/driver_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
require "../../spec_helper"
require "placeos-models"

module PlaceOS
include Client::API::Models # require for Role definitions, would like to dpened on Role definition in placeos-models
include PlaceOS::Model

describe Client::APIWrapper::Drivers do
api = PlaceOS::Client::APIWrapper.new DOMAIN
client = Client::APIWrapper::Drivers.new api

drivers_json = {{ read_file("#{__DIR__}/mocks/drivers.json") }}
drivers = Array(JSON::Any).from_json(drivers_json).map &.to_json

describe "#search" do
it "enumerates all drivers" do
WebMock
.stub(:get, DOMAIN + client.base)
.with(query: {"limit" => "20", "offset" => "0"}, headers: HEADERS)
.to_return(body: drivers_json)
result = client.search
result.size.should eq(2)
driver = result.first
driver.should be_a(PlaceOS::Client::API::Models::Driver)
driver.name.should eq("Place")
end

it "provides driver search" do
WebMock
.stub(:get, DOMAIN + client.base)
.with(query: {"q" => "Place", "limit" => "20", "offset" => "0"}, headers: HEADERS)
.to_return(body: drivers_json)
result = client.search q: "Place"
result.size.should eq(2)
result.first.name.should eq("Place")
end

# TODO
# expecting 1 getting 2.
pending "can limit pages correctly" do
WebMock
.stub(:get, DOMAIN + client.base)
.with(query: {"limit" => "1", "offset" => "0"}, headers: HEADERS)
.to_return(body: drivers_json)
result = client.search limit: 1
result.size.should eq(1)
# result.first.name.should eq("Place")
end
end

describe "#create" do
it "posts to the drivers endpoint" do
body = {name: "Place", role: 1, commit: "string", file_name: "string", module_name: "string", repository_id: "string"}.to_json
WebMock
.stub(:post, DOMAIN + client.base)
.with(
headers: HTTP::Headers{"Content-Type" => "application/json"},
body: body
)
.to_return(body: drivers.first)
result = client.create(name: "Place", role: 1, commit: "string", file_name: "string", module_name: "string", repository_id: "string")
result.should be_a(PlaceOS::Client::API::Models::Driver)
# result.to_json.should eq("{\"created_at\":1562041110,\"updated_at\":1562041120,\"name\":\"Place\",\"description\":\"null\",\"default_uri\":\"hello\",\"default_port\":80,\"role\":1,\"file_name\":\"string\",\"commit\":\"string\",\"repository_id\":\"string\",\"module_name\":\"string\",\"ignore_connected\":true}")
result.commit.should eq("string")
end
end

describe "#fetch" do
it "inspects a drivers metadata" do
WebMock
.stub(:get, DOMAIN + "#{client.base}/driver-oOj2lGgsz")
.to_return(body: drivers.first)
result = client.fetch "driver-oOj2lGgsz"
result.should be_a(PlaceOS::Client::API::Models::Driver)
# result.to_json.should eq("{\"created_at\":1562041110,\"updated_at\":1562041120,\"name\":\"Place\",\"description\":\"null\",\"default_uri\":\"hello\",\"default_port\":80,\"role\":1,\"file_name\":\"string\",\"commit\":\"string\",\"repository_id\":\"string\",\"module_name\":\"string\",\"ignore_connected\":true}")
end
end

describe "#update" do
it "send a put request to the drivers endpoint" do
WebMock
.stub(:put, DOMAIN + "#{client.base}/driver-oOj2lGgsz")
.with(
headers: {"Content-Type" => "application/json"},
body: {name: "Foo"}.to_json
)
.to_return(body: drivers.first)
result = client.update "driver-oOj2lGgsz", name: "Foo"
result.should be_a(PlaceOS::Client::API::Models::Driver)
# result.to_json.should eq("{\"created_at\":1562041110,\"updated_at\":1562041120,\"name\":\"Place\",\"description\":\"null\",\"default_uri\":\"hello\",\"default_port\":80,\"role\":1,\"file_name\":\"string\",\"commit\":\"string\",\"repository_id\":\"string\",\"module_name\":\"string\",\"ignore_connected\":true}")
end
end

describe "#destroy" do
it "execs a delete request" do
WebMock
.stub(:delete, DOMAIN + "#{client.base}/driver-oOj2lGgsz")
result = client.destroy "driver-oOj2lGgsz"
result.should be_nil
end
end

describe "#recompile" do
it "execs recompile" do
WebMock
.stub(:post, DOMAIN + "#{client.base}/driver-oOj2lGgsz/recompile")
.to_return(body: drivers.first)
result = client.recompile "driver-oOj2lGgsz"
result.should be_a(PlaceOS::Client::API::Models::Driver)
# result.to_json.should eq("{\"created_at\":1562041110,\"updated_at\":1562041120,\"name\":\"Place\",\"description\":\"null\",\"default_uri\":\"hello\",\"default_port\":80,\"role\":1,\"file_name\":\"string\",\"commit\":\"string\",\"repository_id\":\"string\",\"module_name\":\"string\",\"ignore_connected\":true}")
end
end

describe "#compiled" do
it "execs compile" do
WebMock
.stub(:get, DOMAIN + "#{client.base}/driver-oOj2lGgsz/compiled")
.to_return(body: drivers.first)
result = client.compiled "driver-oOj2lGgsz"
result.should be_a(PlaceOS::Client::API::Models::Driver)
# result.to_json.should eq("{\"created_at\":1562041110,\"updated_at\":1562041120,\"name\":\"Place\",\"description\":\"null\",\"default_uri\":\"hello\",\"default_port\":80,\"role\":1,\"file_name\":\"string\",\"commit\":\"string\",\"repository_id\":\"string\",\"module_name\":\"string\",\"ignore_connected\":true}")
end
end
end
end
12 changes: 8 additions & 4 deletions spec/placeos/api_wrapper/metadata_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module PlaceOS
mock_metadata = {} of String => String
Hash(String, JSON::Any).from_json(metadata_json).each { |key, value| mock_metadata[key] = value.to_json }

describe "fetch" do
describe "#fetch" do
it "gets metadata for a parent" do
WebMock
.stub(:get, DOMAIN + "#{client.base}/zone-oOj2lGgsz")
Expand All @@ -54,18 +54,22 @@ module PlaceOS
end
end

pending "children" do
pending "#children" do
# WebMock
# .stub(:get, DOMAIN + "#{client.base}/zone-oOj2lGgsz/children")
# .to_return(status: 200)
# result = client.children("zone-oOj2lGgsz")
end

it "update" do
it "#update" do
WebMock
.stub(:put, DOMAIN + "#{client.base}/zone-oOj2lGgsz")
.with(query: {"name" => "Place1"}, body: mock_metadata["Place1"])
.to_return(status: 200, body: mock_metadata["Place1"])
client.update("zone-oOj2lGgsz", "Place1", {name: "frodo"}, "metadata 1").should eq Client::API::Models::Metadata.from_json(mock_metadata["Place1"])
end

it "delete" do
it "#destroy" do
WebMock
.stub(:delete, DOMAIN + "#{client.base}/zone-oOj2lGgsz")
.with(query: {"name" => "Place1"})
Expand Down
32 changes: 32 additions & 0 deletions spec/placeos/api_wrapper/mocks/drivers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"id": "driver-oOj2lGgsz",
"name": "Place",
"description": "null",
"default_uri": "hello",
"default_port": 80,
"role": 1,
"file_name": "string",
"commit": "string",
"repository_id": "string",
"module_name": "string",
"ignore_connected": true,
"created_at": 1562041110,
"updated_at": 1562041120
},
{
"id": "driver-oOj2lGgsa",
"name": "Place",
"description": "null",
"default_uri": "hello again",
"default_port": 80,
"role": 2,
"file_name": "string",
"commit": "string",
"repository_id": "string",
"module_name": "string",
"ignore_connected": true,
"created_at": 1562041111,
"updated_at": 1562041121
}
]
Loading