Skip to content

Commit

Permalink
chore(CE): list api accept per page (#543)
Browse files Browse the repository at this point in the history
Co-authored-by: afthab vp <[email protected]>
  • Loading branch information
github-actions[bot] and afthabvp authored Dec 26, 2024
1 parent 9dd9670 commit 9bb9389
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 12 additions & 0 deletions server/spec/requests/api/v1/models_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
expect(response_hash.dig(:links, :first)).to include("http://www.example.com/api/v1/models?page=1&per_page=20")
end

it "returns success and no models when the data is empty" do
workspace.models.destroy_all
get "/api/v1/models", headers: auth_headers(user, workspace_id)
expect(response).to have_http_status(:ok)
response_hash = JSON.parse(response.body).with_indifferent_access
expect(response_hash[:data].count).to eql(0)
expect(response_hash.dig(:links, :first)).to include("http://www.example.com/api/v1/models?page=1")
expect(response_hash.dig(:links, :last)).to include("http://www.example.com/api/v1/models?page=1")
expect(response_hash.dig(:links, :next)).to be_nil
expect(response_hash.dig(:links, :prev)).to be_nil
end

it "returns success and all mode for viewer role" do
workspace.workspace_users.first.update(role: viewer_role)
get "/api/v1/models", headers: auth_headers(user, workspace_id)
Expand Down
8 changes: 3 additions & 5 deletions server/spec/requests/api/v1/sync_runs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@

context "when it is an authenticated user" do
it "returns success and fetch sync " do
<<<<<<< HEAD
get "/api/v1/syncs/#{sync.id}/sync_runs", headers: auth_headers(user, workspace_id)
=======
get "/api/v1/syncs/#{sync.id}/sync_runs?page=1&per_page=20", headers: auth_headers(user, workspace_id)
response_hash = JSON.parse(response.body).with_indifferent_access
>>>>>>> ac183819 (chore(CE): list api accept per page (#732))
expect(response).to have_http_status(:ok)
response_hash = JSON.parse(response.body).with_indifferent_access
expect(response_hash[:data].size).to eq(2)
first_row_date = DateTime.parse(response_hash[:data].first.dig(:attributes, :updated_at))
second_row_date = DateTime.parse(response_hash[:data].last.dig(:attributes, :updated_at))
expect(first_row_date).to be > second_row_date
response_hash[:data].each_with_index do |row, _index|
sync_run = sync_runs.find { |sr| sr.id == row[:id].to_i }

Expand Down

0 comments on commit 9bb9389

Please sign in to comment.