Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(asset_types): PPT-1803 index endpoint when no matching entries found #398

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading