fix(graphql): improuve sort for pending deleted dossiers

This commit is contained in:
Paul Chavard 2023-09-15 16:15:43 +02:00
parent 0454d2066e
commit 21b9a491cb
3 changed files with 42 additions and 12 deletions

View file

@ -144,7 +144,19 @@ module Types
dossiers = dossiers.hidden_since(deleted_since)
end
dossiers.order(hidden_by_user_at: order, hidden_by_administration_at: order)
dossiers_table = Dossier.arel_table
case_statement = dossiers_table[:state]
.when(:en_construction)
.then(dossiers_table[:hidden_by_user_at])
.else(dossiers_table[:hidden_by_administration_at])
dossiers = dossiers.order(case_statement)
if order == :desc
dossiers = dossiers.reverse_order
end
dossiers
end
def champ_descriptors

View file

@ -83,7 +83,19 @@ module Types
dossiers = dossiers.hidden_since(deleted_since)
end
dossiers.order(hidden_by_user_at: order, hidden_by_administration_at: order)
dossiers_table = Dossier.arel_table
case_statement = dossiers_table[:state]
.when(:en_construction)
.then(dossiers_table[:hidden_by_user_at])
.else(dossiers_table[:hidden_by_administration_at])
dossiers = dossiers.order(case_statement)
if order == :desc
dossiers = dossiers.reverse_order
end
dossiers
end
end
end

View file

@ -185,17 +185,20 @@ describe API::V2::GraphqlController do
before {
dossier.hide_and_keep_track!(dossier.user, DeletedDossier.reasons.fetch(:user_request))
dossier_accepte.hide_and_keep_track!(instructeur, DeletedDossier.reasons.fetch(:instructeur_request))
Timecop.travel(3.hours.ago) {
dossier_accepte.hide_and_keep_track!(instructeur, DeletedDossier.reasons.fetch(:instructeur_request))
}
}
it {
expect(gql_errors).to be_nil
expect(gql_data[:demarche][:id]).to eq(procedure.to_typed_id)
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].size).to eq(2)
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].first[:id]).to eq(GraphQL::Schema::UniqueWithinType.encode('DeletedDossier', dossier.id))
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].second[:id]).to eq(GraphQL::Schema::UniqueWithinType.encode('DeletedDossier', dossier_accepte.id))
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].first[:dateSupression]).to eq(dossier.hidden_by_user_at.iso8601)
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].second[:dateSupression]).to eq(dossier_accepte.hidden_by_administration_at.iso8601)
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].first[:id]).to eq(GraphQL::Schema::UniqueWithinType.encode('DeletedDossier', dossier_accepte.id))
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].second[:id]).to eq(GraphQL::Schema::UniqueWithinType.encode('DeletedDossier', dossier.id))
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].first[:dateSupression]).to eq(dossier_accepte.hidden_by_administration_at.iso8601)
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].second[:dateSupression]).to eq(dossier.hidden_by_user_at.iso8601)
expect(gql_data[:demarche][:pendingDeletedDossiers][:nodes].first[:dateSupression] < gql_data[:demarche][:pendingDeletedDossiers][:nodes].second[:dateSupression])
}
end
end
@ -252,17 +255,20 @@ describe API::V2::GraphqlController do
before {
dossier.hide_and_keep_track!(dossier.user, DeletedDossier.reasons.fetch(:user_request))
dossier_accepte.hide_and_keep_track!(instructeur, DeletedDossier.reasons.fetch(:instructeur_request))
Timecop.travel(3.hours.ago) {
dossier_accepte.hide_and_keep_track!(instructeur, DeletedDossier.reasons.fetch(:instructeur_request))
}
}
it {
expect(gql_errors).to be_nil
expect(gql_data[:groupeInstructeur][:id]).to eq(groupe_instructeur.to_typed_id)
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].size).to eq(2)
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].first[:id]).to eq(GraphQL::Schema::UniqueWithinType.encode('DeletedDossier', dossier.id))
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].second[:id]).to eq(GraphQL::Schema::UniqueWithinType.encode('DeletedDossier', dossier_accepte.id))
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].first[:dateSupression]).to eq(dossier.hidden_by_user_at.iso8601)
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].second[:dateSupression]).to eq(dossier_accepte.hidden_by_administration_at.iso8601)
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].first[:id]).to eq(GraphQL::Schema::UniqueWithinType.encode('DeletedDossier', dossier_accepte.id))
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].second[:id]).to eq(GraphQL::Schema::UniqueWithinType.encode('DeletedDossier', dossier.id))
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].first[:dateSupression]).to eq(dossier_accepte.hidden_by_administration_at.iso8601)
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].second[:dateSupression]).to eq(dossier.hidden_by_user_at.iso8601)
expect(gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].first[:dateSupression] < gql_data[:groupeInstructeur][:pendingDeletedDossiers][:nodes].second[:dateSupression])
}
end
end