Skip to content

Commit e45d652

Browse files
authored
fix(asset_types): PPT-1803 index endpoint when no matching entries found (#398)
1 parent e7293ac commit e45d652

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

spec/controllers/asset_types_spec.cr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ module PlaceOS::Api
55
Spec.test_404(AssetTypes.base_route, model_name: Model::AssetType.table_name, headers: Spec::Authentication.headers, clz: Int64)
66

77
describe "index", tags: "search" do
8-
it "should return json when get request is invoked" do
8+
it "should return an empty array when no matching asset types found" do
9+
PlaceOS::Model::Asset.clear
10+
PlaceOS::Model::AssetType.clear
11+
params = HTTP::Params.encode({"zone_id" => "unknown-zone"})
12+
path = "#{AssetTypes.base_route}?#{params}"
13+
result = client.get(path, headers: Spec::Authentication.headers)
14+
result.status_code.should eq(200)
15+
body = JSON.parse(result.body)
16+
body.as_a?.should_not be_nil
17+
body.as_a.size.should be >= 0
18+
end
19+
20+
it "should return json when get request is invoked for matching asset-types" do
921
PlaceOS::Model::Asset.clear
1022
PlaceOS::Model::AssetType.clear
1123
asset = PlaceOS::Model::Generator.asset.save!

src/placeos-rest-api/controllers/asset_types.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ module PlaceOS::Api
102102
SQL
103103

104104
result = PgORM::Database.connection do |db|
105-
db.query_one sql, &.read(JSON::PullParser).read_raw
105+
db.query_one sql, &.read(JSON::PullParser?).try &.read_raw
106106
end
107-
render json: result
107+
render json: result || "[]"
108108
end
109109

110110
# show the selected asset type

0 commit comments

Comments
 (0)