Skip to content

Commit

Permalink
fix(asset_types): PPT-1803 index endpoint when no matching entries fo…
Browse files Browse the repository at this point in the history
…und (#398)
  • Loading branch information
naqvis authored Feb 4, 2025
1 parent e7293ac commit e45d652
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion spec/controllers/asset_types_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ module PlaceOS::Api
Spec.test_404(AssetTypes.base_route, model_name: Model::AssetType.table_name, headers: Spec::Authentication.headers, clz: Int64)

describe "index", tags: "search" do
it "should return json when get request is invoked" do
it "should return an empty array when no matching asset types found" do
PlaceOS::Model::Asset.clear
PlaceOS::Model::AssetType.clear
params = HTTP::Params.encode({"zone_id" => "unknown-zone"})
path = "#{AssetTypes.base_route}?#{params}"
result = client.get(path, headers: Spec::Authentication.headers)
result.status_code.should eq(200)
body = JSON.parse(result.body)
body.as_a?.should_not be_nil
body.as_a.size.should be >= 0
end

it "should return json when get request is invoked for matching asset-types" do
PlaceOS::Model::Asset.clear
PlaceOS::Model::AssetType.clear
asset = PlaceOS::Model::Generator.asset.save!
Expand Down
4 changes: 2 additions & 2 deletions src/placeos-rest-api/controllers/asset_types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ module PlaceOS::Api
SQL

result = PgORM::Database.connection do |db|
db.query_one sql, &.read(JSON::PullParser).read_raw
db.query_one sql, &.read(JSON::PullParser?).try &.read_raw
end
render json: result
render json: result || "[]"
end

# show the selected asset type
Expand Down

0 comments on commit e45d652

Please sign in to comment.