Skip to content
Snippets Groups Projects
Commit 79916c21 authored by charlie ablett's avatar charlie ablett :tools:
Browse files

Merge branch 'task/404981' into 'master'

Fix edges in KeysetPaginationHelpers spec helper and add specs

See merge request !120572



Merged-by: charlie ablett's avatarcharlie ablett <cablett@gitlab.com>
Approved-by: charlie ablett's avatarcharlie ablett <cablett@gitlab.com>
Reviewed-by: Peter Leitzen's avatarPeter Leitzen <pleitzen@gitlab.com>
Co-authored-by: default avatarMichael Becker <11881043-wandering_person@users.noreply.gitlab.com>
parents 202a78e0 dfcc2351
No related branches found
No related tags found
3 merge requests!122597doc/gitaly: Remove references to removed metrics,!120936Draft: Debugging commit to trigger pipeline (DO NOT MERGE),!120572Fix edges in KeysetPaginationHelpers spec helper and add specs
Pipeline #867390626 passed with warnings
Pipeline: E2E Omnibus GitLab EE

#867398934

    Pipeline: GitLab

    #867398929

      Pipeline: E2E GDK

      #867398265

        ......@@ -7,14 +7,17 @@ def pagination_links(response)
        link.split(',').filter_map do |link|
        match = link.match(/<(?<url>.*)>; rel="(?<rel>\w+)"/)
        break nil unless match
        next unless match
        { url: match[:url], rel: match[:rel] }
        end
        end
        def pagination_params_from_next_url(response)
        next_url = pagination_links(response).find { |link| link[:rel] == 'next' }[:url]
        next_link = pagination_links(response).find { |link| link[:rel] == 'next' }
        next_url = next_link&.fetch(:url)
        return unless next_url
        Rack::Utils.parse_query(URI.parse(next_url).query)
        end
        end
        # frozen_string_literal: true
        require 'spec_helper'
        RSpec.describe KeysetPaginationHelpers, feature_category: :api do
        include described_class
        let(:headers) { { 'LINK' => %(<#{url}>; rel="#{rel}") } }
        let(:response) { instance_double('HTTParty::Response', headers: headers) }
        let(:rel) { 'next' }
        let(:url) do
        'http://127.0.0.1:3000/api/v4/projects/7/audit_eve' \
        'nts?cursor=eyJpZCI6IjYyMjAiLCJfa2QiOiJuIn0%3D&id=7&o' \
        'rder_by=id&page=1&pagination=keyset&per_page=2'
        end
        describe '#pagination_links' do
        subject { pagination_links(response) }
        let(:expected_result) { [{ url: url, rel: rel }] }
        it { is_expected.to eq expected_result }
        context 'with a partially malformed LINK header' do
        # malformed as the regxe is expecting the url to be surrounded by `<>`
        let(:headers) do
        { 'LINK' => %(<#{url}>; rel="next", GARBAGE, #{url}; rel="prev") }
        end
        it { is_expected.to eq expected_result }
        end
        context 'with a malformed LINK header' do
        # malformed as the regxe is expecting the url to be surrounded by `<>`
        let(:headers) { { 'LINK' => %(rel="next", GARBAGE, #{url}; rel="prev") } }
        let(:expected_result) { [] }
        it { is_expected.to eq expected_result }
        end
        end
        describe '#pagination_params_from_next_url' do
        subject { pagination_params_from_next_url(response) }
        let(:expected_result) do
        {
        'cursor' => 'eyJpZCI6IjYyMjAiLCJfa2QiOiJuIn0=',
        'id' => '7',
        'order_by' => 'id',
        'page' => '1',
        'pagination' => 'keyset',
        'per_page' => '2'
        }
        end
        it { is_expected.to eq expected_result }
        context 'with both prev and next rel links' do
        let(:prev_url) do
        'http://127.0.0.1:3000/api/v4/projects/7/audit_eve' \
        'nts?cursor=foocursor&id=8&o' \
        'rder_by=id&page=0&pagination=keyset&per_page=2'
        end
        let(:headers) do
        { 'LINK' => %(<#{url}>; rel="next", <#{prev_url}>; rel="prev") }
        end
        it { is_expected.to eq expected_result }
        end
        context 'with a partially malformed LINK header' do
        # malformed as the regxe is expecting the url to be surrounded by `<>`
        let(:headers) do
        { 'LINK' => %(<#{url}>; rel="next", GARBAGE, #{url}; rel="prev") }
        end
        it { is_expected.to eq expected_result }
        end
        context 'with a malformed LINK header' do
        # malformed as the regxe is expecting the url to be surrounded by `<>`
        let(:headers) { { 'LINK' => %(rel="next", GARBAGE, #{url}; rel="prev") } }
        it { is_expected.to be nil }
        end
        end
        end
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment