Merge pull request #9479 from tchak/graphql-fix-pending-deleted-dossiers-sort

fix(graphql): improuve sort for pending deleted dossiers
This commit is contained in:
Paul Chavard 2023-09-18 09:17:26 +00:00 committed by GitHub
commit ae2d9bba47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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